Westwood Unicode BitFont Format

From ModdingWiki
Jump to: navigation, search
Westwood Unicode BitFont Format
There is no image of a tileset in this format — upload one!
Format typeTileset
HardwareVGA
Max tile count65,535
PaletteHardcoded, variable per use
Tile names?No
Minimum tile size (pixels)0×0
Maximum tile size (pixels)255×?
Plane count1
Plane arrangementLinear
Transparent pixels?Palette-based
Hitmap pixels?No
Metadata?None
Supports sub-tilesets?No
Compressed tiles?No
Hidden data?Yes
Games

In Red Alert 2, Westwood Studios added support for the basic unicode range up to 65,536 symbols. This font type is rather different from the earlier WWFont, going back to 1 bit per pixel, and using a completely different header which seems to be based on that of the earlier non-unicode BitFont format.

The game has only one single font file in this format, namely, game.fnt. While the font's symbols technically represent the unicode range, its 0 to 255 range actually corresponds to Windows-1252 encoding, whereas in normal unicode, this range should be ISO-8859-1. This means the range 128 (0x80) to 160 (0xA0) are used as actual symbols, while in ISO-8859-1 this range only contains control codes. However, the Euro symbol (€) in game.fnt is only at its original position at index 8364 (0x20AC), and not at the 128 (0x80) position where it would be expected in the Windows-1252 encoding.

File format

Header

The font format starts with the following header.

Offset Data type Name Description
0x00 Char[4] Format Literal string "fonT".
0x04 UINT32LE dword04 Unknown. Set to 0x14 in game.fnt.
0x08 UINT32LE Stride Stride of all font image data.
0x0C UINT32LE FontHeight Overall font symbols maximum height, in pixels.
0x10 UINT32LE FontWidth Overall font symbols maximum width, in pixels.
0x14 UINT32LE Count Amount of saved symbol images in the file. Images can be used for any unicode symbol, and can even be used multiple times.
0x18 UINT32LE SymbolDataSize Size of one symbol data block. Should always match 1 + Stride*FontHeight.
0x1C UINT16LE[0x10000] UnicodeTable Array representing the full 65,536 symbol unicode range, referencing which stored symbol block to use for each symbol. Values in this table should be subtracted by 1 to get the index, with an index of -1 (after subtraction) meaning 'empty'.

Since there is only one font of this type in the game, namely game.fnt, it is difficult to see if there is an actual meaning to the unknown value at offset 04, which doesn't seem to have any clear link to the rest of the data.

Though the width and height are saved as 32-bit integers in the header, they are limited by the fact symbol widths in the image data are saved in a single byte, and by the fact the SymbolDataSize, being 1 + (Stride * FontHeight), must also fit in a 32-bit integer.

Image data

The actual font data is very simply straightforward 1 bit per pixel, using the stride and height indicated in the header. The data is prefixed by a byte that gives the symbol width.

Since all symbol image blocks are the same size, the block of data for a specific unicode code point CodePoint can be found by getting the image index from index = UnicodeTable[CodePoint] - 1. If index is -1, the symbol is empty. Otherwise, the data block for that symbol can be found at the address 2001C + SymbolDataSize*index.

Offset Data type Name Description
0x00 UINT8 SymbolWidth Width of this symbol. This does not change the stride of the following data, but only limits the final image width to show.
0x1 BYTE[Stride*FontHeight] SymbolData 1-bpp image block with the stride and height given in the header.

The font does not contain any padding between symbols. Padding is applied automatically by the game, and seems to be one pixel between the symbols.

Technically, data could be hidden in the SymbolData, in the portion of the full stride that is cut off by the local width value.

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
OS Font Editor WindowsYesYesYesNoN/A Can import TrueType fonts. Has issues saving more than 32767 distinct symbols into the font due to handling the data as signed 16 bit. Can't change the font dimensions.
Westwood Font Editor WindowsYesYesYesNoN/A Re-optimises the entire font on save, resulting in slightly longer (±5 second) save times.