chore: add jimp dependency, icon padding script, and update configuration

This commit is contained in:
2026-05-31 14:04:37 +02:00
parent 30f81045ac
commit 7cd17307ba
1126 changed files with 166400 additions and 2 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Jam3
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
+61
View File
@@ -0,0 +1,61 @@
# load-bmfont
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Loads an [AngelCode BMFont](http://www.angelcode.com/products/bmfont/) file in browser (with XHR) and node (with fs and [phin](https://github.com/ethanent/phin)), returning a [JSON representation](json-spec.md).
```js
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](https://github.com/mattdesl/text-modules) for related modules.
## Usage
[![NPM](https://nodei.co/npm/load-bmfont.png)](https://www.npmjs.com/package/load-bmfont)
#### `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](https://www.npmjs.com/package/phin)
- (in browser) options for [xhr](https://github.com/Raynos/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.
```js
load(
{
uri: "fonts/Arial.bin",
binary: true,
},
function (err, font) {
console.log(font);
}
);
```
## License
MIT, see [LICENSE.md](http://github.com/Jam3/load-bmfont/blob/master/LICENSE.md) for details.
+97
View File
@@ -0,0 +1,97 @@
var xhr = require('xhr')
var noop = function(){}
var parseASCII = require('parse-bmfont-ascii')
var parseXML = require('parse-bmfont-xml')
var readBinary = require('parse-bmfont-binary')
var isBinaryFormat = require('./lib/is-binary')
var xtend = require('xtend')
var xml2 = (function hasXML2() {
return self.XMLHttpRequest && "withCredentials" in new XMLHttpRequest
})()
module.exports = function(opt, cb) {
cb = typeof cb === 'function' ? cb : noop
if (typeof opt === 'string')
opt = { uri: opt }
else if (!opt)
opt = {}
var expectBinary = opt.binary
if (expectBinary)
opt = getBinaryOpts(opt)
xhr(opt, function(err, res, body) {
if (err)
return cb(err)
if (!/^2/.test(res.statusCode))
return cb(new Error('http status code: '+res.statusCode))
if (!body)
return cb(new Error('no body result'))
var binary = false
//if the response type is an array buffer,
//we need to convert it into a regular Buffer object
if (isArrayBuffer(body)) {
var array = new Uint8Array(body)
body = Buffer.from(array, 'binary')
}
//now check the string/Buffer response
//and see if it has a binary BMF header
if (isBinaryFormat(body)) {
binary = true
//if we have a string, turn it into a Buffer
if (typeof body === 'string')
body = Buffer.from(body, 'binary')
}
//we are not parsing a binary format, just ASCII/XML/etc
if (!binary) {
//might still be a buffer if responseType is 'arraybuffer'
if (Buffer.isBuffer(body))
body = body.toString(opt.encoding)
body = body.trim()
}
var result
try {
var type = res.headers['content-type']
if (binary)
result = readBinary(body)
else if (/json/.test(type) || body.charAt(0) === '{')
result = JSON.parse(body)
else if (/xml/.test(type) || body.charAt(0) === '<')
result = parseXML(body)
else
result = parseASCII(body)
} catch (e) {
cb(new Error('error parsing font '+e.message))
cb = noop
}
cb(null, result)
})
}
function isArrayBuffer(arr) {
var str = Object.prototype.toString
return str.call(arr) === '[object ArrayBuffer]'
}
function getBinaryOpts(opt) {
//IE10+ and other modern browsers support array buffers
if (xml2)
return xtend(opt, { responseType: 'arraybuffer' })
if (typeof self.XMLHttpRequest === 'undefined')
throw new Error('your browser does not support XHR loading')
//IE9 and XML1 browsers could still use an override
var req = new self.XMLHttpRequest()
req.overrideMimeType('text/plain; charset=x-user-defined')
return xtend({
xhr: req
}, opt)
}
+57
View File
@@ -0,0 +1,57 @@
var fs = require('fs')
var url = require('url')
var path = require('path')
var request = require('phin')
var parseASCII = require('parse-bmfont-ascii')
var parseXML = require('parse-bmfont-xml')
var readBinary = require('parse-bmfont-binary')
var mime = require('mime')
var noop = function() {}
var isBinary = require('./lib/is-binary')
function parseFont(file, data, cb) {
var result, binary
if (isBinary(data)) {
if (typeof data === 'string') data = Buffer.from(data, 'binary')
binary = true
} else data = data.toString().trim()
try {
if (binary) result = readBinary(data)
else if (/json/.test(mime.lookup(file)) || data.charAt(0) === '{')
result = JSON.parse(data)
else if (/xml/.test(mime.lookup(file)) || data.charAt(0) === '<')
result = parseXML(data)
else result = parseASCII(data)
} catch (e) {
cb(e)
cb = noop
}
cb(null, result)
}
module.exports = function loadFont(opt, cb) {
cb = typeof cb === 'function' ? cb : noop
if (typeof opt === 'string') opt = { uri: opt, url: opt }
else if (!opt) opt = {}
var file = opt.uri || opt.url
function handleData(err, data) {
if (err) return cb(err)
parseFont(file, data.body || data, cb)
}
if (url.parse(file).host) {
request(opt).then(function (res) {
handleData(null, res)
}).catch(function (err) {
handleData(err)
})
} else {
fs.readFile(file, opt, handleData)
}
}
+84
View File
@@ -0,0 +1,84 @@
The spec for the JSON output is consistent with the rest of the [BMFont file spec](http://www.angelcode.com/products/bmfont/doc/file_format.html).
Here is what a typical output looks like, omitting the full list of glyphs/kernings for brevity.
```json
{
"pages": [
"sheet.png"
],
"chars": [
{
"id": 10,
"x": 281,
"y": 9,
"width": 0,
"height": 0,
"xoffset": 0,
"yoffset": 24,
"xadvance": 8,
"page": 0,
"chnl": 0
},
{
"id": 32,
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"xoffset": 0,
"yoffset": 0,
"xadvance": 9,
"page": 0,
"chnl": 0
},
...
],
"kernings": [
{
"first": 34,
"second": 65,
"amount": -2
},
{
"first": 34,
"second": 67,
"amount": 1
},
...
],
"info": {
"face": "Nexa Light",
"size": 32,
"bold": 0,
"italic": 0,
"charset": "",
"unicode": 1,
"stretchH": 100,
"smooth": 1,
"aa": 2,
"padding": [
0,
0,
0,
0
],
"spacing": [
0,
0
]
},
"common": {
"lineHeight": 32,
"base": 24,
"scaleW": 1024,
"scaleH": 2048,
"pages": 1,
"packed": 0,
"alphaChnl": 0,
"redChnl": 0,
"greenChnl": 0,
"blueChnl": 0
}
}
```
+8
View File
@@ -0,0 +1,8 @@
var equal = require('buffer-equal')
var HEADER = Buffer.from([66, 77, 70, 3])
module.exports = function(buf) {
if (typeof buf === 'string')
return buf.substring(0, 3) === 'BMF'
return buf.length > 4 && equal(buf.slice(0, 4), HEADER)
}
+55
View File
@@ -0,0 +1,55 @@
{
"name": "load-bmfont",
"version": "1.4.2",
"description": "loads a BMFont file in Node and the browser",
"main": "index.js",
"browser": "browser.js",
"license": "MIT",
"author": {
"name": "Matt DesLauriers",
"email": "dave.des@gmail.com",
"url": "https://github.com/mattdesl"
},
"dependencies": {
"buffer-equal": "0.0.1",
"mime": "^1.3.4",
"parse-bmfont-ascii": "^1.0.3",
"parse-bmfont-binary": "^1.0.5",
"parse-bmfont-xml": "^1.1.4",
"phin": "^3.7.1",
"xhr": "^2.0.1",
"xtend": "^4.0.0"
},
"devDependencies": {
"browserify": "^9.0.3",
"tap-spec": "^2.2.2",
"tape": "^3.5.0",
"testling": "^1.7.1"
},
"scripts": {
"test-node": "(node test.js; node test-server.js) | tap-spec",
"test-browser": "browserify test.js | testling | tap-spec",
"test": "npm run test-node && npm run test-browser"
},
"keywords": [
"bmfont",
"bitmap",
"font",
"angel",
"code",
"angelcode",
"parse",
"ascii",
"xml",
"text",
"json"
],
"repository": {
"type": "git",
"url": "git://github.com/Jam3/load-bmfont.git"
},
"homepage": "https://github.com/Jam3/load-bmfont",
"bugs": {
"url": "https://github.com/Jam3/load-bmfont/issues"
}
}
+26
View File
@@ -0,0 +1,26 @@
var test = require('tape')
var load = require('./')
var expectedArial = require('./fnt/Arial.json')
var fs = require('fs')
var http = require('http')
var arialBin = fs.readFileSync('fnt/Arial.bin')
test('should load from server URL', function (t) {
t.plan(1)
const server = http.createServer((req,res) => {
res.end(arialBin)
})
server.listen(8003, () => {
load({
url: 'http://localhost:8003',
binary: true
}, (err, res) => {
if (err) t.fail(err)
else t.deepEqual(res, expectedArial)
server.close()
})
})
})