FON File Format

This document describes the FON bitmap font format used by the Fallout engine.

Background

FON files are one of the Fallout engine's bitmap font formats. Fallout 2 loads up to ten text fonts named font0.fon through font9.fon for the low-numbered text font manager. Worldmap and interface text can also use AAF-based interface fonts, so FON should not be treated as the only worldmap font format. FON glyphs are non-scalable raster images and do not contain anti-aliasing information.

All numeric fields in the file are 32-bit little-endian integers. The two pointer fields in the header are serialized from the original in-memory structure, but the engine ignores their file values and allocates fresh arrays when loading.

FON viewer

The viewer below parses the same layout described on this page. The glyph grid labels each glyph by its numeric index, and the text preview maps each input byte directly to the glyph with the same index. This matches the engine's 8-bit text rendering path: values outside the loaded glyph count do not draw anything.

Glyph count-
Line height-
Letter spacing-
Bitmap data start-
Bitmap data size-

Text preview

Glyph grid

Structure

OffsetSizeTypeBlockDescription
0x04intHeaderNumber of glyph images in the file. The shorthand num is used below. Some fonts contain fewer than 256 glyphs.
0x44intHeaderFont height in pixels. The renderer uses this as the line height for every glyph.
0x84intHeaderHorizontal spacing, in pixels, added after each glyph.
0xC4FontInfo*HeaderSerialized pointer to the glyph descriptor array. Note: This field only matters in memory. In the file, the loader ignores the stored value.
0x104unsigned char*HeaderSerialized pointer to the glyph bitmap data. Note: This field only matters in memory. In the file, the loader ignores the stored value.
0x144intGlyph descriptor arrayGlyph 0 width in pixels
0x184intGlyph descriptor arrayGlyph 0 offset, relative to the start of the bitmap data block
0x1C4intGlyph descriptor arrayGlyph 1 width in pixels
0x204intGlyph descriptor arrayGlyph 1 offset, relative to the start of the bitmap data block
.........Glyph descriptor array...
0x14 + 8 * num1unsigned charGlyph bitmap data. Each glyph starts at its descriptor's data offset.
.........Glyph bitmap data. Each glyph starts at its descriptor's data offset.

Parsing notes

FON has no magic number or version field. Tools usually identify it by filename and location, or by validating that the header, descriptor table, and bitmap offsets describe a plausible file.

The header is always 20 bytes long. The descriptor table begins immediately after it at 0x14 and contains num entries, each 8 bytes long. The bitmap data block therefore starts at 0x14 + 8 * num. Descriptor offsets are relative to this bitmap data block, not to the beginning of the file.

Each glyph consumes ((width + 7) / 8) * height bytes. This is integer arithmetic, so adding 7 before division is equivalent to rounding the row width up to the next byte. A zero-width glyph consumes no bitmap bytes, but can still occupy a glyph index. The original engine computes the total bitmap block length from the last descriptor; file inspection tools should additionally validate every descriptor so malformed offsets cannot point outside the file.

FON files store shape only. They do not store colors, palette indexes, kerning pairs, Unicode mappings, or proportional layout metadata beyond each glyph's width and the global spacing value.

Runtime notes

In Fallout 2, FON files are registered as font ids 0 through 9. The separate AAF interface font manager registers font ids 100 through 110. A call such as fontSetCurrent(3) selects a loaded FON font, while fontSetCurrent(101) selects an AAF interface font.

The window manager initializes the FON text font system during startup. Missing individual fontN.fon files are tolerated, but initialization fails if none of the ten FON fonts can be loaded.

Shadow, underline, and monospaced text are renderer options applied by the font manager at draw time. They are not stored in the FON file.

FON and AAF comparison

FeatureFONAAF
Typical filesfont0.fon through font9.fonfont0.aaf and other interface font files
Font id range0 through 9 in Fallout 2 CE100 through 110 in Fallout 2 CE
Glyph countStored in the file headerAlways 256 descriptor slots
Pixel data1 bit per pixel; set bits draw the chosen text colorOne value per pixel; values 1 through 9 represent brightness levels
Integer byte orderLittle-endian 32-bit integersBig-endian 16-bit and 32-bit integers

Memory structure

Mapper2.exe and fallout2.exe use the following in-memory structures for loaded FON files:

typedef struct {
    int num;                // number of glyph images in the file
    int height;             // line height in pixels
    int spacing;            // horizontal spacing between adjacent glyphs
    FontInfo* info;         // pointer to glyph descriptors
    unsigned char* data;    // pointer to glyph bitmap data
} Font;

Glyph descriptor

typedef struct {
    int width;   // glyph width in pixels
    int offset;  // glyph image offset in the data block
} FontInfo;

The engine computes the size of the bitmap data block from the final glyph descriptor:

last = font.num-1; // Index of the last glyph in the font
size = font.info[last].offset + (font.info[last].width + 7) / 8 * font.height;

Row byte calculation

(font.info[last].width + 7) / 8

is the number of bytes needed for one row of a glyph image. Glyph bitmap data is a 1-bit matrix, with the most significant bit of each byte drawn first. A set bit draws the current text color; a clear bit leaves the destination pixel unchanged.

Text rendering

During rendering, each byte in the source text is used as a glyph index. When the index is present in the font, the renderer draws that glyph and advances by glyph.width + font.spacing pixels. Missing glyph indexes are skipped.

Example

The following example shows an 8x16 pixel glyph described by 16 bitmap bytes:

00 00 7e 81 a5 81 81 bd 99 81 81 7e 00 00 00 00

The bit matrix is:

00       00000000        ........
00       00000000        ........
7e       01111110        .######.
81       10000001        #......#
a5       10100101        #.#..#.#
81       10000001        #......#
81       10000001        #......#
bd  ==>  10111101  ==>   #.####.#
99       10011001        #..##..#
81       10000001        #......#
81       10000001        #......#
7e       01111110        .######.
00       00000000        ........
00       00000000        ........
00       00000000        ........
00       00000000        ........

Tools

FON editor

FON editor source code

Source code

Fallout 2 Community Edition FON loader and renderer - C++

Fallout 2 Community Edition font manager declarations - C++

Fallout 2 Community Edition AAF interface font manager - C++

Fallout 2 Community Edition window manager font initialization - C++

History

Fallout 2 Community Edition worldmap font usage - C++

2020-01-16 - Ported from https://falloutmods.fandom.com/wiki/FON_File_Format