我很难理解我是如何创建一个可以传递到CreateTextFormat
函数的字体集合。
确切的问题是要了解其中的集合关键部分:http://msdn.microsoft.com/en-us/library/windows/desktop/dd368186(v=vs.85).aspx
到目前为止,这是我的代码,我只是对集合键进行了疯狂的猜测,因为我根本不理解它...
// 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 );
}
它在这里使用:
// 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
);
修改::::: 我不确定我是否得到了无效指针的东西,我是否在正确的轨道上:?
int key;
void *pVoid = &key;
collectionLoader->CreateEnumeratorFromKey( pDWriteFactory, pVoid, sizeof(int), &fileEnumerator );
hr = pDWriteFactory->CreateCustomFontCollection( collectionLoader, pVoid, 1, &fontCollection );