From 4650b8d2930590c4b4332218ac8777294de2d5e0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 26 Aug 2022 21:00:37 -0600 Subject: [PATCH] [cff] Store varStore in CharStrings --- Lib/fontTools/cffLib/__init__.py | 8 +++++--- Lib/fontTools/ttLib/ttGlyphSet.py | 10 ++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/fontTools/cffLib/__init__.py b/Lib/fontTools/cffLib/__init__.py index 3eda9ba48..bdca7d94e 100644 --- a/Lib/fontTools/cffLib/__init__.py +++ b/Lib/fontTools/cffLib/__init__.py @@ -1125,8 +1125,9 @@ class CharStrings(object): """ def __init__(self, file, charset, globalSubrs, private, fdSelect, fdArray, - isCFF2=None): + isCFF2=None, varStore=None): self.globalSubrs = globalSubrs + self.varStore = varStore if file is not None: self.charStringsIndex = SubrsIndex( file, globalSubrs, private, fdSelect, fdArray, isCFF2=isCFF2) @@ -1516,6 +1517,7 @@ class CharStringsConverter(TableConverter): file = parent.file isCFF2 = parent._isCFF2 charset = parent.charset + varStore = getattr(parent, "VarStore", None) globalSubrs = parent.GlobalSubrs if hasattr(parent, "FDArray"): fdArray = parent.FDArray @@ -1529,7 +1531,7 @@ class CharStringsConverter(TableConverter): private = parent.Private file.seek(value) # Offset(0) charStrings = CharStrings( - file, charset, globalSubrs, private, fdSelect, fdArray, isCFF2=isCFF2) + file, charset, globalSubrs, private, fdSelect, fdArray, isCFF2=isCFF2, varStore=varStore) return charStrings def write(self, parent, value): @@ -1551,7 +1553,7 @@ class CharStringsConverter(TableConverter): # there is no fdArray. private, fdSelect, fdArray = parent.Private, None, None charStrings = CharStrings( - None, None, parent.GlobalSubrs, private, fdSelect, fdArray) + None, None, parent.GlobalSubrs, private, fdSelect, fdArray, varStore=getattr(parent, "VarStore", None)) charStrings.fromXML(name, attrs, content) return charStrings diff --git a/Lib/fontTools/ttLib/ttGlyphSet.py b/Lib/fontTools/ttLib/ttGlyphSet.py index 8a2e42ee5..0b3ae9b21 100644 --- a/Lib/fontTools/ttLib/ttGlyphSet.py +++ b/Lib/fontTools/ttLib/ttGlyphSet.py @@ -187,6 +187,7 @@ class _TTVarGlyph(_TTGlyph): super().__init__(glyphs, glyphs[glyphName]) self._ttFont = ttFont + self._glyphs = glyphs self._glyphName = glyphName self._location = location @@ -194,15 +195,12 @@ class _TTVarGlyph(_TTGlyph): class _TTVarGlyphCFF(_TTVarGlyph): def draw(self, pen): - from fontTools.varLib.varStore import VarStoreInstancer - table_tag = "CFF2" if "CFF2" in self._ttFont else "CFF " - cff = self._ttFont[table_tag].cff - topDict = cff.topDictIndex[0] - varStore = getattr(topDict, "VarStore", None) + varStore = self._glyphs.varStore if varStore is None: blender = None else: - vsInstancer = VarStoreInstancer(topDict.VarStore.otVarStore, self._ttFont['fvar'].axes, self._location) + from fontTools.varLib.varStore import VarStoreInstancer + vsInstancer = VarStoreInstancer(varStore.otVarStore, self._ttFont['fvar'].axes, self._location) blender = vsInstancer.interpolateFromDeltas self._glyph.draw(pen, blender) self.width = self._ttFont['hmtx'][self._glyphName][0]