file_format.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <html>
  2. <head>
  3. <title>Bitmap Font Generator - Documentation</title>
  4. </head>
  5. <body>
  6. <h1>Bitmap Font Generator - Documentation</h1>
  7. <p><a href="../documentation.html">Back to main page</a></p>
  8. <h2>File format</h2>
  9. <li><a href="#tags">File tags</a>
  10. <li><a href="#bin">Binary file layout</a>
  11. <a name="tags"></a>
  12. <h2>File tags</h2>
  13. <h3>info</h3>
  14. <p>This tag holds information on how the font was generated.</p>
  15. <table>
  16. <tr><td width=100>face</td><td>This is the name of the true type font.</td></tr>
  17. <tr><td>size</td><td>The size of the true type font.</td></tr>
  18. <tr><td>bold</td><td>The font is bold.</td></tr>
  19. <tr><td>italic</td><td>The font is italic.</td></tr>
  20. <tr><td>charset</td><td>The name of the OEM charset used (when not unicode).</td></tr>
  21. <tr><td>unicode</td><td>Set to 1 if it is the unicode charset.</td></tr>
  22. <tr><td>stretchH</td><td>The font height stretch in percentage. 100% means no stretch.</td></tr>
  23. <tr><td>smooth</td><td>Set to 1 if smoothing was turned on.</td></tr>
  24. <tr><td>aa</td><td>The supersampling level used. 1 means no supersampling was used.</td></tr>
  25. <tr><td>padding</td><td>The padding for each character (up, right, down, left).</td></tr>
  26. <tr><td>spacing</td><td>The spacing for each character (horizontal, vertical).</td></tr>
  27. <tr><td>outline</td><td>The outline thickness for the characters.</td></tr>
  28. </table>
  29. <h3>common</h3>
  30. <p>This tag holds information common to all characters.</p>
  31. <table>
  32. <tr><td width=100>lineHeight</td><td>This is the distance in pixels between each line of text.</td></tr>
  33. <tr><td>base</td><td>The number of pixels from the absolute top of the line to the base of the characters.</td></tr>
  34. <tr><td>scaleW</td><td>The width of the texture, normally used to scale the x pos of the character image.</td></tr>
  35. <tr><td>scaleH</td><td>The height of the texture, normally used to scale the y pos of the character image.</td></tr>
  36. <tr><td>pages</td><td>The number of texture pages included in the font.</td></tr>
  37. <tr><td>packed</td><td>Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel.</td></tr>
  38. <tr><td>alphaChnl</td><td>Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.</td></tr>
  39. <tr><td>redChnl</td><td>Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.</td></tr>
  40. <tr><td>greenChnl</td><td>Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.</td></tr>
  41. <tr><td>blueChnl</td><td>Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.</td></tr>
  42. </table>
  43. <h3>page</h3>
  44. <p>This tag gives the name of a texture file. There is one for each page in the font.</p>
  45. <table>
  46. <tr><td width=100>id</td><td>The page id.</td></tr>
  47. <tr><td>file</td><td>The texture file name.</td></tr>
  48. </table>
  49. <h3>char</h3>
  50. <p>This tag describes on character in the font. There is one for each included character in the font.</p>
  51. <table>
  52. <tr><td width=100>id</td><td>The character id.</td></tr>
  53. <tr><td>x</td><td>The left position of the character image in the texture.</td></tr>
  54. <tr><td>y</td><td>The top position of the character image in the texture.</td></tr>
  55. <tr><td>width</td><td>The width of the character image in the texture.</td></tr>
  56. <tr><td>height</td><td>The height of the character image in the texture.</td></tr>
  57. <tr><td>xoffset</td><td>How much the current position should be offset when copying the image from the texture to
  58. the screen.</td></tr>
  59. <tr><td>yoffset</td><td>How much the current position should be offset when copying the image from the texture to
  60. the screen.</td></tr>
  61. <tr><td>xadvance</td><td>How much the current position should be advanced after drawing the character.</td></tr>
  62. <tr><td>page</td><td>The texture page where the character image is found.</td></tr>
  63. <tr><td>chnl</td><td>The texture channel where the character image is found
  64. (1 = blue, 2 = green, 4 = red, 8 = alpha, 15 = all channels).</td></tr>
  65. </table>
  66. <h3>kerning</h3>
  67. <p>The kerning information is used to adjust the distance between certain characters, e.g. some characters should
  68. be placed closer to each other than others.</p>
  69. <table>
  70. <tr><td width=100>first</td><td>The first character id.</td></tr>
  71. <tr><td>second</td><td>The second character id.</td></tr>
  72. <tr><td>amount</td><td>How much the x position should be adjusted when drawing the second character immediately
  73. following the first.</td></tr>
  74. </table>
  75. <a name="bin"></A>
  76. <h2>Binary file layout</h2>
  77. <p>This section describes the layout of the tags in the binary file format. To understand what each tag means refer
  78. to the <a href="#tags">file tags</A> section.</p>
  79. <p>The first three bytes are the file identifier and must always be 66, 77, 70, or "BMF". The fourth byte gives
  80. the format version, currently it must be 3.</p>
  81. <ul>
  82. <li>Version 1 (introduced with application version 1.8).
  83. <li>Version 2 (introduced with application version 1.9) added the outline field in the infoBlock and the encoded
  84. field in the commonBlock.
  85. <li>Version 3 (introduced with application version 1.10) removed the encoded field in the commonBlock, and
  86. added the alphaChnl, redChnl, greenChnl, blueChnl instead. The size of each block is now stored without
  87. accounting for the size field itself. The character id in the charsBlock and the kerningPairsBlock was increased
  88. to 4 bytes to support the full unicode range.
  89. </ul>
  90. <p>Following the first four bytes is a series of blocks with information. Each block starts with a one byte block
  91. type identifier, followed by a 4 byte integer that gives the size of the block, not including the block type identifier
  92. and the size value.</p>
  93. <h3>Block type 1: info</h3>
  94. <table>
  95. <tr><td width=100><b>field</b></td><td width=30><b>size</b></td><td width=40><b>type</b></td><td width=30><b>pos</b></td><td><b>comment</b></td></tr>
  96. <tr><td>fontSize</td> <td>2</td> <td>int</td> <td>0</td> <td></td></tr>
  97. <tr><td>bitField</td> <td>1</td> <td>bits</td> <td>2</td> <td>bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeigth, bits 5-7: reserved</td></tr>
  98. <tr><td>charSet</td> <td>1</td> <td>uint</td> <td>3</td> <td></td></tr>
  99. <tr><td>stretchH</td> <td>2</td> <td>uint</td> <td>4</td> <td></td></tr>
  100. <tr><td>aa</td> <td>1</td> <td>uint</td> <td>6</td> <td></td></tr>
  101. <tr><td>paddingUp</td> <td>1</td> <td>uint</td> <td>7</td> <td></td></tr>
  102. <tr><td>paddingRight</td><td>1</td> <td>uint</td> <td>8</td> <td></td></tr>
  103. <tr><td>paddingDown</td> <td>1</td> <td>uint</td> <td>9</td> <td></td></tr>
  104. <tr><td>paddingLeft</td> <td>1</td> <td>uint</td> <td>10</td><td></td></tr>
  105. <tr><td>spacingHoriz</td><td>1</td> <td>uint</td> <td>11</td><td></td></tr>
  106. <tr><td>spacingVert</td> <td>1</td> <td>uint</td> <td>12</td><td></td></tr>
  107. <tr><td>outline</td> <td>1</td> <td>uint</td> <td>13</td><td>added with version 2</td></tr>
  108. <tr><td>fontName</td> <td><i>n</i>+1</td><td>string</td> <td>14</td><td>null terminated string with length <i>n</i></td></tr>
  109. </table>
  110. <p>This structure gives the layout of the fields. Remember that there should be no
  111. padding between members. Allocate the size of the block using the blockSize, as
  112. following the block comes the font name, including the terminating null char.
  113. Most of the time this block can simply be ignored.</p>
  114. <h3>Block type 2: common</h3>
  115. <table>
  116. <tr><td width=100><b>field</b></td><td width=30><b>size</b></td><td width=40><b>type</b></td><td width=30><b>pos</b></td><td><b>comment</b></td></tr>
  117. <tr><td>lineHeight</td> <td>2</td> <td>uint</td> <td>0</td> <td></td></tr>
  118. <tr><td>base</td> <td>2</td> <td>uint</td> <td>2</td> <td></td></tr>
  119. <tr><td>scaleW</td> <td>2</td> <td>uint</td> <td>4</td> <td></td></tr>
  120. <tr><td>scaleH</td> <td>2</td> <td>uint</td> <td>6</td> <td></td></tr>
  121. <tr><td>pages</td> <td>2</td> <td>uint</td> <td>8</td> <td></td></tr>
  122. <tr><td>bitField</td> <td>1</td> <td>bits</td> <td>10</td> <td>bits 0-6: reserved, bit 7: packed</td></tr>
  123. <tr><td>alphaChnl</td> <td>1</td> <td>uint</td> <td>11</td> <td></td></tr>
  124. <tr><td>redChnl</td> <td>1</td> <td>uint</td> <td>12</td> <td></td></tr>
  125. <tr><td>greenChnl</td> <td>1</td> <td>uint</td> <td>13</td> <td></td></tr>
  126. <tr><td>blueChnl</td> <td>1</td> <td>uint</td> <td>14</td> <td></td></tr>
  127. </table>
  128. <h3>Block type 3: pages</h3>
  129. <table>
  130. <tr><td width=100><b>field</b></td><td width=70><b>size</b></td><td width=40><b>type</b></td><td width=30><b>pos</b></td><td><b>comment</b></td></tr>
  131. <tr><td>pageNames</td> <td><i>p</i>*(<i>n</i>+1)</td> <td>strings</td> <td>0</td> <td><i>p</i> null terminated strings, each with length <i>n</i></td></tr>
  132. </table>
  133. <p>This block gives the name of each texture file with the image data for the characters.
  134. The string pageNames holds the names separated and terminated by null chars. Each filename
  135. has the same length, so once you know the size of the first name, you can easily determine
  136. the position of each of the names. The id of each page is the zero-based index of the string name.</p>
  137. <h3>Block type 4: chars</h3>
  138. <table>
  139. <tr><td width=100><b>field</b></td><td width=30><b>size</b></td><td width=40><b>type</b></td><td width=70><b>pos</b></td><td><b>comment</b></td></tr>
  140. <tr><td>id</td> <td>4</td> <td>uint</td> <td>0+<i>c</i>*20</td> <td>These fields are repeated until all characters have been described</td></tr>
  141. <tr><td>x</td> <td>2</td> <td>uint</td> <td>4+<i>c</i>*20</td> <td></td></tr>
  142. <tr><td>y</td> <td>2</td> <td>uint</td> <td>6+<i>c</i>*20</td> <td></td></tr>
  143. <tr><td>width</td> <td>2</td> <td>uint</td> <td>8+<i>c</i>*20</td> <td></td></tr>
  144. <tr><td>height</td> <td>2</td> <td>uint</td> <td>10+<i>c</i>*20</td> <td></td></tr>
  145. <tr><td>xoffset</td> <td>2</td> <td>int</td> <td>12+<i>c</i>*20</td> <td></td></tr>
  146. <tr><td>yoffset</td> <td>2</td> <td>int</td> <td>14+<i>c</i>*20</td> <td></td></tr>
  147. <tr><td>xadvance</td> <td>2</td> <td>int</td> <td>16+<i>c</i>*20</td> <td></td></tr>
  148. <tr><td>page</td> <td>1</td> <td>uint</td> <td>18+<i>c</i>*20</td> <td></td></tr>
  149. <tr><td>chnl</td> <td>1</td> <td>uint</td> <td>19+<i>c</i>*20</td> <td></td></tr>
  150. </table>
  151. <p>The number of characters in the file can be computed by taking the size of the block
  152. and dividing with the size of the charInfo structure, i.e.: numChars = charsBlock.blockSize/20.</p>
  153. <h3>Block type 5: kerning pairs</h3>
  154. <table>
  155. <tr><td width=100><b>field</b></td><td width=30><b>size</b></td><td width=40><b>type</b></td><td width=60><b>pos</b></td><td><b>comment</b></td></tr>
  156. <tr><td>first</td> <td>4</td> <td>uint</td> <td>0+<i>c</i>*10</td> <td>These fields are repeated until all kerning pairs have been described</td></tr>
  157. <tr><td>second</td> <td>4</td> <td>uint</td> <td>4+<i>c</i>*10</td> <td></td></tr>
  158. <tr><td>amount</td> <td>2</td> <td>int</td> <td>8+<i>c</i>*6</td> <td></td></tr>
  159. </table>
  160. <p>This block is only in the file if there are any kerning pairs with amount differing from 0.</p>
  161. </body>
  162. </html>