Font tools
This is the Node.js adapter of python font tools via Pyodide without having to install python and its dependencies.
Font tools library usually used for optimizing fonts – subseting, format converting, deleting of unused variable font axes, etc.
Using as a CLI
You can install the library as a global dependency:
npm install --global @web-alchemy/fonttoolsAfter installing font utilities will be available globally:
fonttools <params>
pyftsubset <params>
pyftmerge <params>
ttx <params>Also you can use this tool via npx:
npx --package=@web-alchemy/fonttools -- fonttools <params>
npx --package=@web-alchemy/fonttools -- pyftsubset <params>
npx --package=@web-alchemy/fonttools -- pyftmerge <params>
npx --package=@web-alchemy/fonttools -- ttx <params>Example of converting ttf to woff2:
npx --package=@web-alchemy/fonttools -- pyftsubset \
"./some/path/to/font.ttf" \
"*" \ # keep all glyphs and just convert format
--output-file="./some/path/to/font.woff2" \
--flavor="woff2"Example of converting ttf to woff2 and subseting with text and unicodes options:
npx --package=@web-alchemy/fonttools -- pyftsubset \
"./some/path/to/font.ttf" \
--output-file="./some/path/to/font.woff2" \
--flavor="woff2" \
--text="The text whose characters will be included in the font file" \
--unicodes="U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" \
--desubroutinize \
--no-hinting \
--layout-features="*"Example of customizing variable font's axes:
npx --package=@web-alchemy/fonttools -- fonttools varLib.instancer \
"./src/font.woff2" \
# decrease `wght` axis range
wght=400:600 \
# delete `wdth` axis
wdth=drop \
--output="./dist/font.woff2"Using as a module
Library provides few JavaScript specific methods: