Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FNT AngleCode font parser
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
You can’t perform that action at this time.