[cff] Fix calcBound when seac-like components happen in endchar
I'm also unimpressed by the copy-pasted bounds logic in hhea and vhea, and the fact that that's coded in there instead of calling a function on CFF / glyf tables respectively.
This commit is contained in:
parent
c99a731adb
commit
4fec016862
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]))
|
||||
|
@ -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]))
|
||||
|
@ -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))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user