+
Skip to content

[ttLib] Ignore component bounds if empty #3799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/fontTools/ttLib/tables/_g_l_y_f.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ def tryRecalcBoundsComposite(self, glyfTable, *, boundsDone=None):
if boundsDone is not None:
boundsDone.add(glyphName)
# empty components shouldn't update the bounds of the parent glyph
if g.numberOfContours == 0:
if g.yMin == g.yMax and g.xMin == g.xMax:
continue

x, y = compo.x, compo.y
Expand Down
64 changes: 61 additions & 3 deletions Tests/ttLib/tables/_g_l_y_f_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,17 +567,75 @@ def test_recalcBounds_empty_components(self):
pen = TTGlyphPen(glyphSet)
# empty simple glyph
foo = glyphSet["foo"] = pen.glyph()

pen.moveTo((5, 5))
pen.lineTo((10, 10))
pen.lineTo((10, 5))
pen.lineTo((5, 5))
pen.closePath()

# non-empty simple glyph
doo = glyphSet["doo"] = pen.glyph()

pen = TTGlyphPen(glyphSet)
# use the empty 'foo' glyph as a component in 'bar' with some x/y offsets
pen.addComponent("foo", (1, 0, 0, 1, -80, 50))
# and use the non-empty 'doo' glyph at origin
pen.addComponent("doo", (1, 0, 0, 1, 0, 0))
bar = glyphSet["bar"] = pen.glyph()

foo.recalcBounds(glyphSet)
doo.recalcBounds(glyphSet)
bar.recalcBounds(glyphSet)

assert (foo.xMin, foo.yMin, foo.xMax, foo.yMax) == (0, 0, 0, 0)
assert (doo.xMin, doo.yMin, doo.xMax, doo.yMax) == (5, 5, 10, 10)
# the composite should have bounds identical to 'doo';
# the empty foo glyph should do nothing
assert (bar.xMin, bar.yMin, bar.xMax, bar.yMax) == (5, 5, 10, 10)

def test_recalcBounds_empty_components_nested(self):
# this differs from the above in an important way: it has a 'foofoo'
# glyph, which is a composite glyph, where none of its components
# have any contours; we want to check that when this glyph is referenced
# it is also treated as not contributing to the parent's bounds.

glyphSet = {}
pen = TTGlyphPen(glyphSet)
# empty simple glyph
foo = glyphSet["foo"] = pen.glyph()

pen.addComponent("foo", (1, 0, 0, 1, 20, 20))
foofoo = glyphSet["foofoo"] = pen.glyph()

pen = TTGlyphPen(glyphSet)

pen.moveTo((5, 5))
pen.lineTo((10, 10))
pen.lineTo((10, 5))
pen.lineTo((5, 5))
pen.closePath()

# non-empty simple glyph
doo = glyphSet["doo"] = pen.glyph()

pen = TTGlyphPen(glyphSet)
# use the empty 'foo' glyph as a component in 'bar' with some x/y offsets
pen.addComponent("foofoo", (1, 0, 0, 1, 0, 0))
# and use the non-empty 'doo' glyph at origin
pen.addComponent("doo", (1, 0, 0, 1, 0, 0))
bar = glyphSet["bar"] = pen.glyph()

foo.recalcBounds(glyphSet)
foofoo.recalcBounds(glyphSet)
doo.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)
assert (doo.xMin, doo.yMin, doo.xMax, doo.yMax) == (5, 5, 10, 10)
# the composite should have bounds identical to 'doo';
# the empty foo glyph should do nothing
assert (bar.xMin, bar.yMin, bar.xMax, bar.yMax) == (5, 5, 10, 10)


class GlyphComponentTest:
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载