diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index bff0d92c3..683912be9 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -1211,6 +1211,9 @@ class Glyph(object): g.recalcBounds(glyfTable, boundsDone=boundsDone) if boundsDone is not None: 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 bounds = updateBounds(bounds, (g.xMin + x, g.yMin + y)) diff --git a/Tests/ttLib/tables/_g_l_y_f_test.py b/Tests/ttLib/tables/_g_l_y_f_test.py index ce2e0e575..39f48b266 100644 --- a/Tests/ttLib/tables/_g_l_y_f_test.py +++ b/Tests/ttLib/tables/_g_l_y_f_test.py @@ -562,6 +562,23 @@ class GlyphTest: assert glyphSet["percent"].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: def test_toXML_no_transform(self):