DirectWrite Justified TextAlignment Char Spacing issues RRS feed

  • Question

  • Hello Guys! I'm developing an app using DirectWrite to Draw some texts and I'm facing some troubles

    The problem happens when we have a Justified text on RichEditBox and we try to draw the same text using Direct Write.


    The RichEditBox seems to apply spacing between words while the direct write changes the CharSpacing between every char of the line as you can see below:


    RichEditBox behavior:

    DirectWrite behavior :



    Our first approach to try to solve this issue was replace our to IDWriteTextLayout for IDWriteTextLayout1 and use the method SetCharacterSpacing() to 0 for every character except “ ”(blank space) but when we set SetTextAlignment(DWRITE_TEXT_ALIGNMENT_JUSTIFIED) it seems to ignore the spacing commands before and apply the spacing itself.


    Could you please give us some guidance on that matter?

    Thursday, July 26, 2012 5:54 PM

All replies

  • Anyone? no one knows if this is possible or not to fix?
    Friday, July 27, 2012 9:18 PM
  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to skydriver

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    Best regards,

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 30, 2012 7:30 AM
  • Sorry for the late response.

    HERE it is! A simple C++ metro solution where we see the diference between RichEditBox and DirectWrite behavior about Justified Texts
    Monday, July 30, 2012 4:27 PM
  • Guys? any answer?
    Tuesday, July 31, 2012 7:20 PM
  • "Starting with Windows 8, DirectWrite has a number of methods that allow you to justify text in your apps.

    There is an additional value in the DWRITE_TEXT_ALIGNMENT enumeration. You can use the SetTextAlignment method and pass in the DWRITE_TEXT_ALIGNMENT_JUSTIFIED constant and DirectWrite justifies the text and inserts the appropriate justification character for the script.

    If you are using a custom layout have a number of methods available so you can take advantage of justification. DirectWrite has three methods on the IDWriteTextAnalyzer1 interface that you can use to add justification to a custom layout.

    The first method is GetJustificationOpportunities, which takes in the text that you want to justify and returns a DWRITE_JUSTIFICATION_OPPORTUNITY structure that outlines where justification characters can be added to justify the text.

    The second function is JustifyGlyphAdvances, which justifies an array of glyph advances so that they fit the line width. This method takes in the DWRITE_JUSTIFICATION_OPPORTUNITY structure that GetJustificationOpportunities generates, the glyph advances, and the glyph offsets. It then generates the justified glyph advances and a DWRITE_GLYPH_OFFSET enumeration that contains the justified glyph offsets.

    The third function is GetJustifiedGlyphs, which fills in the new glyphs for complex scripts where justification has increased the advances for glyphs. GetJustifiedGlyphs only needs to be called if the script has a specific justification character as returned by GetScriptProperties. This method takes in information about the font, length of the text, em size of the glyphs, script of the text, number of glyphs, cluster map, original glyph advances/offsets, justified glyph advances/offsets, and glyph properties. The method returns the actual glyph count, updated cluster map, updated glyph indices with inserted justification glyphs, updated glyph offsets, and updated glyph advances."

    Taken from:


    I hope this helps,


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, July 31, 2012 9:45 PM