INFO: Retrieve Font Styles Using EnumFontFamiliesEx

ID: Q200111


The information in this article applies to:
  • Microsoft Win32 Device Driver Kit (DDK) for Windows NT


SUMMARY

BETA INFORMATION BETA INFORMATION BETA INFORMATION

This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about obtaining support for a Beta release, please see the documentation included with the Beta product files, or check the Web location from which you downloaded the release.

BETA INFORMATION BETA INFORMATION BETA INFORMATION


The following article is a detailed explanation of using the EnumFontFamiliesEx function. It also serves as an update to the article "Retrieving Font Styles Using EnumFontFamilies."


MORE INFORMATION

The EnumFontFamiliesEx function is similar to the older EnumFontFamilies function. Following is the prototype for EnumFontFamiliesEx:


Int EnumFontFamiliesEx (
   HDC hdc,               // handle to device context
   LPLOGFONT lpLogfont,         // pointer to LOGFONT struct
   FONTENUMPROC lpEnumFontFamExProc,   // pointer to callback function
   LPARAM lParam,            // application-supplied data
   DWORD dWFlags            // reserved = 0
); 


The lpLogfont points to the LOGFONT structure, which has the information about the fonts for enumeration.

The LOGFONT structure:


typedef struct tagLOGFONT {

   LONG lfHeight;
   LONG lfWidth;
   LONG lfEscapement;
   LONG lfOrientation;
   LONG lfWeight;
   BYTE lfItalic;
   BYTE lfUnderline;
   BYTE lfStrikeOut;
   BYTE lfCharSet;
   BYTE lfOutPrecision;
   BYTE lfClipPrecision;
   BYTE lfQuality;
   BYTE lfPitchAndFamily;
   TCHAR lfFaceName [LF_FACESIZE];

} LOGFONT; 


The lfCharSet parameter specifies the character set. The following values are defined:

ANSI_CHARSET
ARABIC_CHARSET
BALTIC_CHARSET
CHINESEBIG5_CHARSET
DEFAULT_CHARSET
EASTEUROPE_CHARSET
GB2312_CHARSET
GREEK_CHARSET
HANGUEL_CHARSET
HANGUL_CHARSET
HEBREW_CHARSET
JOHAB_CHARSET
MAC_CHARSET
OEM_CHARSET
RUSSIAN_CHARSET
SHIFTJIS_CHARSET
SYMBOL_CHARSET
THAI_CHARSET
TURKISH_CHARSET
VIETNAMESE_CHARSET 
If the lfCharSet parameter is set to DEFAULT_CHARSET, the function will enumerate every font in the system as many times as there are Windows character sets supported in this font.

For example, the Arial font shipping with the Windows 2000 operating system supports the following nine character sets:

ANSI_CHARSET
HEBREW_CHARSET
ARABIC_CHARSET
GREEK_CHARSET
TURKISH_CHARSET
VIETNAMESE_CHARSET
BALTIC_CHARSET
EASTEUROPE_CHARSET
RUSSIAN_CHARSET 
This means that the callback function is called nine times for the Arial font, where on each callback the fields LOGFONT.lfCharSet and TEXTMETRICS.tmCharSet are set to a different charset value from the above set of supported character sets in the Arial font.

If the lfCharSet value on input is set to a value different than DEFAULT_CHARSET, then only those fonts in the system that support this character set will be enumerated. For example, if lfCharSet is set to RUSSIAN_CHARSET, then the Arial font from the above example enumerates and the callback function calls for Arial only once. If lfCharSet value is set to JOHAB_CHARSET on input, the Arial font is not enumerated at all.

The parameter lfFaceName is a null-terminated string that specifies the typeface name of the font. Its length must not exceed 32 characters, including the null terminator. If this is set to an empty string, then the function enumerates one font in each available typeface name.

  • lpEnumFontFamExProc: This parameter points to the callback function defined by EnumFontFamExProc().


  • lParam: This specifies a 32-bit application-defined value which is passed to the callback function along with font information.


  • dwFlags: Must be set to 0.


The EnumFontFamiliesEx() callback function is prototyped in the following manner:


int CALLBACK EnumFontFamExProc (
ENUMLOGFONTEX *lpelfe,
NEWTEXTMETRICEX *lpntme,
int  FontType,
LPARAM lParam
); 


The lpelfe parameter points to an ENUMLOGFONTEX structure that contains information about the logical attributes of the font. The lpntme parameter also points to a structure that contains information about the physical attributes of a font. Set this to NEWTEXTMETRICEX for TrueType fonts, or TEXTMETRICEX for other fonts.

The callback function is called once for each font name of the TrueType font specified by the lfFaceName in the LOGFONT structure. In addition, it gets multiplicatively called for each script supported by that font. Thus, the callback is made for num_of_font_names X num_of_scripts. However, for non-TrueType fonts, the callback function is called once for each face size supported by that font. The number of face sizes supported by each font differs from those supported by another font, and also varies from machine to machine. For example, if MS Sans Serif supports face sizes 8, 10, 12, 14, 18 and 24 on a particular machine, then the callback function is called 6 times (for the above 6 different face sizes). Although, this is not the case for TrueType fonts since these fonts are continuously scalable and if the callback were done for each size of the TrueType font, then there would be an infinite number of callbacks.


// Sample Test piece of code:
#include <Windows.H>
#include <StdIO.H>
#include <ConIO.H>

int CALLBACK EnumFontFamiliesExProc( ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam )

{
        printf( "%s\n", lpelfe->elfFullName );
        return 1;
}
int main( int __argc, char** __argv )

{
        HDC hDC = GetDC( NULL );

        LOGFONT lf = { 0, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0,
         0, "Courier New" };
        EnumFontFamiliesEx( hDC, &lf, EnumFontFamiliesExProc, 0, 0 );
        ReleaseDC( NULL, hDC );
        return 0;
} 

Additional query words: EnumFontFamilies EnumFontFamiliesEx LOGFONT EnumFontFamExProc

Keywords : kbDDK kbFont kbGDI kbNTOS400 kbPrinting kbTTFonts
Version : winnt:
Platform : winnt
Issue type : kbinfo


Last Reviewed: May 19, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.