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 );