2022-08-15 13:01:46 -06:00
|
|
|
"""Specialization of fontTools.misc.visitor to work with TTFont."""
|
|
|
|
|
|
|
|
from fontTools.misc.visitor import Visitor
|
|
|
|
from fontTools.ttLib import TTFont
|
|
|
|
|
|
|
|
|
|
|
|
class TTVisitor(Visitor):
|
2022-08-15 13:42:42 -06:00
|
|
|
def visitAttr(self, obj, attr, value, *args, **kwargs):
|
|
|
|
if isinstance(value, TTFont):
|
|
|
|
return False
|
|
|
|
super().visitAttr(obj, attr, value, *args, **kwargs)
|
|
|
|
|
2022-08-15 13:01:46 -06:00
|
|
|
def visit(self, obj, *args, **kwargs):
|
|
|
|
if hasattr(obj, "ensureDecompiled"):
|
|
|
|
obj.ensureDecompiled(recurse=False)
|
|
|
|
super().visit(obj, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
@TTVisitor.register(TTFont)
|
2022-08-15 17:08:16 -06:00
|
|
|
def visit(visitor, font, *args, **kwargs):
|
2022-08-17 14:20:36 -06:00
|
|
|
# Some objects have links back to TTFont; even though we
|
|
|
|
# have a check in visitAttr to stop them from recursing
|
|
|
|
# onto TTFont, sometimes they still do, for example when
|
|
|
|
# someone overrides visitAttr.
|
2022-08-15 13:01:46 -06:00
|
|
|
if hasattr(visitor, "font"):
|
|
|
|
return False
|
2022-08-17 14:20:36 -06:00
|
|
|
|
2022-08-15 13:01:46 -06:00
|
|
|
visitor.font = font
|
|
|
|
for tag in font.keys():
|
2022-08-15 17:08:16 -06:00
|
|
|
visitor.visit(font[tag], *args, **kwargs)
|
2022-08-15 13:01:46 -06:00
|
|
|
del visitor.font
|
|
|
|
return False
|