Created
September 17, 2018 21:42
-
-
Save talltyler/9b00f50152211026555278028cb1825b to your computer and use it in GitHub Desktop.
FNT AngleCode font parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lines = data.split('\n'); | |
function parseObject(args) { | |
const result = {}; | |
for(let i=0;i<args.length;i++){ | |
const arg = args[i].split('='); | |
const val = arg[1]; | |
result[arg[0]] = ~val.indexOf('"') ? val.substr(1,val.length-2) : parseFloat(val,10); | |
} | |
return result; | |
} | |
const result = {}; | |
for(let i=0;i<lines.length;i++){ | |
const line = lines[i]; | |
const lineParts = line.split(' '); | |
const command = lineParts.shift(); | |
switch (command) { | |
case 'info' : | |
case 'common' : | |
case 'page' : | |
result[command] = parseObject(lineParts); | |
break; | |
case 'kerning' : | |
case 'char' : | |
result[command] = result[command] || []; | |
result[command].push(parseObject(lineParts)); | |
break; | |
} | |
} | |
return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment