Finding Out About the Font

At the right side of its client area, PICKFONT shows you the type of information you can obtain after you select the logical font into the device context. GetTextMetrics tells you the real characteristics of the font, and GetTextFace tells you the typeface name.

To obtain the typeface name, you first define a character array to receive the name:

char szFaceName [LF_FACESIZE] ;

The LF_FACESIZE identifier is the maximum number of characters in the typeface name. You then tell Windows to copy the typeface name into this array:

GetTextFace (hdc, sizeof szFaceName, szFaceName) ;

The GetTextMetrics function retrieves information on the size and other characteristics of the font currently selected in the device context:

TEXTMETRIC tm ;

[other program lines]

GetTextMetrics (hdc, &tm) ;

All the size values that Windows copies into the TEXTMETRIC structure are in logical units except for the digitized aspect ratios. The fields of the TEXTMETRIC structure are as follows:

tmHeight (short integer)—The height of the character in logical units. This is the value that should approximate the lfHeight field specified in the LOGFONT structure. It is the sum of the tmAscent and tmDescent fields. Like the lfHeight field in the LOGFONT structure, it actually represents the line spacing of the font rather than the size, because it includes internal leading.

tmAscent (short integer)—The height of the character above the baseline in logical units. This should approximate the absolute value of the lfHeight field in the LOGFONT structure if lfHeight is set to a negative value.

tmDescent (short integer)—The height of the character below the baseline in logical units.

tmInternalLeading (short integer)—The area used for diacritics on some capital letters. As noted above, the actual internal leading is included in the tmHeight value. You can calculate the point size of the font by subtracting the tmInternalLeading value from the tmHeight value.

tmExternalLeading (short integer)—An additional amount of line spacing (beyond tmHeight) recommended by the designer of the font.

tmAveCharWidth (short integer)—The average width of the characters in logical units.

tmMaxCharWidth (short integer)—The width of the widest character in logical units. This value is the same as tmAveCharWidth for a fixed-pitch font.

tmWeight (short integer)—The weight of the font, ranging from 0 to 999. Currently, it will be set to either 400 (normal) or 700 (boldface).

tmItalic (BYTE)—Nonzero for an italic font.

tmUnderlined (BYTE)—Nonzero for an underlined font.

tmStruckOut (BYTE)—Nonzero for a strikethrough font.

tmPitchAndFamily (BYTE)—A value comprising the pitch in the lower two bits and the family in the higher four bits. This field is coded in the same way as the lfPitchAndFamily field in the LOGFONT structure, and you can use the same identifiers to extract the information.

tmCharSet (BYTE)—The character set. Under most circumstances, it will be either 0 (ANSI_CHARSET) or 255 (OEM_CHARSET).

tmOverhang (short integer)—The amount of extra width (in logical units) that Windows adds to a character when synthesizing italic or boldface. When a font is italicized, the tmAveCharWidth value remains unchanged, because a string of italicized characters has the same overall width as the same string of normal characters. For boldfacing, Windows must slightly expand the width of each character. For a boldfaced font, the tmAveCharWidth value less the tmOverhang value equals the tm- AveCharWidth value for the same font without boldfacing.

tmDigitizedAspectX and tmDigitizedAspectY (short integers)—The aspect ratio for which the font is appropriate. If you specify Proof (under Quality) and check Match Aspect in PICKFONT, then for most devices these values will be equivalent to the pixels-per-logical-inch values returned from GetDeviceCaps. Note, however, that these two TEXTMETRIC fields are switched around in relation to the corresponding GetDeviceCaps parameters: tmDigitizedAspectX is equivalent to the GetDeviceCaps value for the LOGPIXELSY parameter, and tmDigitizedAspectY is equivalent to the value for LOGPIXELSX. If the font is scaled to a larger size, then the tmDigitizedAspectX and tmDigitizedAspectY values increase accordingly.

Because of space restrictions, the following four fields were not included in the display screen of the PICKFONTS program:

tmFirstChar (BYTE)—The character code of the first character in the font. For ANSI_CHARSET fonts, this is normally 32, the space character.

tmLastChar (BYTE)—The character code of the last character in the font. For ANSI_CHARSET fonts, this is normally 255.

tmDefaultChar (BYTE)—The character that Windows uses to display characters that are not in the font. For ANSI_CHARSET fonts, this is normally 128.

tmBreakChar (BYTE)—The character that Windows (and your programs) should use to determine word breaks when justifying text. For ANSI_CHARSET fonts, this is normally 32, the space character.