Sharing a Python library ---fonttools, which is very convenient for processing font files.
Download#
First, you need to download the Python environment on your computer, which is self-explanatory.
Then, enter the following command in the local command line:
pip install fonttools
Font Library#
- Create a new folder locally and name it
fonts
, as you like. Put the fonts you need to compress and organize in the folder, such asOPPOSans.ttf
. - Then create a file named
word.txt
. Now we need to find a commonly used font library. Here, I share one on GitHub https://github.com/zburu/cdn/blob/main/font/ 汉字常用字体.txt. Copy the content of commonly used fonts into theword.txt
file.
Run#
pyftsubset OPPOSans.ttf --text=$(cat word.txt) --no-hinting
Let's take a look at the command. OPPOSans.ttf
is the font file, and word.txt
is the commonly used font. We need to separate these characters.
You can name them according to your own requirements, but they must correspond to each other.
Just enter the command in the command line. After running, you can see the font file with the word "subset" in the folder. The file size is greatly reduced and can be used directly.