INFO: Retrieving Font Styles Using EnumFontFamilies()ID: Q84131
|
Windows version 3.1 introduces the concept of a font style. In previous versions of Windows, a font could have the bold, italic, underline, and strikeout properties, which were supported by respective members in the LOGFONT and TEXTMETRIC structures. Windows 3.1 also supports these properties, as well as a style name for TrueType fonts. The article describes how to obtain the font style name during font enumeration, using the EnumFontFamilies function. For more information about obtaining style information without enumerating the fonts, query on the following words in the Microsoft Knowledge Base:
prod(winsdk) and getoutlinetextmetrics
In Windows 3.1, "style" refers to the weight and slant of a font.
Windows supports a wide range of weights in the lfWeight member of the
LOGFONT structure. (Two examples of weights are FW_BOLD, which is
defined as 700, and FW_THIN, which is defined as 100). Very few
applications, however, use any weights other than FW_BOLD and
FW_DONTCARE (defined as 0).
Windows 3.1 builds on the support presently in Windows for these
variations in weight and slant. Style names are NOT used in the
LOGFONT structure except when the fonts are enumerated with
EnumFontFamilies.
The ChooseFont dialog box in the common dialog boxes Dynamic-Link
Library (COMMDLG.DLL) demonstrates how style names are used. The
ChooseFont dialog box has two list boxes: Font and Font Style. The
Font list box lists the face names for all fonts installed and the
Font Style list box lists the font styles for the currently selected
face. For example, if any non-TrueType font (such as MS Sans Serif) is
selected, the following styles appear in the Font Style list box:
Regular
Bold
Italic
Bold Italic
TrueType fonts may have these or more elaborate styles. For example,
the "Lucida Sans" face includes the following style names:
Regular
Italic
Demibold Roman
Demibold Italic
In the case of Lucida Sans with the style of Demibold Roman or
Demibold Italic, the lfWeight value is 600 (FW_DEMIBOLD).
int EnumFontFamilies(HDC hdc, LPCSTR lpszFamily,
FONTENUMPROC lpfnEnumProc, LPARAM lpData)
The lpszFamily parameter points to a null-terminated string that
specifies the family name (or typeface name) of the desired fonts. If
this parameter is NULL, EnumFontFamilies selects and enumerates one
font of each available font family. For example, to enumerate all
fonts in the "Arial" family, lpszFamily points to a string buffer
containing "Arial."
Typeface Name Font Name Font Style
------------- --------- ----------
Arial Arial Regular
Arial Bold Bold
Arial Italic Italic
Arial Bold Italic Bold Italic
Courier New Courier New Regular
Courier New Bold Bold
Courier New Italic Italic
Courier New Bold Italic Bold Italic
Lucida Sans Lucida Sans Regular
Lucida Sans Italic Italic
Lucida Sans Demibold Roman Demibold Roman
Lucida Sans Demibold Italic Demibold Italic
MS Sans Serif MS Sans Serif Regular
MS Sans Serif Bold
MS Sans Serif Italic
MS Sans Serif Bold Italic
The first three typefaces in the above table are TrueType faces, the
remaining typeface is MS Sans Serif. The typeface name is also
sometimes referred to as the family name.
int CALLBACK EnumFontFamProc(LPNEWLOGFONT lpnlf,
LPNEWTEXTMETRIC lpntm,
int FontType, LPARAM lpData)
The lpnlf parameter points to a LOGFONT structure that contains
information about the logical attributes of the font. If the typeface
being enumerated is a TrueType font [(nFontType | TRUETYPE_FONTTYPE)
is TRUE], this LOGFONT structure will have two additional members
appended to the end of the structure, as follows:
char lfFullName[LF_FACESIZE*2];
char lfStyleName[LF_FACESIZE];
It is important to remember that these two additional fields are used
*only* during enumeration with EnumFontFamilies and nowhere else in
Windows. The documentation for the EnumFontFamilies function on pages 266-268 of the "Microsoft Windows Software Development Kit:
Programmer's Reference, Volume 2: Functions" manual refers to the
NEWLOGFONT structure which contains the additional members listed
above. However, the NEWLOGFONT structure is not defined in the
WINDOWS.H header file. To address this situation, use the ENUMLOGFONT structure which is defined in the WINDOWS.H file but is not listed in the Windows SDK documentation.
Additional query words: 3.10 3.50 4.00 win16sdk
Keywords : kbNTOS350 kbNTOS351 kbNTOS400 kbSDKWin32 kbWinOS95
Version : WINDOWS:3.1,95; winnt:3.5,3.51,4.0
Platform : WINDOWS winnt
Issue type : kbinfo
Last Reviewed: June 22, 1999