Link to home
Start Free TrialLog in
Avatar of Invader
Invader

asked on

CDC: Text Width & Height

I need a way to calculate the actual height of a character drawn with CDC::DrawText.

Take for example the attached picture where the letter "s" is drawn with a grey background.
GetTextExtend returns the height of the character including this background space.
Same goes for DrawText if used with the DT_CALCRECT flag.

Is there a way to get the height of only the actual character?
Just from the top of the "s" to the bottom of it ?

Thanks..







char.JPG
SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Invader
Invader

ASKER

Zoppo:

I tried both the BeginPath and the SetBoundsRect approach. They work as they should but they still include the background area of the font.

I also did some testing with GetGlyphOutline with no luck but I will do some more. I think this one is the most likely to produce the desired result since its supposed to return the outline of the string.

itsmeandnobodyelse:

GetTextExtentPoint32 is the same as GetTextExtend. If you follow the latter, it calls the first one. However, you are right, the width is correct for any string and the height returned is every time of "fixed" size as required by the selected font.

------
I think best bet, is GetGlyphOutline...if I manage to get it to work..
Although it still has the drawback that it works only for True Type Fonts.
> works only for True Type Fonts
I'm not sure, it maybe it works for none-TrueType vector fonts too (AFAIK windows FNT-files can contain raster- or vector fonts).

For raster fonts I guess there's no possibility to get the info you want except maybe analyse the bitmap stored in the FNT file for the character to find the bounding of none-white pixels, since a raster font is just a bunch of bitmaps of same heigth.

ZOPPO
>>>> except maybe analyse the bitmap stored in the FNT file for the character
Maybe it is easier to read the bits of the rectangle on screen into a bitmap. If the background was white or unicolored, it shouldn't be much difficult to find the first non-white pixel when going from top to bottom for all columns.
... or analyze the bitmap returned by GetGlyphOutline using GGO_BITMAP.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial