How to create IDWriteTextFormat from IDWriteFontFace

人盡茶涼 提交于 2019-12-10 19:19:09

问题


I'm creating W8 C++/CX DirectX application and I'm trying to use custom font file from application own storage. I figure out how to use IDWriteFactory::CreateFontFileReference to load IDWriteFontFile from directory and then how to create IDWriteFontFace from it.

What I don't know now is how to use IDWriteFontFace for loading IDWriteTextFormat, if it is possible at all. Should I do this though IDWriteFontCollection ?

Sorry if the answer is really stupid and trivial, I am very new to DirectX and learn everything on the go.


回答1:


See MSDN DirectWrite help topic on Custom Font Collections for the necessary high level view of how to load your own custom fonts at runtime. Your guess about how to do this was wrong.

It appears that the best sample on how to do this ships directly with the Win7SDK directWrite samples. See the DirectWrite\CustomFont C++ sample.

The process does not involve obtaining or using any IDWriteFontFace types. In fact, the only thing you can do with an IDWriteFontFace that I can see is determine glyphindices.

Instead, you start with a factory, as in all directX APIs, then with the factory, you want to make a font collection, and a font file loader, and enumerate fonts using that font collection. The interfaces for creating a text format expect you to pass in your custom font collection, not your font face.

A sample of correct use of the interface type IDWritefontFace to get glyph information is found here on codeproject.




回答2:


You can not create IDWriteTextFormat with IDWriteFontFace, you can create a IDWriteTextFormat instance with function IDWriteFactory::CreateTextFormat. IDWriteFontFace was used to describe the properties of font, while IDWriteTextFormat used to describe the properties of text.



来源:https://stackoverflow.com/questions/11921592/how-to-create-idwritetextformat-from-idwritefontface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!