CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    Need accurate text extent

    How can I get an accurate text extent. I have tried using CDC::GetTextExtent but often the horizontal extent returned is not accurate. I need an accurate value because I am drawing a string in a box and I dont want the string to overrun the box if it wont fit in the box. Using the GetTextExtent function it returns a value that says the string will fit in the box when it in actuality it wont. Anyone have any ideas on how I can get the accurate horizontal extent of the string. Any help is greatly appreciated.


  2. #2
    Join Date
    Aug 2003
    Posts
    8

    Re: Need accurate text extent

    Hi everyone!

    I have the same problem !

    I need to compute a *PRECISE AND ACCURATE* BOUNDING rectangle around a text

    I tried with several methods with Windows32 API(s)

    - GetTextExtentPoint32
    - DrawText (with DT_CALCRECT)
    - GetCharWidth32 (Obtaining the width of every char of the string)

    I'm using MM_ANISOTROPIC mapping into my device context and seems that the X-Extension of the text is always different by the effective text drawned into the device. This happen when the zoom/scale factor is different by 1.0

    What i'm doing of wrong?
    Please help me


    Thank you
    Furno Gianluca

  3. #3
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: Need accurate text extent

    GetCharABCWidths() is working well for me, although it can be tricky sometimes, see http://www.codeguru.com/forum/showthread.php?t=369528
    But I don't know how it works with a zoom/scale factor, because I specify the size of the font in the first argument of CreateFont().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured