Merge pull request #3333 from fonttools/fix-empty-composite-bbox
[glyf] skip empty components when computing bounds of composite glyphs
This commit is contained in:
commit
797c0018a0
@ -1211,6 +1211,9 @@ class Glyph(object):
|
|||||||
g.recalcBounds(glyfTable, boundsDone=boundsDone)
|
g.recalcBounds(glyfTable, boundsDone=boundsDone)
|
||||||
if boundsDone is not None:
|
if boundsDone is not None:
|
||||||
boundsDone.add(glyphName)
|
boundsDone.add(glyphName)
|
||||||
|
# empty components shouldn't update the bounds of the parent glyph
|
||||||
|
if g.numberOfContours == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
x, y = compo.x, compo.y
|
x, y = compo.x, compo.y
|
||||||
bounds = updateBounds(bounds, (g.xMin + x, g.yMin + y))
|
bounds = updateBounds(bounds, (g.xMin + x, g.yMin + y))
|
||||||
|
@ -562,6 +562,23 @@ class GlyphTest:
|
|||||||
assert glyphSet["percent"].getCompositeMaxpValues(glyphSet)[2] == 2
|
assert glyphSet["percent"].getCompositeMaxpValues(glyphSet)[2] == 2
|
||||||
assert glyphSet["perthousand"].getCompositeMaxpValues(glyphSet)[2] == 2
|
assert glyphSet["perthousand"].getCompositeMaxpValues(glyphSet)[2] == 2
|
||||||
|
|
||||||
|
def test_recalcBounds_empty_components(self):
|
||||||
|
glyphSet = {}
|
||||||
|
pen = TTGlyphPen(glyphSet)
|
||||||
|
# empty simple glyph
|
||||||
|
foo = glyphSet["foo"] = pen.glyph()
|
||||||
|
# use the empty 'foo' glyph as a component in 'bar' with some x/y offsets
|
||||||
|
pen.addComponent("foo", (1, 0, 0, 1, -80, 50))
|
||||||
|
bar = glyphSet["bar"] = pen.glyph()
|
||||||
|
|
||||||
|
foo.recalcBounds(glyphSet)
|
||||||
|
bar.recalcBounds(glyphSet)
|
||||||
|
|
||||||
|
# we expect both the empty simple glyph and the composite referencing it
|
||||||
|
# to have empty bounding boxes (0, 0, 0, 0) no matter the component's shift
|
||||||
|
assert (foo.xMin, foo.yMin, foo.xMax, foo.yMax) == (0, 0, 0, 0)
|
||||||
|
assert (bar.xMin, bar.yMin, bar.xMax, bar.yMax) == (0, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
class GlyphComponentTest:
|
class GlyphComponentTest:
|
||||||
def test_toXML_no_transform(self):
|
def test_toXML_no_transform(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user