Trying to use a custom font file using DirectX - What is the collection key?

こ雲淡風輕ζ 提交于 2019-12-02 20:40:30

问题


I'm struggling to understand how the hell I create a font collection that I can pass into my CreateTextFormat function.

The exact problem is understanding what the collection key part of this is: http://msdn.microsoft.com/en-us/library/windows/desktop/dd368186(v=vs.85).aspx

This is my code so far and I just took a wild guess at the collection key coz I don't understand it AT ALL...

// Vars

IDWriteFontFace* pFontFace;
IDWriteFontFile* pFontFiles;
IDWriteFontCollection* pFontCollection;
IDWriteFontCollection* fontCollection;
IDWriteFontCollectionLoader* collectionLoader;
IDWriteFontFileEnumerator* fileEnumerator;

// Set up font

HRESULT hr;

// Gets a filename from a application directory

hr = dWriteFactory->CreateFontFileReference(
    L"Assets/Fonts/PontanoSans-Regular.ttf",
    NULL,
    &pFontFiles );

IDWriteFontFile* fontFileArray[] = { pFontFiles };

if( SUCCEEDED( hr ) )
{
    hr = dWriteFactory->CreateFontFace(
        DWRITE_FONT_FACE_TYPE_TRUETYPE,
        1, // file count
        fontFileArray,
        0,
        DWRITE_FONT_SIMULATIONS_NONE,
        &pFontFace
        );
}

// Get the system font collection. BUT I DONT GET THIS PART ARGHHHH
if( SUCCEEDED( hr ) )
{
    collectionLoader->CreateEnumeratorFromKey( pDWriteFactory, pFontFiles, 1, &fileEnumerator );
    hr = pDWriteFactory->CreateCustomFontCollection( collectionLoader, fileEnumerator, 1, &fontCollection );
}

and it's used here:

// Create device independent resources
hr = dWriteFactory->CreateTextFormat(
    L"Pontano Sans",
    fontCollection, // HERE HERE HERE!
    DWRITE_FONT_WEIGHT_EXTRA_BOLD,
    DWRITE_FONT_STYLE_NORMAL,
    DWRITE_FONT_STRETCH_NORMAL,
    fontSize,
    L"en-US",
    &textFormat
    );

EDIT::::: I'm not sure I get the void pointer thing, am I on the right track:?

    int key;
    void *pVoid = &key;
    collectionLoader->CreateEnumeratorFromKey( pDWriteFactory, pVoid, sizeof(int), &fileEnumerator );
    hr = pDWriteFactory->CreateCustomFontCollection( collectionLoader, pVoid, 1, &fontCollection );

来源:https://stackoverflow.com/questions/21814876/trying-to-use-a-custom-font-file-using-directx-what-is-the-collection-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!