Fix: Patch opentype.js to support method chaining

This commit is contained in:
2025-11-19 08:22:52 -08:00
parent e658d998b9
commit 5147973814

View File

@@ -33,6 +33,12 @@ const __filename = fileURLToPath(import.meta.url);
const outDir = path.join(path.dirname(__filename), "..", "dist"); const outDir = path.join(path.dirname(__filename), "..", "dist");
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true }); if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
// Polyfill: opentype.js Path methods return undefined, preventing chaining. Patching to return this.
["moveTo","lineTo","curveTo","quadraticCurveTo","close"].forEach(m=>{
const f=opentype.Path.prototype[m];
opentype.Path.prototype[m]=function(...a){f.apply(this,a);return this};
});
const mkGlyph = (n, u, a, fn) => new opentype.Glyph({ name: n, unicode: u, advanceWidth: a, path: fn(new opentype.Path()) }); const mkGlyph = (n, u, a, fn) => new opentype.Glyph({ name: n, unicode: u, advanceWidth: a, path: fn(new opentype.Path()) });
// Candara-ish tracking: wider capitals, tighter lower, distinct narrow/wide glyphs // Candara-ish tracking: wider capitals, tighter lower, distinct narrow/wide glyphs