Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Node.js adapter of python font tools via Pyodide

License

NotificationsYou must be signed in to change notification settings

web-alchemy/fonttools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is the Node.js adapter ofpython font tools viaPyodide 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/fonttools

After installingfont utilities will be available globally:

fonttools<params>pyftsubset<params>pyftmerge<params>ttx<params>

Also you can use this tool vianpx:

npx -p @web-alchemy/fonttools<params>npx -p @web-alchemy/fonttools pyftsubset<params>npx -p @web-alchemy/fonttools pyftmerge<params>npx -p @web-alchemy/fonttools ttx<params>

Example of convertingttf towoff2:

npx -p @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 convertingttf towoff2 and subseting with text and unicodes options:

npx -p @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 ofcustomizing variable font's axes:

npx @web-alchemy/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:

const{  subset,  instantiateVariableFont,  ttx}=require('@web-alchemy/fonttools')

Example of convertingttf towoff2:

constfs=require('node:fs')const{ subset}=require('@web-alchemy/fonttools')asyncfunctionmain(){constinputFileBuffer=awaitfs.promises.readFile('./font.ttf')constoutputFileBuffer=awaitsubset(inputFileBuffer,{'*':true,// keep all glyphs and just convert format'flavor':'woff2',})awaitfs.promises.writeFile('./font.woff2',outputFileBuffer)}main()

Example of convertingttf towoff2 and subseting with text and unicodes options:

constfs=require('node:fs')const{ subset}=require('@web-alchemy/fonttools')asyncfunctionmain(){constinputFileBuffer=awaitfs.promises.readFile('./font.ttf')constoutputFileBuffer=awaitsubset(inputFileBuffer,{'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",'flavor':'woff2',})awaitfs.promises.writeFile('./font.woff2',outputFileBuffer)}main()

Methodsubset takes same params asoriginalpyftsubset utility(without dashes--).

Example ofcustomizing variable font's axes:

constfs=require('node:fs')const{ instantiateVariableFont}=require('@web-alchemy/fonttools')asyncfunctionmain(){constinputFileBuffer=awaitfs.promises.readFile('./src/font.woff2')constoutputFileBuffer=awaitinstantiateVariableFont(inputFileBuffer,{wght:[300,500],// decrease `wght` axis rangewdth:null// delete `wdth` axis})awaitfs.promises.writeFile('dist/font.woff2',outputFileBuffer)}main()

This is port ofmethodvarLib.instancer.instantiateVariableFont.

Methodttx can convert binary font files (.otf, .ttf, etc) to the TTX XML format and convert them back to binary format.

Example of converting binary files to xml:

constfs=require('node:fs');const{ ttx}=require('@web-alchemy/fonttools');(async()=>{constoutputTtxBuffer=awaitttx('./font.ttf');// also accept `URL` and `Buffer`awaitfs.promises.writeFile('./font.ttx',outputTtxBuffer);constoutputOtxBuffer=awaitttx('./font.otf');awaitfs.promises.writeFile('./font.otx',outputOtxBuffer);})();

Example of converting xml files to binary files:

constfs=require('node:fs');const{ ttx}=require('@web-alchemy/fonttools');(async()=>{constttfBuffer=awaitttx('./font.ttx');awaitfs.promises.writeFile('./font.ttf',ttfBuffer);constotfBuffer=awaitttx('./font.otx');awaitfs.promises.writeFile('./font.otf',otfBuffer);})();

Example of converting xml files to binary files with encoding towoff2:

constfs=require('node:fs');const{ ttx}=require('@web-alchemy/fonttools');(async()=>{constttfBuffer=awaitttx('./font.ttx',[['--flavor','woff2']]);awaitfs.promises.writeFile('./font.woff2',ttfBuffer);constotfBuffer=awaitttx('./font.otx',[['--flavor','woff2']]);awaitfs.promises.writeFile('./font.woff2',otfBuffer);})();

Limitations

  • Doesn't supportzopfli package for better optimizing woff files.
  • In CLI all file paths should be relative tocwd (current working directory).

References

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp