Last active
November 13, 2024 01:44
-
-
Save mizchi/989e4b4e207363b8b8f0ecbb5b76658f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
事前に 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行例