Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


GetTextExtentPoint32() and italic fonts?

This topic is 5981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey! Does the function GetTextExtentPoint32() not take into consideration whether the font is italic or not when calculating the width of a text string? It seems to me that the function returns the same width of a character no matter if it is italic or not and it shouldn''t do that because italic fonts are wider than non italic fonts. In my application I need to know the exact width of every character, so what can I do? Is there a function which will tell me how many pixels the overhang is? Thanks, Spartacus

Share this post

Link to post
Share on other sites
GetTextExtentPoint32() should take into consideration italics, as long as the font object currently selected in the DC is italics. However, because some devices kern characters, the sum of the extents of the characters in a string does not always equal to the extent of the string.

To determine the current font’s properties, call GetTextMetrics() and pass it the handle of the device context you intend to use. If the function is successful, it returns a TEXTMETRIC structure that describes a number of properties about the current font.

TEXTMETRIC is defined as follows:

typedef struct _TEXTMETRIC {
LONG tmHeight;
LONG tmAscent;
LONG tmDescent;
LONG tmInternalLeading;
LONG tmExternalLeading;
LONG tmAveCharWidth;
LONG tmMaxCharWidth;
// ... other stuff we’re not interested in
BYTE tmPitchAndFamily;

- tmHeight refers to the overall height of the character measured in whatever units are in vogue in many cases, pixels.
- The height consists of 2 parts: the portion above the baseline (tmAscent) and the portion below the baseline (tmDescent). (The baseline is the horizontal line under the letters.)
- An extra area at the top of some fonts, the tmInternalLeading, is used for accents, diacritical marks, and other pieces of punctuation and may be zero.
- TmExternalLeading specifies the amount of extra space to be inserted between lines. This field is similar to double-spacing, except that it has finer grain control.

Note, the above function is not useful for calculating the WIDTH of a string, since it only provides an average width field. To find the exact width of characters in a particular font, use GetCharWidth32():

HDC hdc,
UINT iFirstChar,
UINT iLastChar,
LPINT lpBuffer

hdc - [in] Handle to the device context.
iFirstChar - [in] Unsigned integer that specifies the first character in the group of consecutive characters.
iLastChar - [in] Unsigned integer that specifies the last character in the group of consecutive characters. This last character must not precede the first character that you specified in iFirstChar.
lpBuffer - [out] Pointer to a buffer that receives the character widths, in logical coordinates.

Share this post

Link to post
Share on other sites
Hey thanks for the help! It actually works now Cool! I havent said thanks to you guys earlier, because I''ve not been at home for a while. Anyway, thanks for the help...


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!