locked
How do I get the extent of text that I wish to paint.

    Question

  • I can use ID2D1RenderTarget::DrawText to draw text, but how can I get the extent of that text before I draw it?

    Thanks.

    Thursday, December 20, 2012 5:32 PM

Answers

  • Hi, you must create an instance of IDWriteTextLayout interface and then call GetMetrics or HitTestTextPosition methods.
    • Marked as answer by Jesse Jiang Monday, December 24, 2012 6:07 AM
    Friday, December 21, 2012 3:20 AM

All replies

  • For advanced text rendering and control, look at DirectWrite APIs.

    How to Draw Text

    Text Formatting and Layout


    Thursday, December 20, 2012 7:51 PM
  • Thanks for the links, they were some help, but I still do not seem to be able to get what I need.  What I want to do is determine the bounding box for a block of text (i.e. both the horizontal and vertical extents).  Using IDWriteTextFormat, I seem to be able to get the minimum width, but I do not see any functions that will give me the minimum height (or any height for that matter except for the max height that I pass in).  Can you direct me to what I am missing?

    Thanks

    Friday, December 21, 2012 2:22 AM
  • Hi, you must create an instance of IDWriteTextLayout interface and then call GetMetrics or HitTestTextPosition methods.
    • Marked as answer by Jesse Jiang Monday, December 24, 2012 6:07 AM
    Friday, December 21, 2012 3:20 AM
  • I was already creating an IDWriteTextLayout, it was the call to GetMetrics that I was missing.

    Thanks for the help.

    Friday, December 21, 2012 5:31 AM