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

85
node_modules/parse-bmfont-xml/lib/browser.js generated vendored Normal file
View File

@ -0,0 +1,85 @@
var parseAttributes = require('./parse-attribs')
var parseFromString = require('xml-parse-from-string')
//In some cases element.attribute.nodeName can return
//all lowercase values.. so we need to map them to the correct
//case
var NAME_MAP = {
scaleh: 'scaleH',
scalew: 'scaleW',
stretchh: 'stretchH',
lineheight: 'lineHeight',
alphachnl: 'alphaChnl',
redchnl: 'redChnl',
greenchnl: 'greenChnl',
bluechnl: 'blueChnl'
}
module.exports = function parse(data) {
data = data.toString()
var xmlRoot = parseFromString(data)
var output = {
pages: [],
chars: [],
kernings: []
}
//get config settings
;['info', 'common'].forEach(function(key) {
var element = xmlRoot.getElementsByTagName(key)[0]
if (element)
output[key] = parseAttributes(getAttribs(element))
})
//get page info
var pageRoot = xmlRoot.getElementsByTagName('pages')[0]
if (!pageRoot)
throw new Error('malformed file -- no <pages> element')
var pages = pageRoot.getElementsByTagName('page')
for (var i=0; i<pages.length; i++) {
var p = pages[i]
var id = parseInt(p.getAttribute('id'), 10)
var file = p.getAttribute('file')
if (isNaN(id))
throw new Error('malformed file -- page "id" attribute is NaN')
if (!file)
throw new Error('malformed file -- needs page "file" attribute')
output.pages[parseInt(id, 10)] = file
}
//get kernings / chars
;['chars', 'kernings'].forEach(function(key) {
var element = xmlRoot.getElementsByTagName(key)[0]
if (!element)
return
var childTag = key.substring(0, key.length-1)
var children = element.getElementsByTagName(childTag)
for (var i=0; i<children.length; i++) {
var child = children[i]
output[key].push(parseAttributes(getAttribs(child)))
}
})
return output
}
function getAttribs(element) {
var attribs = getAttribList(element)
return attribs.reduce(function(dict, attrib) {
var key = mapName(attrib.nodeName)
dict[key] = attrib.nodeValue
return dict
}, {})
}
function getAttribList(element) {
//IE8+ and modern browsers
var attribs = []
for (var i=0; i<element.attributes.length; i++)
attribs.push(element.attributes[i])
return attribs
}
function mapName(nodeName) {
return NAME_MAP[nodeName.toLowerCase()] || nodeName
}

49
node_modules/parse-bmfont-xml/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,49 @@
var xml2js = require('xml2js')
var parseAttributes = require('./parse-attribs')
module.exports = function parseBMFontXML(data) {
data = data.toString().trim()
var output = {
pages: [],
chars: [],
kernings: []
}
xml2js.parseString(data, function(err, result) {
if (err)
throw err
if (!result.font)
throw "XML bitmap font doesn't have <font> root"
result = result.font
output.common = parseAttributes(result.common[0].$)
output.info = parseAttributes(result.info[0].$)
for (var i = 0; i < result.pages.length; i++) {
var p = result.pages[i].page[0].$
if (typeof p.id === "undefined")
throw new Error("malformed file -- needs page id=N")
if (typeof p.file !== "string")
throw new Error("malformed file -- needs page file=\"path\"")
output.pages[parseInt(p.id, 10)] = p.file
}
if (result.chars) {
var chrArray = result.chars[0]['char'] || []
for (var i = 0; i < chrArray.length; i++) {
output.chars.push(parseAttributes(chrArray[i].$))
}
}
if (result.kernings) {
var kernArray = result.kernings[0]['kerning'] || []
for (var i = 0; i < kernArray.length; i++) {
output.kernings.push(parseAttributes(kernArray[i].$))
}
}
})
return output
}

28
node_modules/parse-bmfont-xml/lib/parse-attribs.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
//Some versions of GlyphDesigner have a typo
//that causes some bugs with parsing.
//Need to confirm with recent version of the software
//to see whether this is still an issue or not.
var GLYPH_DESIGNER_ERROR = 'chasrset'
module.exports = function parseAttributes(obj) {
if (GLYPH_DESIGNER_ERROR in obj) {
obj['charset'] = obj[GLYPH_DESIGNER_ERROR]
delete obj[GLYPH_DESIGNER_ERROR]
}
for (var k in obj) {
if (k === 'face' || k === 'charset')
continue
else if (k === 'padding' || k === 'spacing')
obj[k] = parseIntList(obj[k])
else
obj[k] = parseInt(obj[k], 10)
}
return obj
}
function parseIntList(data) {
return data.split(',').map(function(val) {
return parseInt(val, 10)
})
}