From 1773f7b0ad4c69c72f62fe23b6cf9d878b4fa5c5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 5 Nov 2024 10:52:03 -0500 Subject: [PATCH] [ttGlyphSet] Support VARC CFF2 fonts --- Lib/fontTools/ttLib/ttGlyphSet.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/ttLib/ttGlyphSet.py b/Lib/fontTools/ttLib/ttGlyphSet.py index 446c81e7d..e8dd007c5 100644 --- a/Lib/fontTools/ttLib/ttGlyphSet.py +++ b/Lib/fontTools/ttLib/ttGlyphSet.py @@ -119,19 +119,35 @@ class _TTGlyphSetCFF(_TTGlyphSet): tableTag = "CFF2" if "CFF2" in font else "CFF " self.charStrings = list(font[tableTag].cff.values())[0].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 if location: + # TODO Optimize by using instancer.setLocation() + from fontTools.varLib.varStore import VarStoreInstancer varStore = getattr(self.charStrings, "varStore", None) if varStore is not None: instancer = VarStoreInstancer( - varStore.otVarStore, font["fvar"].axes, location + varStore.otVarStore, self.font["fvar"].axes, location ) self.blender = instancer.interpolateFromDeltas + else: + self.blender = None - def __getitem__(self, glyphName): - return _TTGlyphCFF(self, glyphName) + @contextmanager + 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): @@ -335,7 +351,6 @@ class _TTGlyphVARC(_TTGlyph): ) for comp in glyph.components: - if comp.flags & VarComponentFlags.HAVE_CONDITION: condition = varc.ConditionList.ConditionTable[comp.conditionIndex] if not _evaluateCondition(