BRFNT (File Format)

From Custom Mario Kart
(Redirected from BRFNT)
Jump to: navigation, search

BRFNT (Binary Revolution FoNT) files contain bitmap fonts for use in Wii games. It is constructed by one or more images, character width tables (CWDH), and a character code maps (CMAP). BRFNT files have been found in Mario Kart Wii, Super Smash Bros. Brawl, Super Mario Galaxy 1 and 2, New Super Mario Bros. Wii, between others.

The file structure is composed by a header and sections. There always appears to be a FINF, TGLP sections along with one or more CWDH and CMAP sections. The file is written in big endian.

There are files similar to BRFNT (BRFNU) files embedded inside Mario Kart Wii's main.dol. These files have slightly different headers, and therefore will not work as a BRFNT on its own. They have a "RFNU" magic, but contain FINF, TGLP, CWDH and CMAP sections, although TGLP seems to be missing some information in its header.

RFNT Header

This is the general header of BRFNT files.

File header
Offset Size Description
0x00 4 File magic, always RFNT in ASCII.
0x04 2 Byte order mark (BOM): The value is always 0xFEFF. If value 0xFFFE is read, then the false endian is used. MKWii uses nearly always big endian (bytes 0xFE,0xFF).
0x06 1 Version major.
0x07 1 Version minor.
0x08 4 Length of the file in bytes.
0x0c 2 Offset to the beginning of the FINF header.
0x0e 2 Number of sections.
0x10 End of file header

FINF

The FINF section describes the font's settings and the way they have to be used.

FINF Section
Offset Size Description
0x00 4 Section magic, always FINF in ASCII.
0x04 4 Length of this section.
0x08 1 Font type:
  • 0x00 = FONT_TYPE_GLYPH: uses glyph data drawn into a BMP image file.
  • 0x01 = FONT_TYPE_NNGCTEXTURE: uses an NNGC (TPL-like) texture.
0x09 1 Leading (space between lines, unsure).
0x0a 2 Default glyph index, used if a character is not present in the font.
0x0c 1 Default left spacing.
0x0d 1 Default glyph width.
0x0e 1 Default character width.
0x0f 1 Font encoding:
  • 0x0 = UTF-8.
  • 0x1 = UTF-16.
  • 0x2 = ShiftJIS.
  • 0x3 = CP1252.
0x10 4 X = TGLP data offset.
0x14 4 Y = CWDH data offset (X + TGLP size).
0x18 4 CMAP data offset (Y + CWDH size).
0x1c 1 Font height.
0x1d 1 Font width.
0x1e 1 Ascent.
0x1f 1 Padding.
0x20 End of this section

TGLP Header

TGLP Header
Offset Size Description
0x00 4 Section magic, always TGLP in ASCII.
0x04 4 Length of this section.
0x08 1 Glyph cell width.
0x09 1 Glyph cell height.
0x0A 1 Baseline position.
0x0B 1 Maximum character width.
0x0C 4 Image size in bytes.
0x10 2 Image count.
0x12 2 Image format.
0x14 2 Glyph cells per row.
0x16 2 Glyph cells per column.
0x18 2 Image width.
0x1A 2 Image height.
0x1C 4 Position of texture data.
0x20 End of this header

TGLP Data

Bitmap is formed in a zig-zag way.

A single block of bitmap looks like this:

00 01 02 03 04 05 06 07

08 09 0A 0B 0C 0D 0E 0F

10 11 12 13 14 15 16 17

18 19 1A 1B 1C 1D 1E 1F

Multiple blocks:

B01 B02 B03 ... B08 (assume width=64)

B09 B0A B0B ...

...

Multiple images:

I01

I02

I03

...

CWDH Section

CWDH Section
Offset Size Description
0x00 4 Section magic, always CWDH in ASCII.
0x04 4 Length of this section.
0x08 2 First glyph index.
0x0A 2 Last glyph index.
0x0C 4 Offset to the next CWDH + 8, 0 if last.
0x10 Char Count * 3 Character width data.
0x10 + Char Count * 3 n Padding to the next 8 byte boundary.
0x10 + Char Count * 3 + Padding End of this section
Character width data
Offset Size Description
0x00 1 Left spacing.
0x01 1 Glyph width.
0x02 1 Character width.
0x03 End of character data

CMAP Section

CMAP Header
Offset Size Description
0x00 4 Section magic, always CMAP in ASCII.
0x04 4 Length of this section.
0x08 2 First character code, 0 if mapping method = 0x2.
0x0A 2 Last character code, 0xFFFF if mapping method = 0x2.
0x0C 2 Mapping method:
  • 0x0 = Direct.
  • 0x1 = Table.
  • 0x2 = Scan.
0x0E 2 Reserved.
0x10 4 Offset to the next CMAP + 8. 0 if last.
0x14 2 Offset of the first character.
0x16 End of the CMAP Header and start of the Mapping Information

Mapping Information

Each mapping method has its own structure for each character, described in the following tables:

Type 0x0 (Direct)

mapInfo Type 0x0
Offset Size Description
0x00 2 Character code.
0x02 2 Glyph index.

Type 0x1 (Table)

mapInfo Type 0x1
Offset Size Description
0x00 2 Glyph index starting from the first character code. 0xFFFF if not present.

Type 0x2 (Scan)

mapInfo Type 0x2
Offset Size Description
0x00 2 N = Number of entries.
0x02 + N * 4 2 Character code.
0x04 + N * 4 2 Glyph index.

Followed by the last index, there is a variable padding to the next 8 byte boundary.

Tools

The following tools can handle BRFNT files: