71 Squared Blog

BMFont Binary Format

Posted by Mike Daley on Saturday, March 1st, 2014

For BMFont text format please read BMFont Text Format

File Header

The first three bytes of the header are the file identifier and are always set to 66, 77, 70 (BMF). The fourth byte is the version which is currently 3.

After the header are a number of blocks based on the tags described above.

Block type 1: info

Field Size Type Pos Comment
fontsize 2 int 0
bitField 1 bits 2 bit 0:smooth bit 1:unicode bit 2:italic bit 3:bold bit 4:fixedHeight bits 5-7:reservered
charSet 1 uint 3
stretchH 2 uint 4
aa 1 uint 6
paddingUp 2 uint 7
paddingRight 1 uint 8
paddingDown 1 uint 9
paddingLeft 1 uint 10
spacingHoriz 1 uint 11
spacingVert 1 uint 12
outline 1 uint 13
fontName n+1 string 14 null terminated string with length n

Block type 2: common

Field Size Type Pos Comment
lineHeight 2 uint 0
base 2 uint 2
scaleW 2 uint 4
scaleH 2 uint 6
pages 2 uint 8
bitField 1 bits 10 bits 0-6:reserved, bit 7:packed

Block type 3: pages

Field Size Type Pos Comment
pageNames p*(n+1) strings 0 p null terminated strings, each with length n

Block type 4: chars

Field Size Type Pos Comment
id 4 uint 0+c*20 these fields are repeated until all characters have been described
x 2 uint 4+c*20
y 2 uint 6+c*20
width 2 uint 8+c*20
height 2 uint 10+c*20
xoffset 2 uint 12+c*20
yoffset 2 uint 14+c*20
xadvance 2 uint 16+c*20
page 1 uint 18+c*20
chnl 1 uint 19+c*20

The number of characters in the file can be calculated by taking the size of the block and dividing it with the size of the charInfo structure, i.e. numChars = charsBlock.blockSize/20

Block type 5: kerning

Field Size Type Pos Comment
first 4 uint 0+c*10 these fields are repeated until all kerning pairs have been described
second 4 uint 4+c*10
amount 2 int 8+c*6

This block is only in the export file if kerning information exits for the selected font and the export kerning information option is selected when exporting the font data.