Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
parse-bmfont-xml
Advanced tools
The parse-bmfont-xml npm package is used to parse BMFont XML files, which are commonly used in bitmap font rendering. This package helps in extracting font data such as character information, kerning, and other font metrics from XML files.
Parse BMFont XML
This feature allows you to parse a BMFont XML file and extract font data. The code sample reads an XML file and uses the parse function to extract and log the font information.
const parse = require('parse-bmfont-xml');
const fs = require('fs');
fs.readFile('path/to/font.xml', 'utf8', (err, data) => {
if (err) throw err;
parse(data, (err, font) => {
if (err) throw err;
console.log(font);
});
});
The parse-bmfont-ascii package is used to parse BMFont ASCII files. While parse-bmfont-xml focuses on XML format, parse-bmfont-ascii handles the ASCII format, providing similar functionality for different file types.
Fontkit is a comprehensive font library that supports various font formats including TrueType, OpenType, WOFF, and more. It offers more extensive functionality compared to parse-bmfont-xml, which is specialized for BMFont XML files.
opentype.js is a JavaScript parser and writer for OpenType and TrueType fonts. It provides a broader range of font manipulation capabilities compared to parse-bmfont-xml, which is specifically for parsing BMFont XML files.
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 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: [
"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).
MIT, see LICENSE.md for details.
FAQs
parses XML BMFont files into a JavaScript object
The npm package parse-bmfont-xml receives a total of 1,115,463 weekly downloads. As such, parse-bmfont-xml popularity was classified as popular.
We found that parse-bmfont-xml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.