Skip to content

Commit

Permalink
Fix mock glyph removal now that check no longer mutates TTFont
Browse files Browse the repository at this point in the history
The previous approach relied on the `glyphOrder` property being
populated as a side-effect of the "unreachable-glyphs" check, but this
no longer happens now that the accidental mutation in the check has been
removed.

This commit avoids using the internal property entirely by using the
`setGlyphOrder()` function, and ensuring that the font is fully loaded
prior to this to avoid the glyph being referenced during a later load
after it has already been removed from the order.

If this causes issues again, it may be more resilient for us to use
fontTools' subsetter library to implement this pytest.

(PR #4835)
  • Loading branch information
Hoolean authored and felipesanches committed Sep 17, 2024
1 parent 315cfda commit b35e3ab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/test_checks_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,15 +1053,20 @@ def test_check_unreachable_glyphs():
assert glyph not in message

ttFont = TTFont(TEST_FILE("notosansmath/NotoSansMath-Regular.ttf"))
ttFont.ensureDecompiled() # (required for mock glyph removal below)
glyph_order = ttFont.getGlyphOrder()

# upWhiteMediumTriangle is used as a component in circledTriangle,
# since CFF does not have composites it became unused.
# So that is a build tooling issue.
message = assert_results_contain(check(ttFont), WARN, "unreachable-glyphs")
assert "upWhiteMediumTriangle" in message
assert "upWhiteMediumTriangle" in ttFont.glyphOrder
assert "upWhiteMediumTriangle" in glyph_order

# Other than that problem, no other glyphs are unreachable:
ttFont.glyphOrder.remove("upWhiteMediumTriangle")
# Other than that problem, no other glyphs are unreachable;
# Remove the glyph and then try again.
glyph_order.remove("upWhiteMediumTriangle")
ttFont.setGlyphOrder(glyph_order)
assert "upWhiteMediumTriangle" not in ttFont.glyphOrder
assert_PASS(check(ttFont))

Expand Down

0 comments on commit b35e3ab

Please sign in to comment.