From c50c419b8c96ce70505706aad1bfbff4d8cb7a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90?= Date: Sat, 24 Aug 2024 08:23:58 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E9=80=9A=E8=BF=87=E5=8F=96=E5=AD=90?= =?UTF-8?q?=E9=9B=86=E7=9A=84=E6=96=B9=E5=BC=8F=E5=8E=8B=E7=BC=A9=E9=9C=9E?= =?UTF-8?q?=E9=B9=9C=E6=96=87=E6=A5=B7=E5=AD=97=E4=BD=93.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../posts/通过取子集的方式压缩霞鹜文楷字体.md | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 content/zh-cn/posts/通过取子集的方式压缩霞鹜文楷字体.md diff --git a/content/zh-cn/posts/通过取子集的方式压缩霞鹜文楷字体.md b/content/zh-cn/posts/通过取子集的方式压缩霞鹜文楷字体.md new file mode 100644 index 0000000..5c8b8c9 --- /dev/null +++ b/content/zh-cn/posts/通过取子集的方式压缩霞鹜文楷字体.md @@ -0,0 +1,50 @@ +--- +title: "通过取子集的方式压缩霞鹜文楷字体" +slug: "yasuoziti" +date: 2024-08-24T00:00:00.000Z +categories: +- 分享 +tags: +- 字体 +--- + +## 使用python + +这里使用到的是Python 的库:`fonttools` + +使用最新版 `Python` 的 pip 命令安装即可在 Shell 中使用: +```shell +pip install fonttools +``` +常用汉字大约有3500字 + +中文常用字库项目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 +