FONT (File Format): Difference between revisions

no edit summary
>Aruki
imported>Antidote
No edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 6: Line 6:


== Format ==
== Format ==
Note: All measurements are in points.


=== 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).
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).
Note: All measurements are in points.


{| class="wikitable"
{| class="wikitable"
Line 42: Line 42:
| u32
| u32
| 4
| 4
| '''Vertical offset'''
| '''Vertical offset''' ''(note: not present in version 1)''
|-
|-
| 0x14
| 0x14
Line 50: Line 50:
|-
|-
| 0x18
| 0x18
| bool
| 1
| {{unknown|'''Unknown'''}}
|-
| 0x19
| bool
| 1
| {{unknown|'''Unknown'''}}
|-
| 0x1A
| u32
| u32
| 4
| 4
| {{unknown|'''Unknown'''}} ''(note: not present in version 1)''
| {{unknown|'''Unknown'''}}  
|-
| 0x1C
| u16
| 2
| {{unknown|'''Unknown'''}}
|-
|-
| 0x1E
| 0x1E
Line 77: Line 82:
| u32
| u32
| 4
| 4
| {{unknown|'''Unknown'''}}
| '''Texture format''' (see [[#Textures|Textures]])
|-
|-
| -
| -
Line 112: Line 117:
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.
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.
This section of the file changes somewhat from version 2 to 4. Starting in version 4, font textures are able to be split up into multiple layers, which allows multiple glyphs to be encoded in the same space on the texture. A "layer index" value was introduced to track which layer 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) ====
==== Version 2 (Metroid Prime NTSC) ====
Line 180: Line 185:
| u32
| u32
| 4
| 4
| '''Kerning index'''
| '''Kerning start index'''
|-
|-
| 0x2E
| 0x2E
Line 186: Line 191:
|}
|}


==== Version 4 (Metroid Prime PAL) ====
==== Version 4 (Metroid Prime PAL/Trilogy) ====


{| class="wikitable"
{| class="wikitable"
Line 222: Line 227:
| u8
| u8
| 1
| 1
| '''RGBA channel index'''
| '''Layer index'''
|-
|-
| 0x13
| 0x13
Line 250: Line 255:
|-
|-
| 0x18
| 0x18
| u8
| 1
| '''Vertical offset'''
|-
| 0x19
| u16
| u16
| 2
| 2
| '''Kerning index'''
| '''Kerning start index'''
|-
|-
| 0x1A
| 0x1B
| colspan=3 {{unknown|End of glyph definition}}
| colspan=3 {{unknown|End of glyph definition}}
|}
|}
Line 285: Line 295:
== Textures ==
== 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:
{{research|minor|Someone should look at the code to make sure the info in this section is accurate.}}
 
Textures used by FONT files are encoded in a bit of an unorthodox manner. The font format allows for multiple glyphs to be encoded in the same spot on the texture by splitting up the texture into multiple layers. The way this is handled on the textures is by encoding the textures with palettes (as C4), but modifying the palette indices at runtime and loading each layer one at a time as a separate texture. Each bit of the palette index corresponds to a layer, so up to four layers per font are supported. The MSB refers to layer 0, while the LSB refers to layer 3. In DKCR, font textures are encoded as C8, so theoretically the game could use up to eight layers per font; however, it still never actually uses more than four.
 
The texture format is determined by a value in the header. These are the possible settings:
 
{| class="wikitable"
! Value
! Description
! V1
! V2
! V4
! V5
|-
| 0
| One glyph layer, no outlines; fill on layer 0
| {{check}}
| {{check}}
| {{check}}
| {{check}}
|-
| 1
| One glyph layer, with outlines; fill on layer 0, outline on layer 1
| {{check}}
| {{check}}
| {{check}}
| {{check}}
|-
| 2
| Four glyph layers, no outlines
| {{nocheck}}
| {{nocheck}}
| {{check}}
| {{check}}
|-
| 3
| Two glyph layers, with outlines; fill on layers 0/2, outlines on layers 1/3
| {{nocheck}}
| {{nocheck}}
| {{check}}
| {{check}}
|-
| 4
| Two glyph layers, no outlines; copies on layers 0/1, and layers 2/3
| {{nocheck}}
| {{nocheck}}
| {{check}}
| {{check}}
|-
| 8
| Two glyph layers, with outlines; fill on layers 2/3, outlines on layers 0/1
| {{nocheck}}
| {{nocheck}}
| {{nocheck}}
| {{check}}
|}


<pre>0 (0000) - 0x8000 (none)
To dump out every layer into a single texture by encoding each layer on a separate RGBA channel, the following palette colors could be substituted into the texture:
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.
{| class="wikitable"
! Index
! Binary
! Color
! Description
|-
| 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
|}


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