diff --git a/Lib/fontTools/cffLib/__init__.py b/Lib/fontTools/cffLib/__init__.py index bbcc27780..a11b8f6a9 100644 --- a/Lib/fontTools/cffLib/__init__.py +++ b/Lib/fontTools/cffLib/__init__.py @@ -2327,7 +2327,7 @@ class TopDict(BaseDict): def recalcFontBBox(self): fontBBox = None for charString in self.CharStrings.values(): - bounds = charString.calcBounds() + bounds = charString.calcBounds(self.CharStrings) if bounds is not None: if fontBBox is not None: fontBBox = unionRect(fontBBox, bounds) diff --git a/Lib/fontTools/misc/psCharStrings.py b/Lib/fontTools/misc/psCharStrings.py index 0bb4a79b3..3f5d1579c 100644 --- a/Lib/fontTools/misc/psCharStrings.py +++ b/Lib/fontTools/misc/psCharStrings.py @@ -979,8 +979,8 @@ class T2CharString(object): extractor.execute(self) self.width = extractor.width - def calcBounds(self): - boundsPen = BoundsPen(None) + def calcBounds(self, glyphSet): + boundsPen = BoundsPen(glyphSet) self.draw(boundsPen) return boundsPen.bounds diff --git a/Lib/fontTools/ttLib/tables/_h_h_e_a.py b/Lib/fontTools/ttLib/tables/_h_h_e_a.py index 9e9d08594..bde9073cb 100644 --- a/Lib/fontTools/ttLib/tables/_h_h_e_a.py +++ b/Lib/fontTools/ttLib/tables/_h_h_e_a.py @@ -64,9 +64,10 @@ class table__h_h_e_a(DefaultTable.DefaultTable): boundsWidthDict[name] = g.xMax - g.xMin elif 'CFF ' in ttFont: topDict = ttFont['CFF '].cff.topDictIndex[0] + charStrings = topDict.CharStrings for name in ttFont.getGlyphOrder(): - cs = topDict.CharStrings[name] - bounds = cs.calcBounds() + cs = charStrings[name] + bounds = cs.calcBounds(charStrings) if bounds is not None: boundsWidthDict[name] = int( math.ceil(bounds[2]) - math.floor(bounds[0])) diff --git a/Lib/fontTools/ttLib/tables/_v_h_e_a.py b/Lib/fontTools/ttLib/tables/_v_h_e_a.py index 51769515d..312c5eca5 100644 --- a/Lib/fontTools/ttLib/tables/_v_h_e_a.py +++ b/Lib/fontTools/ttLib/tables/_v_h_e_a.py @@ -63,9 +63,10 @@ class table__v_h_e_a(DefaultTable.DefaultTable): boundsHeightDict[name] = g.yMax - g.yMin elif 'CFF ' in ttFont: topDict = ttFont['CFF '].cff.topDictIndex[0] + charStrings = topDict.CharStrings for name in ttFont.getGlyphOrder(): - cs = topDict.CharStrings[name] - bounds = cs.calcBounds() + cs = charStrings[name] + bounds = cs.calcBounds(charStrings) if bounds is not None: boundsHeightDict[name] = int( math.ceil(bounds[3]) - math.floor(bounds[1])) diff --git a/Tests/misc/psCharStrings_test.py b/Tests/misc/psCharStrings_test.py index 552565b05..1e36246dc 100644 --- a/Tests/misc/psCharStrings_test.py +++ b/Tests/misc/psCharStrings_test.py @@ -13,17 +13,17 @@ class T2CharStringTest(unittest.TestCase): def test_calcBounds_empty(self): cs = self.stringToT2CharString("endchar") - bounds = cs.calcBounds() + bounds = cs.calcBounds(None) self.assertEqual(bounds, None) def test_calcBounds_line(self): cs = self.stringToT2CharString("100 100 rmoveto 40 10 rlineto -20 50 rlineto endchar") - bounds = cs.calcBounds() + bounds = cs.calcBounds(None) self.assertEqual(bounds, (100, 100, 140, 160)) def test_calcBounds_curve(self): cs = self.stringToT2CharString("100 100 rmoveto -50 -150 200 0 -50 150 rrcurveto endchar") - bounds = cs.calcBounds() + bounds = cs.calcBounds(None) self.assertEqual(bounds, (91.90524980688875, -12.5, 208.09475019311125, 100))