NFTR (NITRO-System Font for Runtime) files store font data. It follows the NNS G2D Binary File Format. NFTR files use file signature 'NFTR'. These files replace BNFR Files.
FINF Block#
The FINF block stores basic information about the font file. There must be exactly one FINF block in the file. It takes on the following structure:
Offset | Type | Meaning |
---|---|---|
0x00 | u8 | Font type. Always 0 (bitmap). |
0x01 | u8 | Line height. This is the amount the vertical coordinate is incremented by on new lines. |
0x02 | u16 | Index of the invalid glyph. When no glyph is mapped to a code point, text rendering references this glyph index. |
0x04 | u8 | Default glyph leading pixels. |
0x05 | u8 | Default glyph width. |
0x06 | u8 | In NFTR 1.0 and above, this is the default glyph trailing pixels. In version 0.1, this is the font's character encoding. |
0x07 | u8 | In NFTR 1.0 and above, this is the font character encoding. This may be 0 (UTF-8), 1 (UTF-16), 2 (Shift-JIS), or 3 (ASCII/CP 1252). In all but Shift-JIS encoding, code points are represented in the font file as a 16-bit Unicode code point. In Shift-JIS encoding, when the code point is represented with a single byte, the stored code unit is this byte, zero-extended to 16 bits. For a 2-byte encoding, the high 8 bits are the first byte in the sequence, and the low 8 bits are the second byte. For NFTR version 0.1, this is padding space. |
0x08 | void * | Offset to the glyph data block. This offset is relative to the beginning of the file and points to the CGLP block (after its header). |
0x0C | void * | Offset to the first character width block. This offset is relative to the beginning of the file and points to a CWDH block (after its header). |
0x10 | void * | Offset to the first code map block. This offset is relative to the beginning of the file and points to a CMAP block (after its header). |
0x14 | u8 | (NFTR 1.2) Glyph cell height |
0x15 | u8 | (NFTR 1.2) Glyph cell width |
0x16 | u8 | (NFTR 1.2) Font glyph ascent (pixels from baseline to the top of the cell). |
0x17 | u8 | (NFTR 1.2) (padding) |
CGLP Block#
The CGLP block stores the glyph information for a font file. This block is required and there may be only one of them. It takes on the following structure:
Offset | Type | Meaning |
---|---|---|
0x00 | u8 | Glyph cell width in pixels |
0x01 | u8 | Glyph cell height in pixels |
0x02 | u16 | Cell data size in bytes (typically ceil(width * height * bpp / 8)). |
0x04 | u8 | Glyph ascent (pixels from baseline to the top of the cell) |
0x05 | u8 | Width of the widest glyph in the font file |
0x06 | u8 | Glyph data bit depth. May be any number from 1 to 8. |
0x07 | u8 | Flags (NFTR 1.1+). The least significant bit indicates that the font is horizontal (0) or vertical (1) oriented. Bits 1-2 indicate the direction of the font (0=0 degrees clockwise, 1=90 degrees clockwise, 2=180 degrees clockwise, 3=270 degrees clockwise). For NFTR versions below 1.1, this field is zero. |
Following the above structure is an array of glyph data. Each glyph size is determined by the glyph size defined above. Bits are arranged from most to least significant, with the bitmap data being read in bytes. Individual pixel values may span more than one byte.
CWDH Block#
The CWDH block stores the character width data for the font file. This block is optional, and there may be more than one. This block maps glyph indices to that glyph's width information. When looking up a glyph's width information, these blocks are traversed as a linked list. If the first CWDH block does not contain a width entry for the requested glyph, then the next block is searched, until one block has data for that glyph or all of the CWDH blocks are traversed. When no width data exists for a glyph, the default glyph width parameters defined in the FINF block are used. The CWDH block takes the following structure:
Offset | Type | Meaning |
---|---|---|
0x00 | u16 | First glyph index |
0x02 | u16 | Last glyph index (inclusive) |
0x04 | void * | Next CWDH block in the list (relative to the beginning of the file, and points after the block header). This may be NULL if this is the last width block in the sequence. |
Following the above structure is an array of width entries. These take the following structure:
Offset | Type | Meaning |
---|---|---|
0x00 | s8 | Glyph leading pixels. This is added to the glyph's horizontal position before it is drawn. |
0x01 | u8 | Glyph width. |
0x02 | s8 | (NFTR 1.0+) Total glyph width (leading+width+trailing). For NFTR version 0.1, this field does not exist and the structure is only 2 bytes large. |
CMAP Block#
The CMAP block defines the mappings of code points to glyph indices. The CMAP block is optional, and there may exist multiple. Like the CWDH block, these blocks are traversed as a linked list. Each block defines a mapping of code points to glyph indices over some range of code points. It takes one of three kinds: direct (0), table (1), and scan (2). A direct block maps a continuous range of code points to a corresponding continuous range of glyph indices. A table mapping block maps a continuous range of code points to individual glyph indices. A scan mapping block maps individual code points to individual glyph indices. The CMAP block takes the following structure:
Offset | Type | Meaning |
---|---|---|
0x00 | u16 | First code point |
0x02 | u16 | Last code point (inclusive) |
0x04 | u16 | Mapping type (0=direct, 1=table, 2=scan) |
0x06 | u16 | Padding (0) |
0x08 | void * | Pointer to the next mapping block in the sequence, or NULL if this is the last mapping block. |
For a direct mapping block, this structure is followed by a u16 indicating the index of the first glyph index it maps characters to. A mapping block defining the code points from 0x0020 to 0x007E and a starting glyph index of 0x0012 will map code point 0x0020 to 0x0012, 0x0021 to 0x0013, etc.
For a table mapping block, the CMAP structure is followed by an array of u16. The length is equal to the last code point minus the first code point, plus one. The first code point this block maps is subtracted from the searched code point and used as a subscript in this array. A value of 0xFFFF may be used to specify that no glyph is mapped to a code point. The search does not continue to the next block in the sequence, however.
For a scan mapping block, the CMAP structure is followed by a u16 indicating the number of entries, and an array of the following structure:
Offset | Type | Meaning |
---|---|---|
0x00 | u16 | Code point |
0x02 | u16 | Glyph index |
The array is arranged in ascending order of code point. This creates a mapping of each individual code point to individual glyph indices.