## 使用python 这里使用到的是Python 的库:`fonttools` 使用最新版 `Python` 的 pip 命令安装即可在 Shell 中使用: ```shell pip install fonttools ``` 常用汉字大约有3500字 我使用的是这个[现代汉语常用 3500 字.txt](https://cdn.jkjoy.cn/3000.txt) 中文常用字库项目https://github.com/DavidSheh/CommonChineseCharacter ## 取子集 使用以下命令即可对字体文件取子集 ``` fonttools subset "$input_file" --text-file="$text_file" --output-file="$output_file" ``` 其中 `$input_file`:输入的字体文件。 `$text_file`:定义保留字符的纯文本文件路径。 `$output_file`:输出的字体文件路径。 取完子集完成之后字体从11M压缩到1.7M左右 ## 压缩 安装模块`brotli` ```shell pip install brotli ``` 使用命令 ```shell fonttools ttLib.woff2 compress "$input_file" -o "$output_file" ``` 其中 `$input_file`:输入的字体文件。 `$output_file`:输出的字体文件路径。 再次压缩为 woff2 字体格式 大约840kb Loading... ## 使用python 这里使用到的是Python 的库:`fonttools` 使用最新版 `Python` 的 pip 命令安装即可在 Shell 中使用: ```shell pip install fonttools ``` 常用汉字大约有3500字 我使用的是这个[现代汉语常用 3500 字.txt](https://cdn.jkjoy.cn/3000.txt) 中文常用字库项目https://github.com/DavidSheh/CommonChineseCharacter ## 取子集 使用以下命令即可对字体文件取子集 ``` fonttools subset "$input_file" --text-file="$text_file" --output-file="$output_file" ``` 其中 `$input_file`:输入的字体文件。 `$text_file`:定义保留字符的纯文本文件路径。 `$output_file`:输出的字体文件路径。 取完子集完成之后字体从11M压缩到1.7M左右 ## 压缩 安装模块`brotli` ```shell pip install brotli ``` 使用命令 ```shell fonttools ttLib.woff2 compress "$input_file" -o "$output_file" ``` 其中 `$input_file`:输入的字体文件。 `$output_file`:输出的字体文件路径。 再次压缩为 woff2 字体格式 大约840kb [AD]【腾讯云】年度爆款2核2G4M云服务器118元/年,新老用户同享 最后修改:2024 年 08 月 22 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏