This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

56
node_modules/parse-bmfont-ascii/README.md generated vendored Normal file
View File

@ -0,0 +1,56 @@
# parse-bmfont-ascii
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Parses ASCII (text) [BMFont files](http://www.angelcode.com/products/bmfont/).
Takes a string or Buffer:
```js
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 ... ]
})
```
The spec for the returned JSON object is [here](https://github.com/mattdesl/bmfont2json/wiki/JsonSpec). The input data should match the spec, see [test/Nexa Light-32.fnt](test/Nexa Light-32.fnt) for an example.
## See Also
See [text-modules](https://github.com/mattdesl/text-modules) for related modules.
## Usage
[![NPM](https://nodei.co/npm/parse-bmfont-ascii.png)](https://www.npmjs.com/package/parse-bmfont-ascii)
#### `result = parse(data)`
Parses `data`, a string or Buffer that represents ASCII (text) data of an AngelCode BMFont file. The returned `result` object looks like this:
```js
{
pages: [
"sheet_0.png",
"sheet_1.png"
],
chars: [
{ chnl, height, id, page, width, x, y, xoffset, yoffset, xadvance },
...
],
info: { ... },
common: { ... },
kernings: [
{ first, second, amount }
]
}
```
## License
MIT, see [LICENSE.md](http://github.com/mattdesl/parse-bmfont-ascii/blob/master/LICENSE.md) for details.

108
node_modules/parse-bmfont-ascii/index.js generated vendored Normal file
View File

@ -0,0 +1,108 @@
module.exports = function parseBMFontAscii(data) {
if (!data)
throw new Error('no data provided')
data = data.toString().trim()
var output = {
pages: [],
chars: [],
kernings: []
}
var lines = data.split(/\r\n?|\n/g)
if (lines.length === 0)
throw new Error('no data in BMFont file')
for (var i = 0; i < lines.length; i++) {
var lineData = splitLine(lines[i], i)
if (!lineData) //skip empty lines
continue
if (lineData.key === 'page') {
if (typeof lineData.data.id !== 'number')
throw new Error('malformed file at line ' + i + ' -- needs page id=N')
if (typeof lineData.data.file !== 'string')
throw new Error('malformed file at line ' + i + ' -- needs page file="path"')
output.pages[lineData.data.id] = lineData.data.file
} else if (lineData.key === 'chars' || lineData.key === 'kernings') {
//... do nothing for these two ...
} else if (lineData.key === 'char') {
output.chars.push(lineData.data)
} else if (lineData.key === 'kerning') {
output.kernings.push(lineData.data)
} else {
output[lineData.key] = lineData.data
}
}
return output
}
function splitLine(line, idx) {
line = line.replace(/\t+/g, ' ').trim()
if (!line)
return null
var space = line.indexOf(' ')
if (space === -1)
throw new Error("no named row at line " + idx)
var key = line.substring(0, space)
line = line.substring(space + 1)
//clear "letter" field as it is non-standard and
//requires additional complexity to parse " / = symbols
line = line.replace(/letter=[\'\"]\S+[\'\"]/gi, '')
line = line.split("=")
line = line.map(function(str) {
return str.trim().match((/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g))
})
var data = []
for (var i = 0; i < line.length; i++) {
var dt = line[i]
if (i === 0) {
data.push({
key: dt[0],
data: ""
})
} else if (i === line.length - 1) {
data[data.length - 1].data = parseData(dt[0])
} else {
data[data.length - 1].data = parseData(dt[0])
data.push({
key: dt[1],
data: ""
})
}
}
var out = {
key: key,
data: {}
}
data.forEach(function(v) {
out.data[v.key] = v.data;
})
return out
}
function parseData(data) {
if (!data || data.length === 0)
return ""
if (data.indexOf('"') === 0 || data.indexOf("'") === 0)
return data.substring(1, data.length - 1)
if (data.indexOf(',') !== -1)
return parseIntList(data)
return parseInt(data, 10)
}
function parseIntList(data) {
return data.split(',').map(function(val) {
return parseInt(val, 10)
})
}

45
node_modules/parse-bmfont-ascii/package.json generated vendored Normal file
View File

@ -0,0 +1,45 @@
{
"name": "parse-bmfont-ascii",
"version": "1.0.6",
"description": "parses ASCII BMFont files to a JavaScript object",
"main": "index.js",
"license": "MIT",
"author": {
"name": "Matt DesLauriers",
"email": "dave.des@gmail.com",
"url": "https://github.com/mattdesl"
},
"dependencies": {},
"devDependencies": {
"tape": "^3.5.0"
},
"scripts": {
"test": "node test/test.js"
},
"keywords": [
"ascii",
"parse",
"convert",
"bmfont",
"bm",
"bitmap",
"font",
"bitmaps",
"angel",
"angelcode",
"code",
"text",
"gl",
"sprite",
"sprites",
"stackgl"
],
"repository": {
"type": "git",
"url": "git://github.com/mattdesl/parse-bmfont-ascii.git"
},
"homepage": "https://github.com/mattdesl/parse-bmfont-ascii",
"bugs": {
"url": "https://github.com/mattdesl/parse-bmfont-ascii/issues"
}
}