From 99f500ff9741e1908b226f6edbf010a01aa84fa4 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sat, 12 Oct 2024 17:56:53 +0300 Subject: [PATCH] [outlineCompiler] Make space the 2nd glyph unless public.glyphOrder is set Fixes https://github.com/googlefonts/ufo2ft/issues/880 --- Lib/ufo2ft/util.py | 5 +++++ tests/outlineCompiler_test.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Lib/ufo2ft/util.py b/Lib/ufo2ft/util.py index 17d4eff1..842d2b9d 100644 --- a/Lib/ufo2ft/util.py +++ b/Lib/ufo2ft/util.py @@ -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 diff --git a/tests/outlineCompiler_test.py b/tests/outlineCompiler_test.py index 5755ce5d..28dad3bf 100644 --- a/tests/outlineCompiler_test.py +++ b/tests/outlineCompiler_test.py @@ -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(