Skip to content
Rebecca G. Bettencourt edited this page Sep 4, 2020 · 2 revisions

Bits'N'Picas Bitmap Font Format

The Bits'N'Picas bitmap font format, used with the file extension kbits, is a chunk-based binary file format with implied chunk lengths based on version numbers. It starts with a header and ends with a single tag. All multibyte values are big endian.

Bits'N'Picas Bitmap Font Format
int32 magic number 0x4B426E50 (KBnP) for start of file
int32 magic number 0x62697473 (bits) for bitmap font header
int32 version number; only version 1 is currently defined
int32 em ascent (corresponds to TrueType hhea ascent)
int32 em descent (corresponds to TrueType hhea descent)
int32 line ascent (corresponds to TrueType OS/2 typoAscent)
int32 line descent (corresponds to TrueType OS/2 typoDescent)
int32 line gap (corresponds to TrueType OS/2 typoLineGap)
int32 x height
... chunks
int32 magic number 0x66696E2E (fin.) for end of file

There are two types of chunks currently defined: name and character chunks.

Name Chunks

Name chunks associate strings with the font. These strings may be copyright notices, font names, family names, style names, or so on. They correspond to TrueType name table entries.

Name Chunk Format
int32 magic number 0x6E616D65 (name) for name chunk
int32 version number; only version 1 is currently defined
int32 name type
int16 name length in bytes
byte[] UTF-8 encoded string

The following values are supported for the name type field, inherited from the TrueType name table specification:

Name Type Values
0 copyright notice
1 font family name
2 font style name
3 unique id
4 font family and style name
5 version
6 PostScript font name
7 trademark notice
8 manufacturer name
9 designer name
10 description
11 vendor URL
12 designer URL
13 license description
14 license URL
16 Windows font family name
17 Windows font style name
18 Mac OS font family and style name
19 sample text
20 PostScript CID
21 WWS naming system font family name
22 WWS naming system font style name

Character Chunks

Character chunks define the glyphs in the font. The glyph data is organized as an array of scan lines.

Character Chunk Format
int32 magic number 0x63686172 (char) for character chunk
int32 version number; only version 1 is currently defined
int32 Unicode code point for this character
int32 advance width
int32 glyph X offset / left side bearing
int32 glyph Y offset / number of scan lines above baseline
int32 glyph height / total number of scan lines
... scan lines

Each scan line is organized as an array of single-byte grayscale values. Each scan line has its own length. (Usually all scan line lengths are equal, but this is not guaranteed.)

Character Chunk Scan Line
int32 glyph width / number of columns in scan line
byte[] grayscale values for each column of scan line
Clone this wiki locally