Click to See Complete Forum and Search --> : Need accurate text extent
Kelly Cox
April 21st, 1999, 08:10 PM
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.
mshadow65
June 24th, 2006, 12:25 PM
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
olivthill
June 24th, 2006, 12:43 PM
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().
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.