[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):
|
def recalcFontBBox(self):
|
||||||
fontBBox = None
|
fontBBox = None
|
||||||
for charString in self.CharStrings.values():
|
for charString in self.CharStrings.values():
|
||||||
bounds = charString.calcBounds()
|
bounds = charString.calcBounds(self.CharStrings)
|
||||||
if bounds is not None:
|
if bounds is not None:
|
||||||
if fontBBox is not None:
|
if fontBBox is not None:
|
||||||
fontBBox = unionRect(fontBBox, bounds)
|
fontBBox = unionRect(fontBBox, bounds)
|
||||||
|
@ -979,8 +979,8 @@ class T2CharString(object):
|
|||||||
extractor.execute(self)
|
extractor.execute(self)
|
||||||
self.width = extractor.width
|
self.width = extractor.width
|
||||||
|
|
||||||
def calcBounds(self):
|
def calcBounds(self, glyphSet):
|
||||||
boundsPen = BoundsPen(None)
|
boundsPen = BoundsPen(glyphSet)
|
||||||
self.draw(boundsPen)
|
self.draw(boundsPen)
|
||||||
return boundsPen.bounds
|
return boundsPen.bounds
|
||||||
|
|
||||||
|
@ -64,9 +64,10 @@ class table__h_h_e_a(DefaultTable.DefaultTable):
|
|||||||
boundsWidthDict[name] = g.xMax - g.xMin
|
boundsWidthDict[name] = g.xMax - g.xMin
|
||||||
elif 'CFF ' in ttFont:
|
elif 'CFF ' in ttFont:
|
||||||
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
||||||
|
charStrings = topDict.CharStrings
|
||||||
for name in ttFont.getGlyphOrder():
|
for name in ttFont.getGlyphOrder():
|
||||||
cs = topDict.CharStrings[name]
|
cs = charStrings[name]
|
||||||
bounds = cs.calcBounds()
|
bounds = cs.calcBounds(charStrings)
|
||||||
if bounds is not None:
|
if bounds is not None:
|
||||||
boundsWidthDict[name] = int(
|
boundsWidthDict[name] = int(
|
||||||
math.ceil(bounds[2]) - math.floor(bounds[0]))
|
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
|
boundsHeightDict[name] = g.yMax - g.yMin
|
||||||
elif 'CFF ' in ttFont:
|
elif 'CFF ' in ttFont:
|
||||||
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
||||||
|
charStrings = topDict.CharStrings
|
||||||
for name in ttFont.getGlyphOrder():
|
for name in ttFont.getGlyphOrder():
|
||||||
cs = topDict.CharStrings[name]
|
cs = charStrings[name]
|
||||||
bounds = cs.calcBounds()
|
bounds = cs.calcBounds(charStrings)
|
||||||
if bounds is not None:
|
if bounds is not None:
|
||||||
boundsHeightDict[name] = int(
|
boundsHeightDict[name] = int(
|
||||||
math.ceil(bounds[3]) - math.floor(bounds[1]))
|
math.ceil(bounds[3]) - math.floor(bounds[1]))
|
||||||
|
@ -13,17 +13,17 @@ class T2CharStringTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_calcBounds_empty(self):
|
def test_calcBounds_empty(self):
|
||||||
cs = self.stringToT2CharString("endchar")
|
cs = self.stringToT2CharString("endchar")
|
||||||
bounds = cs.calcBounds()
|
bounds = cs.calcBounds(None)
|
||||||
self.assertEqual(bounds, None)
|
self.assertEqual(bounds, None)
|
||||||
|
|
||||||
def test_calcBounds_line(self):
|
def test_calcBounds_line(self):
|
||||||
cs = self.stringToT2CharString("100 100 rmoveto 40 10 rlineto -20 50 rlineto endchar")
|
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))
|
self.assertEqual(bounds, (100, 100, 140, 160))
|
||||||
|
|
||||||
def test_calcBounds_curve(self):
|
def test_calcBounds_curve(self):
|
||||||
cs = self.stringToT2CharString("100 100 rmoveto -50 -150 200 0 -50 150 rrcurveto endchar")
|
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))
|
self.assertEqual(bounds, (91.90524980688875, -12.5, 208.09475019311125, 100))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user