TEXTMETRIC

2.x

typedef struct tagTEXTMETRIC {  /* tm */
    int  tmHeight;
    int  tmAscent;
    int  tmDescent;
    int  tmInternalLeading;
    int  tmExternalLeading;
    int  tmAveCharWidth;
    int  tmMaxCharWidth;
    int  tmWeight;
    BYTE tmItalic;
    BYTE tmUnderlined;
    BYTE tmStruckOut;
    BYTE tmFirstChar;
    BYTE tmLastChar;
    BYTE tmDefaultChar;
    BYTE tmBreakChar;
    BYTE tmPitchAndFamily;
    BYTE tmCharSet;
    int  tmOverhang;
    int  tmDigitizedAspectX;
    int  tmDigitizedAspectY;
} TEXTMETRIC;

The TEXTMETRIC structure contains basic information about a physical font. For Windows version 3.1, the EnumFonts and EnumFontFamilies functions return information about TrueType fonts in a NEWTEXTMETRIC structure.

Members

tmHeight

Specifies the height of character cells. (The height is the sum of the tmAscent and tmDescent members.)

tmAscent

Specifies the ascent of character cells. (The ascent is the space between the base line and the top of the character cell.)

tmDescent

Specifies the descent of character cells. (The descent is the space between the bottom of the character cell and the base line.)

tmInternalLeading

Specifies the difference between the point size of a font and the physical size of the font. For TrueType fonts, this value is equal to tmHeight minus (s * ntmSizeEM), where s is the scaling factor for the TrueType font and ntmSizeEM is a value from the NEWTEXTMETRIC structure. For bitmap fonts, this value is used to determine the point size of a font. When an application specifies a negative value in the lfHeight member of the LOGFONT structure, the application is requesting a font whose height equals tmHeight minus tmInternalLeading.

tmExternalLeading

Specifies the amount of extra leading (space) that the application adds between rows. Since this area is outside the character cell, it contains no marks and will not be altered by text output calls in either opaque or transparent mode. The font designer sometimes sets this member to zero.

tmAveCharWidth

Specifies the average width of characters in the font. For ANSI_CHARSET fonts, this is a weighted average of the characters “a” through “z” and the space character. For other character sets, this value is an unweighted average of all characters in the font.

tmMaxCharWidth

Specifies the “B” spacing of the widest character in the font. For more information about “B” spacing, see the description of the ABC structure.

tmWeight

Specifies the weight of the font. This member can be one of the following values:

Constant Value

FW_DONTCARE 0
FW_THIN 100
FW_EXTRALIGHT 200
FW_ULTRALIGHT 200
FW_LIGHT 300
FW_NORMAL 400
FW_REGULAR 400
FW_MEDIUM 500
FW_SEMIBOLD 600
FW_DEMIBOLD 600
FW_BOLD 700
FW_EXTRABOLD 800
FW_ULTRABOLD 800
FW_BLACK 900
FW_HEAVY 900

tmItalic

Specifies an italic font if it is nonzero.

tmUnderlined

Specifies an underlined font if it is nonzero.

tmStruckOut

Specifies a “struckout” font if it is nonzero.

tmFirstChar

Specifies the value of the first character defined in the font.

tmLastChar

Specifies the value of the last character defined in the font.

tmDefaultChar

Specifies the value of the character that will be substituted for characters that are not in the font.

tmBreakChar

Specifies the value of the character that will be used to define word breaks for text justification.

tmPitchAndFamily

Specifies the pitch and family of the selected font.

The four low-order bits identify the type of font, as shown in the following list:

Value Meaning

TMPF_PITCH Designates a fixed-pitch font.
TMPF_VECTOR Designates a vector or TrueType font.
TMPF_TRUETYPE Designates a TrueType font.
TMPF_DEVICE Designates a device font.

Some fonts are identified by several of these bits—for example, the bits TMPF_PITCH, TMPF_VECTOR, and TMPF_TRUETYPE would be set for the monospace TrueType font, Courier New. The TMPF_DEVICE bit could be set for a TrueType font as well, because this bit is set for both downloaded and device-resident fonts.

When the TMPF_TRUETYPE bit is set, the font is usable on all output devices. For example, if a TrueType font existed on a printer but could not be used on the display, the TMPF_TRUETYPE bit would not be set for that font.

The four high-order bits of this member designate the font family. The tmPitchAndFamily member can be combined with the value 0xF0 by using the bitwise AND operator and can then be compared with the font family names for an identical match. The following font families are defined:

Value Meaning

FF_DECORATIVE Novelty fonts. Old English is an example.
FF_DONTCARE Don't care or don't know.
FF_MODERN Fonts with constant stroke width, with or without serifs. Pica, Elite, and Courier New are examples.
FF_ROMAN Fonts with variable stroke width and with serifs. Times New Roman and New Century Schoolbook are examples.
FF_SCRIPT Fonts designed to look like handwriting. Script and Cursive are examples.
FF_SWISS Fonts with variable stroke width and without serifs. MS Sans Serif is an example.

tmCharSet

Specifies the character set of the font. The following values are defined:

Constant Value

ANSI_CHARSET 0
DEFAULT_CHARSET 1
SYMBOL_CHARSET 2
SHIFTJIS_CHARSET 128
OEM_CHARSET 255

tmOverhang

Specifies the extra width that is added to some synthesized fonts. When synthesizing some attributes, such as bold or italic, GDI or a device sometimes adds width to a string on both a per-character and per-string basis. For example, GDI makes a string bold by expanding the intracharacter spacing and overstriking by an offset value and italicizes a font by skewing the string. In either case, the string is wider after the attribute is synthesized. For bold strings, the overhang is the distance by which the overstrike is offset. For italic strings, the overhang is the amount the top of the font is skewed past the bottom of the font.

The tmOverhang member is zero for many italic and bold TrueType fonts because many TrueType fonts include italic and bold faces that are not synthesized. For example, the overhang for Courier New Italic is zero.

An application that uses raster fonts can use the overhang value to determine the spacing between words that have different attributes.

tmDigitizedAspectX

Specifies the horizontal aspect of the device for which the font was designed.

tmDigitizedAspectY

Specifies the vertical aspect of the device for which the font was designed. The ratio of the tmDigitizedAspectX and tmDigitizedAspectY members is the aspect ratio of the device for which the font was designed.

Comments

All sizes are given in logical units; that is, they depend on the current mapping mode of the display context.

See Also

EnumFontFamilies, EnumFonts, GetDeviceCaps, GetTextMetrics