[ttGlyphSet] Support VARC CFF2 fonts

This commit is contained in:
Behdad Esfahbod 2024-11-05 10:52:03 -05:00
parent d6f3c51895
commit 1773f7b0ad

View File

@ -119,19 +119,35 @@ class _TTGlyphSetCFF(_TTGlyphSet):
tableTag = "CFF2" if "CFF2" in font else "CFF " tableTag = "CFF2" if "CFF2" in font else "CFF "
self.charStrings = list(font[tableTag].cff.values())[0].CharStrings self.charStrings = list(font[tableTag].cff.values())[0].CharStrings
super().__init__(font, location, self.charStrings) super().__init__(font, location, self.charStrings)
self.setLocation(location)
def __getitem__(self, glyphName):
return _TTGlyphCFF(self, glyphName)
def setLocation(self, location):
self.blender = None self.blender = None
if location: if location:
# TODO Optimize by using instancer.setLocation()
from fontTools.varLib.varStore import VarStoreInstancer from fontTools.varLib.varStore import VarStoreInstancer
varStore = getattr(self.charStrings, "varStore", None) varStore = getattr(self.charStrings, "varStore", None)
if varStore is not None: if varStore is not None:
instancer = VarStoreInstancer( instancer = VarStoreInstancer(
varStore.otVarStore, font["fvar"].axes, location varStore.otVarStore, self.font["fvar"].axes, location
) )
self.blender = instancer.interpolateFromDeltas self.blender = instancer.interpolateFromDeltas
else:
self.blender = None
def __getitem__(self, glyphName): @contextmanager
return _TTGlyphCFF(self, glyphName) def pushLocation(self, location, reset: bool):
self.setLocation(location)
with _TTGlyphSet.pushLocation(self, location, reset) as value:
try:
yield value
finally:
self.setLocation(self.location)
class _TTGlyphSetVARC(_TTGlyphSet): class _TTGlyphSetVARC(_TTGlyphSet):
@ -335,7 +351,6 @@ class _TTGlyphVARC(_TTGlyph):
) )
for comp in glyph.components: for comp in glyph.components:
if comp.flags & VarComponentFlags.HAVE_CONDITION: if comp.flags & VarComponentFlags.HAVE_CONDITION:
condition = varc.ConditionList.ConditionTable[comp.conditionIndex] condition = varc.ConditionList.ConditionTable[comp.conditionIndex]
if not _evaluateCondition( if not _evaluateCondition(