Skip to content
parses XML BMFont files into a JavaScript object
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Parses XML BMFont files.

Takes a string or Buffer:

var fs = require('fs')
var parse = require('parse-bmfont-xml')

fs.readFileSync(__dirname+'/Arial.fnt', function(err, data) {
  var result = parse(data)
  console.log(   // "Arial"
  console.log(result.pages)       // [ 'sheet0.png' ]
  console.log(result.chars)       // [ ... char data ... ]
  console.log(result.kernings)    // [ ... kernings data ... ]

Also works in the browser, for example using XHR:

var parse = require('parse-bmfont-xml')
var xhr = require('xhr')

xhr({ uri: 'fonts/NexaLight32.xml' }, function(err, res, body) {
  if (err)
    throw err
  var result = parse(body)

The spec for the returned JSON object is here. The input XML should match the spec with a <font> root element, see [test/Nexa Light-32.fnt](test/Nexa Light-32.fnt) for an example.

See Also

See text-modules for related modules.



result = parse(data)

Parses data, a string or Buffer that represents XML data of an AngelCode BMFont file. The returned result object looks like this:

     pages: [
     chars: [
         { chnl, height, id, page, width, x, y, xoffset, yoffset, xadvance },
     info: { ... },
     common: { ... },
     kernings: [
         { first, second, amount }

If the data is malformed, an error will be thrown.

The browser implementation relies on xml-parse-from-string, which may not work in environments without valid DOM APIs (like CocoonJS).


MIT, see for details.

You can’t perform that action at this time.