parse-bmfont-xml

WebJar for parse-bmfont-xml

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

parse-bmfont-xml
Last Version

Last Version

1.1.4
Release Date

Release Date

Type

Type

jar
Description

Description

parse-bmfont-xml
WebJar for parse-bmfont-xml
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mattdesl/parse-bmfont-xml

Download parse-bmfont-xml

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/parse-bmfont-xml/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>parse-bmfont-xml</artifactId>
    <version>1.1.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/parse-bmfont-xml/
implementation 'org.webjars.npm:parse-bmfont-xml:1.1.4'
// https://jarcasting.com/artifacts/org.webjars.npm/parse-bmfont-xml/
implementation ("org.webjars.npm:parse-bmfont-xml:1.1.4")
'org.webjars.npm:parse-bmfont-xml:jar:1.1.4'
<dependency org="org.webjars.npm" name="parse-bmfont-xml" rev="1.1.4">
  <artifact name="parse-bmfont-xml" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='parse-bmfont-xml', version='1.1.4')
)
libraryDependencies += "org.webjars.npm" % "parse-bmfont-xml" % "1.1.4"
[org.webjars.npm/parse-bmfont-xml "1.1.4"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : xml-parse-from-string jar [1.0.0,2)
org.webjars.npm : xml2js jar [0.4.5,0.5)

Project Modules

There are no modules declared in this project.

parse-bmfont-xml

stable

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(result.info.face)   // "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)
  console.log(result.info.face)
})

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.

Usage

NPM

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: [
         "sheet_0.png", 
         "sheet_1.png"
     ],
     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).

License

MIT, see LICENSE.md for details.

Versions

Version
1.1.4
1.1.3
1.1.1
1.1.0