From aaed718e41941bd2a665e5788265992a27936dbb Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 14 Nov 2023 16:30:26 +0000 Subject: [PATCH 1/2] [glyf_test] Test that composite referencing empty glyph also gets zero bounds Add reproducer for possible regression in Glyph.recalcBounds introduced with https://github.com/fonttools/fonttools/pull/3301 --- Tests/ttLib/tables/_g_l_y_f_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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): From 4610bf39e39ddfac2e35411d7ae8030b1e6ea405 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 14 Nov 2023 16:47:20 +0000 Subject: [PATCH 2/2] [glyf] skip empty components when computing bounds of composite glyphs --- Lib/fontTools/ttLib/tables/_g_l_y_f.py | 3 +++ 1 file changed, 3 insertions(+) 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))