locked
How to get the correct text width for oblique font in DirectWrite ? RRS feed

  • Question

  • I create a IDWriteTextLayout object by the following code,

    hr = g_pDWriteFactory->CreateTextLayout(text, textLength, *g_pTextFormat, 200000000, 200000000, g_pTextLayout);

    then get the text width by text metric,

            DWRITE_TEXT_METRICS dtm;
            pTextLayout->GetMetrics(&dtm);
            float minHeight = dtm.height;
            float minWidth = dtm.widthIncludingTrailingWhitespace;
                 

    what confuse me is that whether the style of the font is  DWRITE_FONT_STYLE_OBLIQUE or DWRITE_FONT_STYLE_NORMAL,

    the width is the same value. Why? I expect that when the font tyle is DWRITE_FONT_STYLE_OBLIQUE, the width should be bigger. how can i get the correct width for oblique text?

    Thanks.

    Sunday, February 12, 2017 4:36 PM

Answers

  • Hi Southwind2016,

    thanks for posting here.

    >>what confuse me is that whether the style of the font is  DWRITE_FONT_STYLE_OBLIQUE or DWRITE_FONT_STYLE_NORMAL,

    the width is the same value. Why? I expect that when the font tyle is DWRITE_FONT_STYLE_OBLIQUE, the width should be bigger. how can i get the correct width for oblique text?

    Actually they do have the same width if you use the same fonts. You could test that in your word, for example:

    The characters in an oblique font are artificially slanted. The slant is achieved by performing a shear transformation on the characters from a normal font.

    For more information about these font styles, please refer to this document below.

    https://msdn.microsoft.com/en-us/library/windows/desktop/dd368080(v=vs.85).aspx

    Hope this could be help of you.

    Best Regards,
    Sera Yu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Baron Bi Tuesday, February 14, 2017 7:41 AM
    • Marked as answer by Southwind2016 Wednesday, February 15, 2017 5:14 AM
    Monday, February 13, 2017 2:48 AM