From 6ac255593a6ff4b282ca14c17f46cbf1d187fcbe 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 | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) 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..db3c0d7f 100644 --- a/tests/outlineCompiler_test.py +++ b/tests/outlineCompiler_test.py @@ -737,16 +737,16 @@ def test_compile_tweaked_glyph_order(self, quadufo): def test_compile_strange_glyph_order(self, quadufo): """Move space and .notdef to end of glyph ids - ufo2ft always puts .notdef first. + ufo2ft always puts .notdef and space first. """ NEW_ORDER = ["b", "a", "c", "d", "space", ".notdef"] EXPECTED_ORDER = [ ".notdef", + "space", "b", "a", "c", "d", - "space", "e", "f", "g", @@ -924,11 +924,11 @@ def test_duplicate_glyph_names(self, testufo): result = compileTTF(testufo, useProductionNames=True).getGlyphOrder() - assert result[1] == "ab" - assert result[2] == "ab.1" - assert result[3] == "ab.2" - assert result[4] == "ab.3" - assert result[5] == "ab.4" + assert result[2] == "ab" + assert result[3] == "ab.1" + assert result[4] == "ab.2" + assert result[5] == "ab.3" + assert result[6] == "ab.4" def test_too_long_production_name(self, testufo): name = "_".join(("a",) * 16)