first commit
This commit is contained in:
21
build/node_modules/load-bmfont/LICENSE.md
generated
vendored
Normal file
21
build/node_modules/load-bmfont/LICENSE.md
generated
vendored
Normal 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.
|
||||
|
||||
59
build/node_modules/load-bmfont/README.md
generated
vendored
Normal file
59
build/node_modules/load-bmfont/README.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# load-bmfont
|
||||
|
||||
[](http://github.com/badges/stability-badges)
|
||||
|
||||
Loads an [AngelCode BMFont](http://www.angelcode.com/products/bmfont/) file from XHR (in browser) and fs (in Node), 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
|
||||
|
||||
[](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 (in the browser)
|
||||
- `binary` boolean, whether the data should be read as binary, default false
|
||||
- (in node) options for `fs.readFile`
|
||||
- (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
build/node_modules/load-bmfont/browser.js
generated
vendored
Normal file
97
build/node_modules/load-bmfont/browser.js
generated
vendored
Normal 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 = new Buffer(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 = new Buffer(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)
|
||||
}
|
||||
46
build/node_modules/load-bmfont/index.js
generated
vendored
Normal file
46
build/node_modules/load-bmfont/index.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
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')
|
||||
|
||||
module.exports = function loadFont(opt, cb) {
|
||||
cb = typeof cb === 'function' ? cb : noop
|
||||
if (typeof opt === 'string')
|
||||
opt = { uri: opt }
|
||||
else if (!opt)
|
||||
opt = {}
|
||||
|
||||
var file = opt.uri || opt.url
|
||||
fs.readFile(file, opt, function(err, data) {
|
||||
if (err) return cb(err)
|
||||
|
||||
var result, binary
|
||||
if (isBinary(data)) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(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)
|
||||
})
|
||||
}
|
||||
84
build/node_modules/load-bmfont/json-spec.md
generated
vendored
Normal file
84
build/node_modules/load-bmfont/json-spec.md
generated
vendored
Normal 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
build/node_modules/load-bmfont/lib/is-binary.js
generated
vendored
Normal file
8
build/node_modules/load-bmfont/lib/is-binary.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
var equal = require('buffer-equal')
|
||||
var HEADER = new Buffer([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)
|
||||
}
|
||||
82
build/node_modules/load-bmfont/package.json
generated
vendored
Normal file
82
build/node_modules/load-bmfont/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"load-bmfont@1.3.0",
|
||||
"/Users/asciidisco/Desktop/asciidisco.com/build"
|
||||
]
|
||||
],
|
||||
"_from": "load-bmfont@1.3.0",
|
||||
"_id": "load-bmfont@1.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-u358cQ3mvK/LE8s7jIHgwBMey8k=",
|
||||
"_location": "/load-bmfont",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "load-bmfont@1.3.0",
|
||||
"name": "load-bmfont",
|
||||
"escapedName": "load-bmfont",
|
||||
"rawSpec": "1.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/jimp"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/load-bmfont/-/load-bmfont-1.3.0.tgz",
|
||||
"_spec": "1.3.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
|
||||
"author": {
|
||||
"name": "Matt DesLauriers",
|
||||
"email": "dave.des@gmail.com",
|
||||
"url": "https://github.com/mattdesl"
|
||||
},
|
||||
"browser": "browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Jam3/load-bmfont/issues"
|
||||
},
|
||||
"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.0",
|
||||
"xhr": "^2.0.1",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"description": "loads a BMFont file in Node and the browser",
|
||||
"devDependencies": {
|
||||
"browserify": "^9.0.3",
|
||||
"tap-spec": "^2.2.2",
|
||||
"tape": "^3.5.0",
|
||||
"testling": "^1.7.1"
|
||||
},
|
||||
"homepage": "https://github.com/Jam3/load-bmfont",
|
||||
"keywords": [
|
||||
"bmfont",
|
||||
"bitmap",
|
||||
"font",
|
||||
"angel",
|
||||
"code",
|
||||
"angelcode",
|
||||
"parse",
|
||||
"ascii",
|
||||
"xml",
|
||||
"text",
|
||||
"json"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "load-bmfont",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Jam3/load-bmfont.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run test-node && npm run test-browser",
|
||||
"test-browser": "browserify test.js | testling | tap-spec",
|
||||
"test-node": "node test.js | tap-spec"
|
||||
},
|
||||
"version": "1.3.0"
|
||||
}
|
||||
Reference in New Issue
Block a user