From 54520eb36a3ca9e61a7a39db673b2df76c456999 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Sun, 9 Nov 2025 08:56:42 -0800 Subject: [PATCH] Feat: Build Stain font into dist --- scripts/build-font.js | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 scripts/build-font.js diff --git a/scripts/build-font.js b/scripts/build-font.js new file mode 100644 index 0000000..14dde55 --- /dev/null +++ b/scripts/build-font.js @@ -0,0 +1,44 @@ +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; +import opentype from "opentype.js"; +import { glyphA, glypha } from "../src/glyphs/A.js"; +import { glyphB, glyphb } from "../src/glyphs/B.js"; +import { glyphC, glyphc } from "../src/glyphs/C.js"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const outDir = path.join(__dirname, "..", "dist"); +if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true }); + +const familyName = "Stain"; +const unitsPerEm = 1000; +const ascender = 800; +const descender = -200; +const advanceWidth = 600; + +const font = new opentype.Font({ + familyName, + styleName: "Regular", + unitsPerEm, + ascender, + descender, + glyphs: [] +}); + +const addGlyph = (g) => font.addGlyph(g); + +addGlyph(glyphA(opentype, advanceWidth)); +addGlyph(glypha(opentype, advanceWidth)); +addGlyph(glyphB(opentype, advanceWidth)); +addGlyph(glyphb(opentype, advanceWidth)); +addGlyph(glyphC(opentype, advanceWidth)); +addGlyph(glyphc(opentype, advanceWidth)); + +const otfBuffer = Buffer.from(font.toArrayBuffer()); +const baseName = "Stain"; +const otfPath = path.join(outDir, `${baseName}.otf`); +fs.writeFileSync(otfPath, otfBuffer); + +console.log(`Built ${otfPath}`);