Example: Manual Font Loading

We can load font files automatically with fgf_load() or manually with fgf_define(). Example FGFW4 illustrates manual font loading. In this example, the font file contents are read into a fixed 8,258-byte array, though in practice it's usually preferable to allocate dynamic memory for this purpose. The size of the array (or allocated memory block) must be at least as large as the font file. The fgf_define() function reformats the font data, so you cannot rely on the array's original contents after fgf_define() returns.

If your program uses manual font loading and allocates dynamic memory for a font, it must not free the memory until the font is no longer needed. If you free memory containing a font and later try to display characters from that font, the results are unpredictable.

When you use fgf_unload() to unload a font previously loaded with fgf_load(), Fastgraph/Fonts deallocates the font memory and releases the font handle. If you load a font with fgf_define(), your program is responsible for the necessary memory management functions to release the font memory, but that does not make the font handle available again. If you want to reclaim a font handle, use fgf_undefine(). It's not necessary to use fgf_undefine() unless your program must perform more than 256 font loads during its execution.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.