BMFont ASCII File Parser

1.0.6 · abandoned · verified Sun Apr 19

The `parse-bmfont-ascii` library is designed to parse ASCII-formatted BMFont (Bitmap Font) files into a structured JavaScript object. It specifically handles the human-readable text-based `.fnt` files generated by tools like AngelCode BMFont. This package, currently at version 1.0.6, was last published 11 years ago, indicating it is no longer actively maintained. It accepts either a string or a Node.js `Buffer` containing the BMFont data and returns a JavaScript object detailing font metadata (`info`, `common`), individual character properties (`chars`), kerning pairs (`kernings`), and referenced page textures (`pages`). Its primary function is to provide a lightweight, dedicated parser for this specific text-based bitmap font format, distinct from XML or binary BMFont variants. Given its age, it relies on CommonJS module patterns and does not inherently support ESM or TypeScript type definitions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `parse-bmfont-ascii` to parse a string containing BMFont ASCII data, then log key properties of the resulting JavaScript object.

const parse = require('parse-bmfont-ascii');

// Example BMFont ASCII data (simplified Arial.fnt structure)
const bmfontData = `info face="Arial" size=32 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=0,0 outline=0
common lineHeight=32 base=26 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0
page id=0 file="sheet0.png"
chars count=3
char id=65 x=1 y=1 width=20 height=20 xoffset=0 yoffset=4 xadvance=20 page=0 chnl=15
char id=66 x=22 y=1 width=20 height=20 xoffset=0 yoffset=4 xadvance=20 page=0 chnl=15
char id=67 x=43 y=1 width=20 height=20 xoffset=0 yoffset=4 xadvance=20 page=0 chnl=15
kernings count=1
kerning first=65 second=66 amount=-2`;

try {
  const result = parse(bmfontData);

  console.log('Font Face:', result.info.face); // Expected: Arial
  console.log('Pages:', result.pages);         // Expected: [ 'sheet0.png' ]
  console.log('Number of chars:', result.chars.length); // Expected: 3
  console.log('First char ID:', result.chars[0].id);   // Expected: 65 (A)
  console.log('First kerning amount:', result.kernings[0].amount); // Expected: -2
} catch (error) {
  console.error('Failed to parse BMFont data:', error);
}

view raw JSON →