FONT (File Format): Difference between revisions

Jump to navigation Jump to search
m
>Aruki
>Aruki
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
The '''FONT format''' defines fonts that can be used to display text in-game.
The '''FONT format''' defines fonts that can be used to display text in-game.


{{todo|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.}}
{{research|2|There's some unknowns in the header. Also, some version 4/5 fonts have outlines on their textures - how do these work?}}
{{research|2|There's some unknowns in the header, and some of the values in the character definition structure should be double-checked.}}


__TOC__
__TOC__
Line 9: Line 8:


=== 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 40:
| u32
| u32
| 4
| 4
| '''Paragraph upper margin'''
| '''Vertical offset'''
|-
|-
| 0x14
| 0x14
Line 66: Line 67:
| '''Font name'''; zero-terminated string
| '''Font name'''; zero-terminated string
|-
|-
| 0x22+N
| -
| [[TXTR (Metroid Prime)|TXTR]]
| [[TXTR (Metroid Prime)|TXTR]]
| 4
| 4/8
| '''Texture ID'''
| '''Texture ID'''
|-
|-
| 0x26+N
| -
| u32
| u32
| 4
| 4
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|-
|-
| 0x2A+N
| -
| u32
| u32
| 4
| 4
| '''Glyph count'''
| '''Glyph count'''
|-
|-
| 0x2E+N
| -
| Glyph[]
| Glyph[]
| -
| -
Line 97: Line 98:
|-
|-
| 2
| 2
| ''Metroid Prime'' NTSC 0-00
| ''Metroid Prime'' NTSC
|-
|-
| 4
| 4
| ''Metroid Prime'' PAL/Player's Choice and ''Metroid Prime 2''
| ''Metroid Prime'' PAL and ''Metroid Prime 2''
|-
|-
| 5
| 5
Line 106: Line 107:
|}
|}


=== Glyph Entry (Version 2) ===
=== 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 NTSC) ====


{| class="wikitable"
{| class="wikitable"
Line 167: Line 178:
| u32
| u32
| 4
| 4
| '''Base offset'''
| '''Vertical offset'''
|-
|-
| 0x2A
| 0x2A
Line 178: Line 189:
|}
|}


=== Glyph Entry (Version 4) ===
==== Version 4 (Metroid Prime PAL) ====


{| class="wikitable"
{| class="wikitable"
Line 214: Line 225:
| u8
| u8
| 1
| 1
| '''RGBA layer index'''
| '''RGBA channel index'''
|-
|-
| 0x13
| 0x13
Line 252: Line 263:
=== Kerning Table ===
=== Kerning Table ===


This table is at the end of the file, and defines kerning pairs. It starts with a 32-bit count value and then loops the following structure:
This table is at the end of the file, and defines kerning pairs. The purpose of this table is to horizontally adjust the second character of the pair whenever this particular sequence of characters is encoutered. 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"
Line 274: Line 285:
| colspan=2 {{unknown|End of entry}}
| colspan=2 {{unknown|End of entry}}
|}
|}
== Textures ==
Starting with version 4, textures used by FONT files are encoded in a bit of an unorthodox manner. The textures are ostensibly C4, but it appears that the game probably replaces the palette colors with different ones at runtime, which means trying to decode them as-is will turn out junk. Fortunately, the correct colors are fairly intuitive to guess at, so the textures can be decoded as such: For each 4-bit palette index, each bit determines whether a given color channel should be set to 0 or 255. Bit 3 (the MSB) refers to the red channel, bit 2 refers to the green channel, bit 1 refers to the blue channel, and bit 0 (the LSB) refers to the alpha channel. This would correspond to the following RGB5A3 color palettes:
<pre>0 (0000) - 0x8000 (none)
1 (0001) - 0x7000 (alpha)
2 (0010) - 0xFC00 (blue)
3 (0011) - 0x7F00 (blue/alpha)
4 (0100) - 0x83E0 (green)
5 (0101) - 0x70F0 (green/alpha)
6 (0110) - 0xFFE0 (green/blue)
7 (0111) - 0x7FF0 (green/blue/alpha)
8 (1000) - 0x801F (red)
9 (1001) - 0x700F (red/alpha)
10 (1010) - 0xFC1F (red/blue)
11 (1011) - 0x7F0F (red/blue/alpha)
12 (1100) - 0x83FF (red/green)
13 (1101) - 0x70FF (red/green/alpha)
14 (1110) - 0xFFFF (red/green/blue)
15 (1111) - 0x7FFF (red/green/blue/alpha)</pre>
Note: ''Donkey Kong Country Returns'' features some font textures that use C8 instead of C4, but the palette indices still only range from 0 to 15, so the same method still applies.


[[Category:File Formats]]
[[Category:File Formats]]
Anonymous user

Navigation menu