FONT (File Format): Difference between revisions
>Aruki (→Header) |
>Aruki (→Format) |
||
Line 9: | Line 9: | ||
=== Header === | === Header === | ||
The header has a couple minor differences depending on the version. Version 1 (MP1 Kiosk Demo) is missing the value at 0x18, and starting in Version 5 (MP3/DKCR), the texture ID is 64 bits. Those are the only changes, though (and for that matter, those are the only differences in version 1/5). | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 39: | Line 41: | ||
| u32 | | u32 | ||
| 4 | | 4 | ||
| ''' | | '''Vertical offset''' | ||
|- | |- | ||
| 0x14 | | 0x14 | ||
Line 66: | Line 68: | ||
| '''Font name'''; zero-terminated string | | '''Font name'''; zero-terminated string | ||
|- | |- | ||
| | | - | ||
| [[TXTR (Metroid Prime)|TXTR]] | | [[TXTR (Metroid Prime)|TXTR]] | ||
| 4 | | 4/8 | ||
| '''Texture ID''' | | '''Texture ID''' | ||
|- | |- | ||
| | | - | ||
| u32 | | u32 | ||
| 4 | | 4 | ||
| {{unknown|'''Unknown'''}} | | {{unknown|'''Unknown'''}} | ||
|- | |- | ||
| | | - | ||
| u32 | | u32 | ||
| 4 | | 4 | ||
| '''Glyph count''' | | '''Glyph count''' | ||
|- | |- | ||
| | | - | ||
| Glyph[] | | Glyph[] | ||
| - | | - | ||
Line 106: | Line 108: | ||
|} | |} | ||
=== | === Glyphs === | ||
This section of the file details each glyph making up the font. One glyph corresponds to one character. To map the character with the part of the font texture that contains that character, each glyph contains a set of texture coordinates. Since the UV map is always rectangular, the file only stores the min/max X/Y coordinates; they should be mixed and matched to get the absolute values. | |||
In addition, glyphs contain a vertical offset. This offset is necessary because the textures are usually so tightly packed that there's no extra space for vertical spacing. After applying the offset, the vertical offset from the FONT header is applied. This aligns the glyphs at their intended position. | |||
The kerning index value is the index of the first kerning table entry for the given character. Since the table is sorted in alphabetical order, this can be used to speed up lookup time. | |||
This section of the file changes somewhat from version 2 to 4. Starting in version 4, glyphs are able to be encoded to only one particular RGBA channel, which allows multiple glyphs to be encoded in the same space on the texture. A "channel index" value was introduced to track which channel the glyph is on. Additionally, a lot of 32-bit values were reduced to 8- or 16-bit. Aside from that, though, the actual layout is still the same, with the same values in the same places. | |||
==== Version 2 (Metroid Prime 0-00) ==== | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 167: | Line 179: | ||
| u32 | | u32 | ||
| 4 | | 4 | ||
| ''' | | '''Vertical offset''' | ||
|- | |- | ||
| 0x2A | | 0x2A | ||
Line 178: | Line 190: | ||
|} | |} | ||
=== | ==== Version 4 (Metroid Prime PAL) ==== | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 214: | Line 226: | ||
| u8 | | u8 | ||
| 1 | | 1 | ||
| '''RGBA | | '''RGBA channel index''' | ||
|- | |- | ||
| 0x13 | | 0x13 | ||
Line 252: | Line 264: | ||
=== Kerning Table === | === Kerning Table === | ||
This table is at the end of the file, and defines kerning pairs. | This table is at the end of the file, and defines kerning pairs. The table is case-sensitively sorted in alphabetical order, which allows for fast lookup times using the glyph kerning indices. After a 32-bit count value, each pair follows this simple structure: | ||
{| class="wikitable" | {| class="wikitable" |
Revision as of 08:10, 27 March 2015
The FONT format defines fonts that can be used to display text in-game.
To do: Notate differences between different versions of the format. Only Metroid Prime's FONT version is documented at the moment. Character definition structure should be expanded on; there should be a section explaining what each value does, and it should be made more clear which UV coordinate corresponds to which vertex. |
This file format needs more research There's some unknowns in the header, and some of the values in the character definition structure should be double-checked. |
Format
Header
The header has a couple minor differences depending on the version. Version 1 (MP1 Kiosk Demo) is missing the value at 0x18, and starting in Version 5 (MP3/DKCR), the texture ID is 64 bits. Those are the only changes, though (and for that matter, those are the only differences in version 1/5).
Offset | Type | Size | Description |
---|---|---|---|
0x0 | char[4] | 4 | "FONT" magic fourCC |
0x4 | u32 | 4 | Version; see below |
0x8 | u32 | 4 | Unknown |
0xC | s32 | 4 | Line height |
0x10 | u32 | 4 | Vertical offset |
0x14 | s32 | 4 | Line margin |
0x18 | u32 | 4 | Unknown (note: not present in version 1) |
0x1C | u16 | 2 | Unknown |
0x1E | u32 | 4 | Font size (in points) |
0x22 | string | N | Font name; zero-terminated string |
- | TXTR | 4/8 | Texture ID |
- | u32 | 4 | Unknown |
- | u32 | 4 | Glyph count |
- | Glyph[] | - | Glyph table (Version 2, Version 4) |
Version
Version | Game |
---|---|
1 | Metroid Prime Kiosk Demo |
2 | Metroid Prime NTSC 0-00 |
4 | Metroid Prime PAL/Player's Choice and Metroid Prime 2 |
5 | Metroid Prime 3, DKCR |
Glyphs
This section of the file details each glyph making up the font. One glyph corresponds to one character. To map the character with the part of the font texture that contains that character, each glyph contains a set of texture coordinates. Since the UV map is always rectangular, the file only stores the min/max X/Y coordinates; they should be mixed and matched to get the absolute values.
In addition, glyphs contain a vertical offset. This offset is necessary because the textures are usually so tightly packed that there's no extra space for vertical spacing. After applying the offset, the vertical offset from the FONT header is applied. This aligns the glyphs at their intended position.
The kerning index value is the index of the first kerning table entry for the given character. Since the table is sorted in alphabetical order, this can be used to speed up lookup time.
This section of the file changes somewhat from version 2 to 4. Starting in version 4, glyphs are able to be encoded to only one particular RGBA channel, which allows multiple glyphs to be encoded in the same space on the texture. A "channel index" value was introduced to track which channel the glyph is on. Additionally, a lot of 32-bit values were reduced to 8- or 16-bit. Aside from that, though, the actual layout is still the same, with the same values in the same places.
Version 2 (Metroid Prime 0-00)
Offset | Type | Size | Description |
---|---|---|---|
0x0 | u16 | 2 | UTF-16 character |
0x2 | float | 4 | Left UV coordinate |
0x6 | float | 4 | Top UV coordinate |
0xA | float | 4 | Right UV coordinate |
0xE | float | 4 | Bottom UV coordinate |
0x12 | u32 | 4 | Left padding |
0x16 | u32 | 4 | Print head advance |
0x1A | u32 | 4 | Right padding |
0x1E | u32 | 4 | Width |
0x22 | u32 | 4 | Height |
0x26 | u32 | 4 | Vertical offset |
0x2A | u32 | 4 | Kerning index |
0x2E | End of glyph definition |
Version 4 (Metroid Prime PAL)
Offset | Type | Size | Description |
---|---|---|---|
0x0 | u16 | 2 | UTF-16 character |
0x2 | float | 4 | Left UV coordinate |
0x6 | float | 4 | Top UV coordinate |
0xA | float | 4 | Right UV coordinate |
0xE | float | 4 | Bottom UV coordinate |
0x12 | u8 | 1 | RGBA channel index |
0x13 | u8 | 1 | Glyph left padding |
0x14 | u8 | 1 | Print head advance |
0x15 | u8 | 1 | Glyph right padding |
0x16 | u8 | 1 | Glyph width |
0x17 | u8 | 1 | Glyph height |
0x18 | u16 | 2 | Kerning index |
0x1A | End of glyph definition |
Kerning Table
This table is at the end of the file, and defines kerning pairs. The table is case-sensitively sorted in alphabetical order, which allows for fast lookup times using the glyph kerning indices. After a 32-bit count value, each pair follows this simple structure:
Offset | Size | Description |
---|---|---|
0x0 | 2 | Character 1 |
0x2 | 2 | Character 2 |
0x4 | 4 | Kerning adjust |
0x8 | End of entry |