pythonpython-3.xtruetype

Python3 how to install .ttf font file?


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.


Solution

  • 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.