使用指定字体与directx-11 [英] Use specified font with directx-11
问题描述
我想使用DirectX 11指定的字体文件
I would like to use a specified font file with DirectX 11
搜索后,我无法创建自定义字体集合。
After searching, i am stuck to create a custom Font Collection.
加载指定字体文件的代码:
Code to load the specified font file:
Platform::String^ pathTEST;
Microsoft::WRL::ComPtr<IDWriteFontFile> fontFileTEST;
Microsoft::WRL::ComPtr<IDWriteFontFileLoader> fontFileLoaderTEST;
Windows::Storage::StorageFolder^ folder = Windows::Storage::ApplicationData::Current->LocalFolder;
pathTEST = folder->Path + L"\\Bubblegum.ttf";//#BubbleGum
HRESULT hr = S_OK;
if (SUCCEEDED(hr))
hr = dwriteFactory->CreateFontFileReference(pathTEST->Data(), NULL, &fontFileTEST);
if (SUCCEEDED(hr))
hr = fontFileTEST->GetLoader(&fontFileLoaderTEST);
if (SUCCEEDED(hr))
hr = dwriteFactory->RegisterFontFileLoader(fontFileLoaderTEST.Get());
应该使用字体的代码,但我缺少Font集合:
Code that should use the font, but i am missing the Font collection:
MyIDWriteFactory2->CreateTextFormat(
L"BubbleGum", MyWriteFontCollection (nullptr for the moment),
DWRITE_FONT_WEIGHT_LIGHT, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
16.0f, L"en-us", &MyIDWriteTextFormat);
我没有任何问题,使用像Arial这样的系统字体。
I don't have any problem to use a system Font like Arial.
感谢您的帮助。
推荐答案
/stackoverflow.com/questions/21814876/trying-to-use-a-custom-font-file-using-directx-what-is-the-collection-key\">尝试使用DirectX使用自定义字体文件 - 什么是集合键?和自定义字体集合,我开始了解如何获得自定义集合。
After reading again Trying to use a custom font file using DirectX - What is the collection key? and Custom Font Collections, i have beginning to understand a little how to get a custom collection.
我已经修改了Microsoft给出的示例代码原因:
I have modified the sample code given by Microsoft for this reasons:
-
在Windows应用商店中,不允许使用GetModuleHandle。我在ResourceFontFileEnumerator中直接使用CreateFontFileReference而不是CreateCustomFontFileReference。
In Windows Store Apps, it don't allow to use GetModuleHandle. I used directly CreateFontFileReference and not CreateCustomFontFileReference in ResourceFontFileEnumerator.
它在应用程序中使用字体,但在我的例子中,字体在用户给出的另一个文件中。所以我使用一个工作来给ResourceFontFileEnumerator的ResourceFontFileEnumerator路径的列表由ResourceFontContext :: CreateFontCollection
It use fonts inside the application but in my case, the fonts are in another file given by the user. So I used a work around to give a list of the path to the font to ResourceFontFileEnumerator by ResourceFontContext::CreateFontCollection
现在,它的作品很好。
这篇关于使用指定字体与directx-11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!