Skip to content

Commit

Permalink
[outlineCompiler] Make space the 2nd glyph unless public.glyphOrder i…
Browse files Browse the repository at this point in the history
…s set

Fixes #880
  • Loading branch information
khaledhosny committed Oct 15, 2024
1 parent feeb474 commit 99f500f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Lib/ufo2ft/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ def makeOfficialGlyphOrder(font, glyphOrder=None):
If ".notdef" glyph is present in the font, force this to always be
the first glyph (at index 0).
"""
reorderSpace = False
if glyphOrder is None:
glyphOrder = getattr(font, "glyphOrder", ())
reorderSpace = True
names = set(font.keys())
order = []
if ".notdef" in names:
names.remove(".notdef")
order.append(".notdef")
if reorderSpace and "space" in names:
names.remove("space")
order.append("space")
for name in glyphOrder:
if name not in names:
continue
Expand Down
13 changes: 13 additions & 0 deletions tests/outlineCompiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,19 @@ def test_compile_strange_glyph_order(self, quadufo):
compiler.compile()
assert compiler.otf.getGlyphOrder() == EXPECTED_ORDER

def test_compile_reorder_space_glyph(self, FontClass):
"""Move space and .notdef to end of glyph ids ufo2ft always puts
.notdef first, and put space second of no explicit glyph order is set.
"""
DEAFAULT_ORDER = ["b", "a", "c", "d", "space", ".notdef", "e", "f", "g"]
EXPECTED_ORDER = [".notdef", "space", "b", "a", "c", "d", "e", "f", "g"]
ufo = FontClass()
for n in DEAFAULT_ORDER:
ufo.newGlyph(n)
compiler = OutlineTTFCompiler(ufo)
compiler.compile()
assert compiler.otf.getGlyphOrder() == EXPECTED_ORDER


class NamesTest:
@pytest.mark.parametrize(
Expand Down

0 comments on commit 99f500f

Please sign in to comment.