An elegant font compression solution — fonttools

Original link: https://zburu.com/2022/05/24/106.html

Sharing a python library – fonttools, it is very convenient to deal with font files.

download

You need to download the python environment on your computer first, so I won’t say much about this.

Then enter on the local command line:

 pip install fonttools

font library

1653623749590.png

  1. Create a new folder locally, name it fonts , you can do whatever you want. Put the fonts you need to compress and organize in a folder, such as OPPOSans.ttf .
  2. Then create a file named word.txt , then we need to find a common font library, here I share one on github https://github.com/zburu/cdn/blob/main/font/Chinese common fonts.txt , and copy the common fonts in it to the word.txt file.

run

 pyftsubset OPPOSans.ttf --text=$(cat word.txt) --no-hinting

1653623896959.png

Let’s take a look at the command, where OPPOSans.ttf is the font file, word.txt is the common font, we want to separate these words separately.

The names can be according to their own requirements, but they must correspond to each other.

1653623936778.png

You can enter it on the command line. After the operation is completed, you can see the font file with the word subset in the folder. The space occupied is greatly reduced, and it can be used directly.

This article is reprinted from: https://zburu.com/2022/05/24/106.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.