Westwood Font Format v2

From ModdingWiki
Jump to navigation Jump to search
Westwood Font Format v2
Eob font8.png
Format typeFont
Max glyph count128
Minimum glyph size (pixels)0×0 (global)
Maximum glyph size (pixels)8×255 (global)
Access modeIndexed
Metadata?None
Bitmap glyphs?Yes
Vector glyphs?No
Compressed glyphs?No
Hidden data?Yes
Games

This is the second type of bitmap font created by Westwood Studios, used in the Eye of the Beholder and BattleTech games. It is a 1-bit-per-pixel font with a fixed set of 128 characters. The format has a data index, and a header specifying global dimensions for all characters, though the width is limited to 8; the amount of pixels in a single byte.

File format

Header

The font format starts with the following header.

Offset Data type Name Description
0x00 UINT16LE Size File size.
0x02 UINT16LE[0x80] Offsets Offset of the data block for each of the 128 symbols. Offsets are relative to the start of the file.
0x102 BYTE Height Font symbol height, in pixels.
0x103 BYTE Width Font symbol width, in pixels. Can't be larger than 8.

Following this header is the data, normally one block per symbol, each symbol length being the height in bytes.

Optimisation

Later versions of the font optimise the data by making the offsets for any identical symbols in the font refer to the same data, greatly reducing the data for the symbols before index 0x20. That system works on this format too, since the games generally just follow the header instructions for finding the data without doing any further checks, but do note that games may look at the sizes of their files as simple integrity check. Eye of the Beholder 1 refuses to launch if its font sizes are deemed illegal; Eye of the Beholder 2, in contrast, has no such issues.

Note that this refusal to launch may simply be caused by an internal table of file sizes, which would need to be found and modified for any more in-depth modding anyway. But for fonts, the issue is easily solved simply by not using any optimisation. Since this is a fixed-length font without variable character sizes, any font with specific dimensions will always have exactly the same file size.

Rendering

To render a character from the font, you could use something like the following code:

C# .NET:

TFIXEDFONT fnt;      // assume this is loaded and initialized
Int32 x, y;          // position to draw the character
Int32 color;         // color of the text
Char c;              // the character to be drawn

UInt16 offset = fnt.Offsets[c];
for (Int32 h = 0; h < fnt.Height; h++)
{
    Byte line = fnt.Data[offset + h];
    Byte bit = 0x80;
    for (int w = 0; w < fnt.Width; w++)
    {
        if ((line & bit) != 0)
            DrawPixel(x + w, y + h, color);
        bit = bit >> 1;
    }
}

Tools

The following tools are able to work with files in this format.

Name PlatformView images in this format? Convert/export to another file/format? Import from another file/format? Access hidden data? Edit metadata? Notes
Westwood Font Editor WindowsYesYesYesNoN/A