目前,我正在使用fonttools(https://github.com/fonttools/fonttools)将字体文件ttf
通过ttx
命令转换成woff2
格式,分为两步:
- 将
ttf
转换成ttx
- 然后将
ttx
转换成woff2
但是这种方法速度太慢,且ttx
文件太大,是否有办法直接使用fonttools将ttf
文件转换成woff2
格式以提高性能?
目前,我正在使用fonttools(https://github.com/fonttools/fonttools)将字体文件ttf
通过ttx
命令转换成woff2
格式,分为两步:
ttf
转换成ttx
ttx
转换成woff2
但是这种方法速度太慢,且ttx
文件太大,是否有办法直接使用fonttools将ttf
文件转换成woff2
格式以提高性能?
如果您在Python(virtualenv、pipenv等)中安装了fonttools:
$ python
>>> from fontTools.ttLib import TTFont
>>> f = TTFont('path/to/your/file.otf')
>>> f.flavor='woff2'
>>> f.save('path/to/your/file.woff2')
注意:您可能需要安装其他fontTools
依赖项(例如'brotli'等)才能使保存时使用flavor=woff2
正常工作。
pip install --user --upgrade fonttools[woff]
python3
>>> from fontTools.ttLib.woff2 import compress
>>> compress('filename.otf','filename.woff2')
./fonttools ttLib Roboto-Regular.ttf --flavor woff2 Roboto-Regular.woff2