0

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 );
Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
  • [This](http://msdn.microsoft.com/en-us/library/windows/desktop/ee264312(v=vs.85).aspx) explains the steps necessary, and links to a sample at the end. – melak47 Feb 16 '14 at 17:50
  • Hm, I can't understand the void pointer bit? Evidently I have already read this stuff and have re-focused on that key part.. do you have an example yourself, I'm not understanding what's going on in the example provided by Microsoft, it's just too much for me to get. I'm a delicate newbie. – Jimmyt1988 Feb 16 '14 at 18:31
  • I've added an edit @melak47 – Jimmyt1988 Feb 16 '14 at 18:38
  • I think that should work, but the lifetime of `key` must not expire before you unregister your collection loader – melak47 Feb 16 '14 at 18:45

0 Answers0