Westwood Font Format v3
This is the third type of bitmap font created by Westwood Studios, used in the Lands of Lore and Legend of Kyrandia series and in their early RTS games. It is a 4-bit-per-pixel font with a variable amount of characters, which allows the separate symbols to specify their width, height and Y-offset.
The font format starts with the following header.
|0x02||BYTE||DataFormat||Data format. 0x00 for v3, 0x02 for v4.|
|0x03||BYTE||SigByte1||Signature byte. Always 0x05.|
|0x04||BYTE||SigByte2||Signature byte. Always 0x0E.|
|0x05||BYTE||SigByte3||Signature byte. Always 0x00.|
|0x06||UINT16LE||OffsetsListOffset||Offset of the array of data offsets.|
|0x08||UINT16LE||WidthsListOffset||Offset of the array of symbol widths|
|0x0A||UINT16LE||FontOffsetStart||Start address of the font data. Unused in v3, since the addresses in the |
|0x0C||UINT16LE||HeightsListOffset||Offset of the array containing the symbol heights and Y-offsets.|
|0x0E||UINT16LE||Unknown||Unknown. Always 0x1012.|
|0x10||BYTE||Unknown||Unknown. Always 0x00.|
|0x11||BYTE||NrOfChars||Number of characters. Actually, this is the byte value of the last character in the list, so the real number of characters is this value plus one.|
|0x12||BYTE||Height||Overall font symbols maximum height, in pixels.|
|0x13||BYTE||Width||Overall font symbols maximum width, in pixels.|
Following this header are the referenced arrays and the font data, normally in this order:
- Array of UINT16LE values indicating the offset of the data for each symbol, relative to the start of the file. The start offset of this list is specified by
- Array of byte values indicating the symbol widths, in pixels. The start offset of this list is specified by
- Array containing two bytes per entry; the first being the Y-offset, the second the height in pixels. The start offset of this array is specified by
- Actual symbol data referenced in the offsets list.
However, since the game just follows the offsets as it reads them, this order probably doesn't really matter.
The fonts could technically be pushed slightly beyond their normal limit of 65535 bytes, by making sure the last symbol offset referred to in the index is still below that maximum. Though there is no guarantee that the game will reserve enough space to fully read such large font files into memory, and third party apps to view or edit the font may have trouble identifying such files, since the file size saved in the header will always be incorrect.
The font data is uncompressed, but it is optimised by making the offsets for any identical symbols in the font refer to the same data. The use of this technique means that very little space is lost by including the normally unusable symbols range of 0 to 31. Most of these indices are filled with the same one or two filler symbols, which will each only be saved once despite being used dozens of times. This also allows fonts with no difference in upper and lower case to expose the same image data for both, with barely any increase in file size.
This optimisation technique can actually be used on any indexed image type, in any game, as long as the game doesn't do any elaborate checks on the expected data length.
The actual font data is 4 bit per pixel, and always uses the minimum stride per line, so, for example, a font with a width of 5 will require 3 bytes to contain all five nybbles, and, as is common for image formats in general, will have these three bytes for each line, without optimising a next line's start-nybble into the unused end of the previous line's byte. The general method of calculating the minimum stride for any bit-per-pixel value under 8 is
(width * bpp + 7) / 8.
For each byte, the lowest nybble is the leftmost of the two pixels, which might seem counterintuitive when compared to the way the bytes are viewed in a hex editor.
The following tools are able to work with files in this format.
|Name||Platform||View images in this format?||Convert/export to another file/format?||Import from another file/format?||Access hidden data?||Edit metadata?||Notes|
|Westwood Font Editor||Windows||Yes||Yes||Yes||No||N/A||Automatically trims off the top of the characters on save, and saves the trimmed amount as Y-offset.|
|Engie File Converter||Windows||Yes||Yes||Yes||No||N/A||Automatically trims off the top of the characters on save, and saves the trimmed amount as Y-offset. This font type was added to Engie to allow creation of font sheets.|