Enumerating Fonts

You can enumerate the available fonts by calling the EnumFonts or EnumFontFamilies function. These functions send information about the available fonts to a callback function that the application supplies. The callback function stores the information in the LOGFONT structure and in either the NEWTEXTMETRIC structure for TrueType fonts or the TEXTMETRIC structure for raster fonts. By using the information returned from these functions, you can limit the user's choices to available fonts only.

The EnumFontFamilies function is similar to the EnumFonts function but includes some extra functionality for use with TrueType fonts. The EnumFontFamilies function enumerates all the styles associated with a specified typeface, not simply the bold and italic attributes. For example, when the system includes a TrueType font called Courier New Extra-Bold, EnumFontFamilies lists it with the other Courier New fonts.

Note Despite its name, EnumFontFamilies actually enumerates the styles associated with a specified typeface — for example, Arial — rather than a font family, such as Roman.

If you do not supply a typeface name, the EnumFonts and EnumFontFamilies functions supply information about one font in each available family. To enumerate all the fonts in a device context, you can specify NULL for the typeface name, compile a list of the available typefaces, and then enumerate each font in each typeface.

A font resource is a group of individual fonts in a specified character set that have various combinations of heights, widths, and pitches. You can load font resources and add the fonts in each resource to the operating system font table by using the AddFontResource function. To remove a font resource from the font table, you can use the RemoveFontResource function.