4.7 Font and Font Directory Resources

Font resources are different from the other types of resources in that they are not added to the resources of a specific application program. Font resources are added to .EXE files that are renamed to be .FON files. These files are libraries as opposed to applications.

Font resources use a resource group structure. Individual fonts are the components of a font group. Each component is defined by a FONT statement in the .RC file. The group header follows all components and contains all information necessary to access a specific font. The format of a font component resource is as follows:


[Normal resource header (type = 8)]

[Complete contents of the .FNT file follow as the resource body--See the Windows SDK Reference for the format of the .FNT file]

The group header for the fonts is normally last in the .RES file. Note that unlike cursor and icon groups, the font group need not be contiguous in the .RES file. Font declarations may be placed in the .RC file mixed with other resource declarations. The group header is added automatically by RC at the end of the .RES file. Programs generating .RES files must add the FONTDIR entry manually. The group header has the following structure:


[Normal resource header (type = 7)]

WORD NumberOfFonts;     // Total number in .RES file

The remaining data is repeated for every font in the .RES file.


WORD fontOrdinal;
struct FontDirEntry {
     WORD     dfVersion;
     DWORD    dfSize;
     char     dfCopyright[60];
     WORD     dfType;
     WORD     dfPoints;
     WORD     dfVertRes;
     WORD     dfHorizRes;
     WORD     dfAscent;
     WORD     dfInternalLeading;
     WORD     dfExternalLeading;
     BYTE     dfItalic;
     BYTE     dfUnderline;
     BYTE     dfStrikeOut;
     WORD     dfWeight;
     BYTE     dfCharSet;
     WORD     dfPixWidth;
     WORD     dfPixHeight;
     BYTE     dfPitchAndFamily;
     WORD     dfAvgWidth;
     WORD     dfMaxWidth;
     BYTE     dfFirstChar;
     BYTE     dfLastChar;
     BYTE     dfDefaultChar;
     BYTE     dfBreakChar;
     WORD     dfWidthBytes;
     DWORD    dfDevice;
     DWORD    dfFace;
     DWORD    dfReserved;
     char     szDeviceName[];
     char     szFaceName[];
     };