locked
DirectWrite and getting total lenght of text string.

    Question

  • Hello.

    I have a problem with a DirectWrite, specificly with a CreateTextFormat and DrawText function, because when I create text format with function CreateTextFormat, I cannot check the amount of width of the text, what it is draw. This caousr problem for example with center this text in my game and it is very frustating. It is any solution for my problem, exept a method text.size()*someValueOfWidthLetter because it is a bad idea.

    I really thank you for any interestring resolution for my problem.

    Sunday, October 12, 2014 11:48 PM

Answers

All replies

  • Create your text layout and then query the metrics with IDWriteTextLayout::GetMetrics

    • Marked as answer by MiXenXd Tuesday, October 14, 2014 4:53 PM
    Monday, October 13, 2014 9:28 PM
    Moderator
  • I used it before and I have a lot of problems(eg. cannot render multiple lines of text or bad coordinates in relation to screen coordinates). I don't really remember, but this function doesn't fit a change of width of the letters.

    Is there any different solution?

    edit:
    DWRITE_TEXT_METRICS field width what type of width return? When I call this function after drawing text, I get the total width of this line?


    • Edited by MiXenXd Monday, October 13, 2014 10:03 PM
    Monday, October 13, 2014 9:58 PM
  • GetMetrics will return results based on the layout you create. If you aren't getting the results you want then I suspect you're not creating the layout the way you need.

    Beyond that I'm not sure what you are asking for.

    Can you share on your OneDrive a minimal sample which demonstrates what you are trying to do and how GetMetrics fails? Show what you are doing, what results you expect, and what results you actually get.

    --Rob

    Monday, October 13, 2014 11:13 PM
    Moderator
  • Thank you for offering me your help, but actually I remake my code in use CreateTextLayout, DrawTextLayout and GetMetrics with field width and now I get the real width of the rendered text.

    Thank you very much :)

    Tuesday, October 14, 2014 4:53 PM