PRODUCT : Resource Workshop NUMBER : 737 VERSION : 1.0 OS : WIN DATE : October 19, 1993 PAGE : 1/5 TITLE : Creating/Using Custom Fonts with Resource Workshop INTRODUCTION: One of the greatest features of Microsoft Windows is its ability to allow applications to share system resources (fonts, printer drivers, etc.). This 'device independent' approach is a mixed blessing to application developers: While this capability makes Windows work better for its users, it makes life a nightmare for an application developer. This document addresses the issue of how to create a custom font, to cause Windows to recognize it, and to actually use it in your own applications. It is divided into two sections: I. Creating a custom font library II. Using custom fonts in your applications This document assumes that you own Borland C++ 2.0. It is recommended that you own Resource Workshop as well. I. CREATING A CUSTOM FONT LIBRARY: Windows supports the use of custom fonts by allowing the user (or an application) to install a 'font resource' into the system font pool. A font resource is a font library (.FON) file which contains at least one font (.FNT). Individual .FNT files apparently do not count as font resources. Creating the custom font: First, you can use the Resource Workshop to create a .FNT font file. RW can edit both .FNT and .FON files, but can only create .FNT files. .FNT files are individual fonts while .FON files are collections of .FNT files (usually representing different sizes of the same font). Since Windows expects .FON files, and since Resource Workshop creates only .FNT files, you must create .FON files manually. Once you have created a .FON file, you can use your new font(s) in your own applications! Constructing a font library: PRODUCT : Resource Workshop NUMBER : 737 VERSION : 1.0 OS : WIN DATE : October 19, 1993 PAGE : 2/5 TITLE : Creating/Using Custom Fonts with Resource Workshop A font library is basically just a DLL with an empty code segment and a file extension of .FON. You may choose any name for your font library up to eight letters. Before you begin, you will need the following: * At least one .FNT font file (possibly created using Resource Workshop) * A .ASM file containing the empty code segment * A .RC file listing the fonts to be included in the font library * A .DEF file for the font library The .ASM empty code segment module: In order to build the font library, you need to have at least one code segment. This segment should be empty. Here is some sample code that will do the trick: .model large CODE SEGMENT CODE ENDS end You will need to create an empty .ASM file (give it the same name as your font) and insert this code. Once you have created this file, you will need to assemble it using: TASM XXXXXXXX.asm "XXXXXXXX" should be replaced with the name of your font. You have now created the empty code segment module. The .RC resource script file: You should create a new file with the extension '.RC'. Give the file the same name as your font. The .RC file may contain as many lines as you wish. Here is the format for the file: 1 FONT xxxxxxxx.FNT PRODUCT : Resource Workshop NUMBER : 737 VERSION : 1.0 OS : WIN DATE : October 19, 1993 PAGE : 3/5 TITLE : Creating/Using Custom Fonts with Resource Workshop 2 FONT yyyyyyyy.FNT : : "xxxxxxxx" and "yyyyyyyy" are the names of .FNT font files that make up the individual fonts in the font library. The .DEF module definition file: The module definition file should be a file with the same name as your font, with a .DEF extension. The .DEF file should look like this: LIBRARY XXXXXXXX DESCRIPTION 'FONTRES yyyyyyy' STUB 'WINSTUB.EXE' DATA NONE "XXXXXXXX" should be the UPPERCASE name of your font library. "yyyyyyyy" can be in one of three formats: - aspect, logpixelsx, logpixelsy: comment - CONTINUOUSSCALING: comment - DEVICESPECIFIC devicetypegroup: comment See Chapter 18 of the Microsoft Windows Guide to Programming book for details on each of these three formats. Putting it all together: Building the .FON file: There are essentially two steps to building the finished .FON font library file: 1. Linking the empty code segment module into an 'executable' .FON file 2. Adding the actual font resources to the library To link the empty code segment module into a .FON file, you can use the following command: PRODUCT : Resource Workshop NUMBER : 737 VERSION : 1.0 OS : WIN DATE : October 19, 1993 PAGE : 4/5 TITLE : Creating/Using Custom Fonts with Resource Workshop TLINK -Twd xxxxxxxx.obj, xxxxxxxx.fon,,,xxxxxxxx.def "xxxxxxxx" is the name of your font library. Notice the - Twd switch, which tells TLINK to form a Dynamic Link Library (DLL). Font libraries are really just resource-only DLL's (which have no code). To complete the .FON file, you must append the font resources onto the font library. This is done with: RC xxxxxxxx.rc xxxxxxxx.fon "xxxxxxxx" is the name of your font library. II. USING CUSTOM FONTS Congratulations! You have now created a custom font. You are almost certainly ready to use the custom font resource in your own program. Loading the font: The first order of business is to get Windows to recognize the font. This can be accomplished in one of two ways. First, you can use the Windows Control Panel to add the font to the list of system fonts. Alternately, you can use the function AddFontResource(). This function takes a filename and causes Windows to load your font. Don't forget to use RemoveFontResource() when your program terminates. Using the font: First, you should initialize a LOGFONT structure with the information describing the font that you wish to use. Use CreateFontIndirect to get a handle to your font (HFONT). Once this HFONT is selected into a device context, any text output functions using that device context will use your font. Cleanup: You should use DeleteObject to remove the font (HFONT) when you are finished with it. Also, if you have used PRODUCT : Resource Workshop NUMBER : 737 VERSION : 1.0 OS : WIN DATE : October 19, 1993 PAGE : 5/5 TITLE : Creating/Using Custom Fonts with Resource Workshop AddFontResource to load the font, you should call RemoveFontResource. DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.