This repository has been archived on 2025-10-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
inter-font/misc/pylib/extractor/formats/ttx.py
2017-11-28 17:11:48 -08:00

28 lines
982 B
Python
Executable file

from extractor.formats.opentype import extractOpenTypeInfo, extractOpenTypeGlyphs, extractOpenTypeKerning
def isTTX(pathOrFile):
from fontTools.ttLib import TTFont, TTLibError
try:
font = TTFont()
font.importXML(pathOrFile)
del font
except TTLibError:
return False
return True
def extractFontFromTTX(pathOrFile, destination, doGlyphs=True, doInfo=True, doKerning=True, customFunctions=[]):
from fontTools.ttLib import TTFont, TTLibError
source = TTFont()
source.importXML(pathOrFile)
if doInfo:
extractOpenTypeInfo(source, destination)
if doGlyphs:
extractOpenTypeGlyphs(source, destination)
if doKerning:
kerning, groups = extractOpenTypeKerning(source, destination)
destination.groups.update(groups)
destination.kerning.clear()
destination.kerning.update(kerning)
for function in customFunctions:
function(source, destination)
source.close()