GithubHelp home page GithubHelp logo

isabella232 / load-bmfont Goto Github PK

View Code? Open in Web Editor NEW

This project forked from experience-monks/load-bmfont

0.0 0.0 0.0 131 KB

loads a BMFont file in Node and the browser

License: MIT License

JavaScript 100.00%

load-bmfont's Introduction

load-bmfont

stable

Loads an AngelCode BMFont file in browser (with XHR) and node (with fs and phin), returning a JSON representation.

var load = require('load-bmfont')

load('fonts/Arial-32.fnt', function(err, font) {
  if (err)
    throw err
  
  //The BMFont spec in JSON form
  console.log(font.common.lineHeight)
  console.log(font.info)
  console.log(font.chars)
  console.log(font.kernings)
})

Currently supported BMFont formats:

  • ASCII (text)
  • JSON
  • XML
  • binary

See Also

See text-modules for related modules.

Usage

NPM

load(opt, cb)

Loads a BMFont file with the opt settings and fires the callback with (err, font) params once finished. If opt is a string, it is used as the URI. Otherwise the options can be:

  • uri or url the path (in Node) or URI
  • binary boolean, whether the data should be read as binary, default false
  • (in node) options for fs.readFile or phin
  • (in browser) options for xhr

To support binary files in the browser and Node, you should use binary: true. Otherwise the XHR request might come in the form of a UTF8 string, which will not work with binary files. This also sets up the XHR object to override mime type in older browsers.

load({ 
  uri: 'fonts/Arial.bin', 
  binary: true
}, function(err, font) {
  console.log(font)
})

License

MIT, see LICENSE.md for details.

load-bmfont's People

Contributors

mattdesl avatar hipstersmoothie avatar jakechampion avatar codelenny avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.