96-Character Font File Structure

The structure of a Fastgraph/Fonts 96-character font file is surprisingly simple. A 96-character font file contains definitions for ASCII characters 32 through 127 decimal, although character 127 isn't used. Each character is stored in a bitmap that is the same size for all characters in the font. The bitmap width is the width of the font's widest character, while its height is the height of the font's tallest character. Given this information, we can summarize the font file structure in the following table.

byte offset

field size

field name

description

0

1

MaxX

The width in bytes of the font's widest character. There are 8 pixels per byte.

1

1

MaxY

The height of the font's tallest character.

2

96

Xsizes

The width in pixels plus one or more kerning pixels for each character (ASCII values 32 to 127).

98

96

Ysizes

The height in pixels for each character (ASCII values 32 to 127).

194

96*size

Bitmap

The actual bitmap for each of the 96 characters. The size of each bitmap is MaxX*MaxY.

Each character's bitmap is stored in rows from top to bottom and includes space for descender characters (even if the character is not a descender). Within each row, the bitmap values are stored from left to right. In addition, each row may include one or more blank pixels (for kerning) appended to the end of the row.

To illustrate the bitmap format, consider the following two bitmaps for the lower case characters "x" and "y". The "x" bitmap is 10 pixels wide (including one pixel of kerning) and 10 pixels high (including three rows for descenders, even though "x" is not a descender). The "y" bitmap is 9 pixels wide and 10 pixels high.

* * * * . . * * * . F3 80    * * * . . * * * . E7 00
. . * . . . . * . . 21 00    . * . . . . * . . 42 00
. . . * . . * . . . 12 00    . . * . . . * . . 22 00
. . . * * * . . . . 1C 00    . . * . . * . . . 24 00
. . * . . * . . . . 24 00    . . . * . * . . . 14 00
. * . . . . * . . . 42 00    . . . * * . . . . 18 00
* * * . . * * * * . E7 80    . . . . * . . . . 08 00
. . . . . . . . . . 00 00    . . . * . . . . . 10 00
. . . . . . . . . . 00 00    . . . * . . . . . 10 00
. . . . . . . . . . 00 00    * * * . . . . . . E0 00

The hexadecimal values to the right of each row are the bitmap values for the bytes in that row. To compute these values, set the dot (.) pixels to 0 and the asterisk (*) pixels to 1, then convert the resulting binary values to hex. When the rows do not contain a multiple of 8 pixels, logically pad them with zero pixels to compute the hex values.

96-character font files contain bitmaps for the characters whose ASCII decimal values are 32 through 127. This means the offset for a given character is

(ASCIIvalue - 32) * size + 194

where ASCIIvalue is the character's ASCII value, and size is the bitmap size for each character (the value 194 is the offset within the file for the first character's bitmap). For this example, let's assume the value of MaxX is 2 and the value of MaxY is 15, making the bitmap size 30 bytes. The ASCII value of "x" is 120, so its bitmap offset is (120-32)*30+194, or 2,834. Similarly, the ASCII value of "y" is 121, so its offset is 2,864. The bitmap values are then stored in the file as shown below.

2830   ww ww ww ww F3 80 21 00 12 00
2840   1C 00 24 00 42 00 E7 80 00 00
2850   00 00 00 00 ** ** ** ** ** **
2860   ** ** ** ** E7 00 42 00 22 00
2870   24 00 14 00 18 00 08 00 10 00
2880   10 00 E0 00 ** ** ** ** ** **
2890   ** ** ** ** zz zz zz zz zz zz

The ww bytes are the end of the bitmap for the "w" character, and the zz bytes are the beginning of the "z" bitmap. The ** bytes are filler bytes that pad the "x" and "y" bitmaps to their fixed 30-byte size. All such filler bytes must be zero.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.