Upgraded to code2000 font

This commit is contained in:
Willem Cazander 2022-02-11 02:46:44 +01:00
parent bb76cbbe2f
commit 76014cfe87
11 changed files with 81 additions and 106 deletions

View file

@ -18,19 +18,34 @@ console.log("<opentype>");
let num = font.numGlyphs;
for(let glyphIndex = 0; glyphIndex < num; glyphIndex++) {
let glyph = font.glyphs.get(glyphIndex);
let path = glyph.getPath(0, 0, 72);
if (path.commands.length === 0) {
// JS NOTE: without calling xMin the getContours return empty set.... :''(
glyph.xMin;
var contours = glyph.getContours();
if (contours.length === 0) {
// TODO: add compound support
continue;
}
if (glyph.unicodes.length === 0) {
continue; // with cmds, these are compound glyphs
}
let uni = glyph.unicodes.map(formatUnicode).join(', ');
console.log("\t<glyph unicode=\""+uni+"\" name=\""+glyph.name+"\">"); /*"advanceWidth=\""+glyph.advanceWidth+"\" "+
console.log("\t<glyph unicode=\""+uni+"\" name=\""+glyph.name+"\" advanceWidth=\""+glyph.advanceWidth+"\" "+
"xMin=\""+glyph.xMin+"\" xMax=\""+glyph.xMax+"\" yMin=\""+glyph.yMin+"\" yMax=\""+glyph.yMax+"\" "+
"leftSideBearing=\""+glyph.leftSideBearing+"\" pathFill=\""+path.fill+"\" "+
"strokeStyle=\""+path.stroke+"\" lineWidth=\""+path.strokeWidth+"\">"); */
"leftSideBearing=\""+glyph.leftSideBearing+"\">");
for (let contourIndex = 0; contourIndex < contours.length; ++contourIndex) {
const contour = contours[contourIndex];
console.log("\t\t<contour>");
for (let i = 0; i < contour.length; ++i) {
let curr = contour[i];
console.log("\t\t\t<point x=\""+curr.x+"\" y=\""+curr.y+"\" onCurve=\""+curr.onCurve+"\"/>");
}
console.log("\t\t</contour>");
//console.log(JSON.stringify(curr));
}
/*
for (i = 0; i < path.commands.length; i += 1) {
cmd = path.commands[i];
if (cmd.type === 'M') {
@ -45,6 +60,7 @@ for(let glyphIndex = 0; glyphIndex < num; glyphIndex++) {
console.log("\t\t<pathClose/>");
}
}
*/``
console.log("\t</glyph>");
}
console.log("</opentype>");

View file

@ -4,13 +4,10 @@
"description": "Convert font data to XML intermediate.",
"private": true,
"scripts": {
"start": "npm run-script conv0 && npm run-script conv1 && npm run-script conv2 && npm run-script conv3 && npm run-script conv4",
"conv0": "node conv-font.js ../main-gdxapp/assets/font/free-sans.ttf > bin/free-sans.xml",
"conv1": "node conv-font.js ../main-gdxapp/assets/font/noto-sans-cjkjp-medium.otf > bin/noto-sans-cjkjp-medium.xml",
"conv2": "node conv-font.js ../main-gdxapp/assets/font/roboto-bold.ttf > bin/roboto-bold.xml",
"conv3": "node conv-font.js ../main-gdxapp/assets/font/arslan-wessam.ttf > bin/arslan-wessam.xml",
"conv4": "node conv-font.js ../main-gdxapp/assets/font/norse-kawl.otf > bin/norse-kawl.xml",
"debug": "node conv-font.js ../main-gdxapp/assets/font/roboto-bold.ttf"
"start": "npm run-script conv0 && npm run-script conv1",
"conv0": "node conv-font.js ../main-gdxapp/assets/font/code2000.ttf > bin/code2000.xml",
"conv1": "node conv-font.js ../main-gdxapp/assets/font/free-sans.ttf > bin/free-sans.xml",
"debug": "node conv-font.js ../main-gdxapp/assets/font/free-sans.ttf"
},
"dependencies": {
"opentype.js": "1.3.4"