Embedding .FON Files in an MS-DOS .EXE File

ID: Q89144


The information in this article applies to:


SUMMARY

You can create MS-DOS programs that load fonts from .FON font files. It is sometimes desirable to embed a font into an MS-DOS .EXE file so that there are fewer files to distribute with the program. However, it is not possible to embed the .FON files into .EXE files.

You can create a new font resource file (.FNT) and embed it into the MS-DOS .EXE file rather than placing it into a .FON file. A Windows resource compiler such as RC.EXE supplied with the Windows 3.0 Software Development Kit (SDK) or Windows 3.1 SDK needs to be used to embed a .FNT file into an .EXE file or to create a .FON file.

The purpose of embedding a font into an MS-DOS .EXE file is to have fewer files to distribute. The _registerfonts() and _setfont() functions will still read the font information from the .EXE file at run time. Embedding the font into the executable does not stop these functions from accessing the disk.


MORE INFORMATION

To embed a .FNT file into an MS-DOS executable, do the following:

  1. Create a .FNT file using a font editor, such as the one supplied with the Windows 3.0 or 3.1 SDK. When creating the .FNT file with the font editor, you must save the .FNT file as a Windows 2.0 font resource file to allow it to work with the Microsoft C graphics libraries. For this example, the .FNT file will be called FONT.FNT.


  2. Compile and link the executable that will use the font. The following example program will simply display a message in the font embedded into the same file. For this example, the executable will be called HELLO.EXE:
    
           /* Compile options needed: /link graphics.lib
           */ 
    
           #include <graph.h>
           #include <conio.h>
    
           void main (short argc, char * argv[])
           {
               _registerfonts (argv[0]);
               _setfont ("n1");
               _setvideomode (_MAXRESMODE);
               _outgtext ("hello");
               getch ();
               _setvideomode (_DEFAULTMODE);
           } 


  3. Create the following .RC file, replacing the font resource name FONT.FNT with the name of the font resource file that is to be embedded into the executable. For this example, this file will be called FONT.RC:
    
          1 FONT FONT.FNT 


  4. Create the following C source file and compile it. For this example, this file will be called FNTHELLO.C:
    
           /* Compile options needed: /c
           */ 
    
           int junk; 


  5. Create the following .DEF file replacing the program name HELLO.EXE with the name of the MS-DOS .EXE file that the font will be embedded in. For this example, this file will be called FNTHELLLO.DEF:
    
           LIBRARY font
           EXETYPE WINDOWS
           DESCRIPTION 'font'
           STUB 'HELLO.EXE'
           DATA NONE 


  6. Use the following command to run LINK 5.01 or later to create a segmented executable:
    
           LINK FNTHELLO.OBJ, FNTHELLO.EXE, NUL, /NOD, FNTHELLO.DEF 


  7. Run RC.EXE to add the font to the executable:
    
           RC FONT.RC FNTHELLO.EXE 


After completing the steps listed above, the executable file FNTHELLO.EXE can be run to cause the string "hello" to be displayed in the font stored in the executable.


REFERENCES

- Microsoft Windows Software Development Kit "Guide to Programming" manual for version 3.0

Additional query words: kbinf 6.00 6.00a 6.00ax 7.00 1.00 1.50


Keywords          : kb16bitonly 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 26, 1999