You must install Fonttools and SFNT2WOFF-Zopfli to use the functionality in this Gist. You will also need to ensure that the brotli
library is available for Fonttools.
Fonttools can be easily installed using Homebrew, by doing brew install fonttools
. If you installed via Brew, you can install the brotli
extension using
/usr/local/Cellar/fonttools/3.5.0/libexec/bin/pip install brotli
SFNT2WOFF-Zopfli is a somewhat more complicated to install. The simples way is to just have it in a folder somewhere, which you can do it by downloading the source off of GitHub and then running make
inside the downloaded directory.
You should make two folders, called input
and output
. Place your TTF-files in the input
-folder. Then create a text-file called subset.txt
which contains the unicode-characters you want the subset to contain.
Simply run make
in this directory.
If Fonttools isn't in your path, use FONTTOOLS_DIR
to change where to search for the tools. Similarly for SFNT2WOFF-Zopfli where you can use SFNT2WOFF_DIR
to modify the search-path.
If you wish to change the number of iterations that Zopfli runs, then you can use the variable ITERATIONS
If you want to utilize more than one CPU, you can use the -j
-flag, which enables parallel processing in Make.
If you have Fonttools installed via Brews (and thus in your path), but have SFNT2WOFF-Zopfli in your user-directory (Users/xyz/sfnt2woff-zopfli
), and you want to run 50 Zopfli-iterations and utilize 4 CPU-cores, you can use
SFNT2WOFF_DIR=/Users/xyz/sfnt2woff-zopfli ITERATIONS=50 make -j4
The characters of the font that is included in the subset is determined by the contents of the file subset.txt
. When you modify it, you can simply rerun make
to optimize based on the new subset.
I admit that I'm pretty bad at doing anything in Make, so it's been a lot of trial-and-error to get it working. If anyone has suggestions for doing something differently, let me know.
If there is enough interest, I guess this should be made into a proper repo.