locked
custom font collections & create text format (metro app/directwrite)

    Question

  • I'm trying to figure out the best way to load a custom font and then use it with DrawText(...).

    So, my question is, what is the best (ok, easiest) way to get from an IDWriteFontFile (from CreateFontFileReference(...)) to an IDWriteTextFormat?

    It looks like I'll need to use CreateCustomFontCollection, which looks like I'll need to implement IDWriteFontCollectionLoader, and then write an IDWriteFontCollection, etc...  Is that the case?  Or am I missing something?  Is there a good example somewhere?

    Thanks!

    Friday, August 31, 2012 5:14 AM

Answers

All replies

  • Hi Mike,

    Take a look at the Custom Font Collections documentation and the Custom Font Sample . It's a desktop sample, but I think everything relevant will work the same in a Windows Store app.

    --Rob

    • Marked as answer by Mike Muir Saturday, September 1, 2012 4:11 AM
    Saturday, September 1, 2012 2:05 AM
    Moderator
  • Thanks!  I was actually able to get this working using those exact same resources today.  In order to make it work, you (minimally) need to implement IDWriteFontCollectionLoader and IDWriteFontFileEnumerator.

    As a bit of feedback, I really feel like the API is rather heavyweight, given that this is something that a lot of developers will need to use (particularly game developers).  And, it is particularly frustrating that the Custom Font Sample is not available in the Code Gallery.  It would also be great if the sample were tailored for WinRT.

    Saturday, September 1, 2012 4:11 AM
  • I don't think it's a good idea to use DirectWrite directly for game (that drawing in every frame).

    • Edited by Raptor K Sunday, September 2, 2012 2:35 PM
    Sunday, September 2, 2012 2:19 PM
  • I don't think it's a good idea to use DirectWrite directly for game (that drawing in every frame).


    It would be helpful if you explained why it's a bad idea, and then suggested a better way to do it. :)
    Monday, September 3, 2012 5:10 PM
  • The performance of DWrite is not so good. It is better to use font texture for games.


    C++ DX11

    Tuesday, September 4, 2012 3:26 AM
  • Yeah, I haven't profiled it yet, so I may end up having to do that.  Thanks.

    Tuesday, September 4, 2012 11:17 PM
  • It depends a great deal on usage scenario. Many games have fairly trivial text needs, and for those a 'font texture' solution (such as DirectXTK's SpriteFont class) can be very useful and high-performance. If you are rendering unconstrained text in CJK lanugages or using Arabic or other complex layout languages, you will find DirectWrite is very robust for your scenario.
    Wednesday, September 5, 2012 12:21 AM
  • Just got around to profiling, and, yep, it's pretty slow.  (I'm getting a 25% performance hit by just displaying one line of text).  But, the good news is that the layout features are really nice, and I'll probably still end up using it for fairly static screens (e.g., help screens, etc.).
    Thursday, September 6, 2012 1:14 AM
  • Just render text using directwrite into texture and draw texture every frame. You performance should be pretty much the same as using texture fonts but a lot more flexible.
    Monday, September 17, 2012 2:14 AM
  • Another problem is that Windows Phone 8 does NOT support Direct2D/DirectWrite, so if you want to port your game to WP8, you'd better only use pre-generated texture font.


    Win8 Developer QQ Group 95331609

    Monday, September 17, 2012 2:23 AM