Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active November 13, 2024 01:44
Show Gist options
  • Save mizchi/989e4b4e207363b8b8f0ecbb5b76658f to your computer and use it in GitHub Desktop.
Save mizchi/989e4b4e207363b8b8f0ecbb5b76658f to your computer and use it in GitHub Desktop.
/*
事前に unicode-range が判明しているフォントから、unicode-range を抜き出して専用の woff2 を作成するテスト
ブラウザでこれを実行
[...new Set(Array.from(document.body.textContent).map(t => t.codePointAt(0)))].sort()
$ ls
╭───┬─────────────────────────┬──────┬──────────┬────────────────╮
│ # │ name │ type │ size │ modified │
├───┼─────────────────────────┼──────┼──────────┼────────────────┤
│ 1 │ NotoSansJP-custom.woff2 │ file │ 28.5 KiB │ 31 seconds ago │
│ 2 │ NotoSansJP.ttf │ file │ 9.1 MiB │ an hour ago │
╰───┴─────────────────────────┴──────┴──────────┴────────────────╯
*/
import { Font, woff2 } from "fonteditor-core";
import fs from "fs/promises";
const ranges = [];
async function main() {
await woff2.init();
const b0 = await fs.readFile("NotoSansJP.ttf");
const font = Font.create(b0, {
type: "ttf",
subset: ranges,
compound2simple: true,
inflate: undefined,
combinePath: false,
});
// @ts-ignore
const b1 = font.write({
type: "woff2",
toBuffer: true,
hinting: false,
kerning: false,
writeZeroContoursGlyfData: false,
support: { head: {}, hhea: {} },
});
font.optimize();
font.compound2simple();
await fs.writeFile("NotoSansJP-custom.woff2", b1 as any);
}
// cons
main().catch(console.error);
@mizchi
Copy link
Author

mizchi commented Oct 16, 2024

実行例
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment