[cff] Store varStore in CharStrings

This commit is contained in:
Behdad Esfahbod 2022-08-26 21:00:37 -06:00
parent a7cda37fbb
commit 4650b8d293
2 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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]