diff --git a/Lib/glyphsLib/glyphdata.py b/Lib/glyphsLib/glyphdata.py index 48f9d069d..508e0187d 100644 --- a/Lib/glyphsLib/glyphdata.py +++ b/Lib/glyphsLib/glyphdata.py @@ -295,16 +295,29 @@ def _translate_category(glyph_name, unicode_category): def _split_ligature_glyph_name(name, data): + # Split name to ligature parts parts = name.split("_") - if len(parts) > 1 and "-" in parts[-1]: - script = parts[-1].rsplit("-", 1)[-1] - for i, part in enumerate(parts): - new = f"{part}-{script}" - if "-" in part: - continue - if _lookup_attributes(part, data) and not _lookup_attributes(new, data): - continue - parts[i] = new + + # If the last part has a script suffix, strip it and re-split the name. + if "-" in parts[-1]: + base, script = name.rsplit("-", 1) + parts = base.split("_") + + # If there is more than one part, try adding the script suffix to each + # part, if this results in a known glyph name, use it as the part name. + if len(parts) > 1: + for i, part in enumerate(parts): + new = f"{part}-{script}" + # If the part already has a script suffix, keep it unchanged. + if "-" in part: + continue + # If the non suffixed name exists and the suffixed name does + # not exist, keep the part name unchanged. + if _lookup_attributes(part, data) and not _lookup_attributes(new, data): + continue + parts[i] = new + else: + parts = name.split("_") return parts diff --git a/tests/glyphdata_test.py b/tests/glyphdata_test.py index 6c669e459..7a26a2b26 100644 --- a/tests/glyphdata_test.py +++ b/tests/glyphdata_test.py @@ -315,14 +315,14 @@ def test_glyphdata_no_duplicates(self): "ma_uMatra-tamil": "uni0BAE0BC1", "ma_uuMatra-tamil": "uni0BAE0BC2", "mo-khmer.below.ro": "uni17D21798.ro", - "moMa_underscore-thai": "uni0E21_uni005F", + "moMa_underscore-thai": "uni0E21005F", # uni0E21_uni005F "na_iMatra-tamil": "uni0BA80BBF", "na_uMatra-tamil": "uni0BA80BC1", "na_uuMatra-tamil": "uni0BA80BC2", "ng_ya-deva": "uni0919094D092F", "nga_uMatra-tamil": "uni0B990BC1", "nga_uuMatra-tamil": "uni0B990BC2", - "ngoNgu_underscore-thai": "uni0E07_uni005F", + "ngoNgu_underscore-thai": "uni0E07005F", # uni0E07_uni005F "niggahita_maiCatawa-lao": "uni0ECD0ECB", "niggahita_maiCatawa-lao.right": "uni0ECD0ECB.right", "niggahita_maiEk-lao": "uni0ECD0EC8", @@ -345,7 +345,7 @@ def test_glyphdata_no_duplicates(self): "nnna_uuMatra-tamil": "uni0BA90BC2", "nno-khmer.below.narrow1": "uni17D2178E.narrow1", "nno-khmer.below.narrow2": "uni17D2178E.narrow2", - "noNu_underscore-thai": "uni0E19_uni005F", + "noNu_underscore-thai": "uni0E19005F", # uni0E19_uni005F "nya_iMatra-tamil": "uni0B9E0BBF", "nya_uMatra-tamil": "uni0B9E0BC1", "nya_uuMatra-tamil": "uni0B9E0BC2", @@ -397,7 +397,7 @@ def test_glyphdata_no_duplicates(self): "va_uuMatra-tamil": "uni0BB50BC2", "ya_uMatra-tamil": "uni0BAF0BC1", "ya_uuMatra-tamil": "uni0BAF0BC2", - "yoYing_underscore-thai": "uni0E0D_uni005F", + "yoYing_underscore-thai": "uni0E0D005F", # uni0E0D_uni005F }