The information in this article applies to:
SUMMARYWindows 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 MORE INFORMATION
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).
TrueType fonts may have these or more elaborate styles. For example,
the "Lucida Sans" face includes the following style names:
In the case of Lucida Sans with the style of Demibold Roman or
Demibold Italic, the lfWeight value is 600 (FW_DEMIBOLD).
In Windows 3.1, the EnumFontFamilies function can be used to obtain the style name of a font during font enumeration. The EnumFontFamilies function works in a manner very similar to the Windows 3.0 EnumFonts function. The EnumFontFamilies function is prototyped as follows:
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."
The following table illustrates the meanings of the terms, "typeface name," "font name," and "font style:"
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.
When dealing with non-TrueType fonts, typeface name and font name are the same. However, it is important to recognize the distinction when dealing with a TrueType font. For example, CreateFont takes a pointer to a string containing the typeface name of the font to create. It is not valid to use Arial Bold as this string because Arial is a TrueType font and Arial Bold is a font name, not a typeface name. If EnumFontFamilies is called with the lpszFamily parameter pointing to a valid TrueType typeface name, the callback function, which is specified in fntenmprc, will be called once for each font name for that typeface name. For example, if EnumFontFamilies is called with lpszFamily pointing to Lucida Sans, the callback function will be called four times; once for each font name. If the lpszFamily parameter points to the typeface name of a non- TrueType font, such as MS Sans Serif, the callback will be called once for each face size supported by the font. The number of face sizes supported by the font can vary from font to font and from device to device. Note that the callback is called for different sizes, not for different styles. This behavior is identical to that found using the EnumFonts function. Remember that, because TrueType fonts are continuously scalable, there is no reason for the callback function to be called for each size. If the callback function was called for each size that a TrueType font supported, the callback function would be called an infinite number of times! The EnumFontFamilies callback function is prototyped as follows:
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:
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.
To retrieve the style name and full name of a font without using enumeration, use the GetOutlineTextMetrics function. Additional query words: 3.10 3.50 4.00 win16sdk
Keywords : kbNTOS350 kbNTOS351 kbNTOS400 kbSDKWin32 kbWinOS95 |
Last Reviewed: June 22, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |