Python3 how to install .ttf font file?

倖福魔咒の 提交于 2020-01-13 19:36:54

问题


I wanted to install .ttf font file on windows 10 with python3 (more precise Python 3.6) code, I googled but the only thing I found was this one Install TTF fonts on windows with python, I tested it but it didn't do anything. Is there a way to install .ttf with python3 code?

Thanks in advance.


回答1:


This library seems promising (I haven't tried myself).

Installing

pip install --user fonttools

or

pip3 install --user fonttools

Code

from fontTools.ttLib import TTFont
font = TTFont('/path/to/font.ttf')

Then use font.save method:

Definition: font.save(self, file, reorderTables=True)

Docstring: Save the font to disk. Similarly to the constructor, the 'file' argument can be either a pathname or a writable file object.



来源:https://stackoverflow.com/questions/51177475/python3-how-to-install-ttf-font-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!