C++ 在directx-11中使用指定字体
我想在DirectX 11中使用指定的字体文件 搜索之后,我坚持创建自定义字体集合 加载指定字体文件的代码:C++ 在directx-11中使用指定字体,c++,windows,fonts,directx-11,C++,Windows,Fonts,Directx 11,我想在DirectX 11中使用指定的字体文件 搜索之后,我坚持创建自定义字体集合 加载指定字体文件的代码: Platform::String^ pathTEST; Microsoft::WRL::ComPtr<IDWriteFontFile> fontFileTEST; Microsoft::WRL::ComPtr<IDWriteFontFileLoader> fontFileLoaderTEST; Windows::Storage::StorageFolder^ f
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());
我使用像Arial这样的系统字体没有任何问题
谢谢您的帮助。在再次阅读和之后,我开始了解一些如何获得定制收藏
出于以下原因,我修改了Microsoft提供的示例代码:
- 在Windows应用商店应用程序中,它不允许使用GetModuleHandle。我在ResourceFontFileEnumerator中直接使用了CreateFontFileReference,而不是CreateCustomFontFileReference
- 它在应用程序中使用字体,但在我的例子中,字体位于用户提供的另一个文件中。因此,我使用了一个变通方法,通过ResourceFontContext::CreateFontCollection向ResourceFontFileEnumerator提供字体路径列表
现在,它可以正常工作。显示的是直接从
IDWriteFontFile
创建字体。你试过了吗?谢谢你的回答。是的,但是当我使用它来创建文本格式或在屏幕上写入文本时,它会忽略指定的字体。
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);