bmfont2json

    0.1.9 • Public • Published

    Parses BMFont files (XML/TXT) to JSON objects, with a command-line tool for easy conversion.

    example

    var fs = require('fs');
    var bmfont2json = require('bmfont2json');
     
    //grab the Buffer or a string of our data
    var data = fs.readFileSync(__dirname + '/myfile.fnt');
     
    //the bitmap font data as an object
    var obj = bmfont2json(data);
     
    //we can stringify it if we want...
    var json = JSON.stingify( obj );

    The function parses a string (or Node Buffer) that is either XML data (with a root element), or TXT data (following Bitmap Font spec).

    The output looks something like the following JSON. It tries to stay true to the BMFont spec.

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

    Related modules:

    spec

    See here for a more complete JSON output.

    command-line tool

    Converts a single file. If no output is provided, it prints to stdout.

    Install
        npm install bmfont2json -g
    
    Usage:
        bmfont2json file [options]
    
    Options:
        -o, --ouput the output path
        -p, --pretty pretty print the JSON output
    

    Install

    npm i bmfont2json

    DownloadsWeekly Downloads

    464

    Version

    0.1.9

    License

    MIT

    Last publish

    Collaborators

    • mattdesl