diff --git a/Lib/fontTools/ttLib/reorderGlyphs.py b/Lib/fontTools/ttLib/reorderGlyphs.py index 3221261f1..0e4a99fc1 100644 --- a/Lib/fontTools/ttLib/reorderGlyphs.py +++ b/Lib/fontTools/ttLib/reorderGlyphs.py @@ -258,6 +258,12 @@ def reorderGlyphs(font: ttLib.TTFont, new_glyph_order: List[str]): f"* only in old: {set(old_glyph_order) - set(new_glyph_order)}" ) + # Glyph 0 must be assigned to a .notdef glyph. + # https://learn.microsoft.com/en-us/typography/opentype/spec/recom#glyph-0-the-notdef-glyph + if ".notdef" in new_glyph_order: + new_glyph_order.remove(".notdef") + new_glyph_order.insert(0, ".notdef") + # Changing the order of glyphs in a TTFont requires that all tables that use # glyph indexes have been fully. # Cf. https://github.com/fonttools/fonttools/issues/2060 @@ -276,3 +282,11 @@ def reorderGlyphs(font: ttLib.TTFont, new_glyph_order: List[str]): reorder_key = (type(value), getattr(value, "Format", None)) for reorder in _REORDER_RULES.get(reorder_key, []): reorder.apply(font, value) + + if "CFF " in font: + cff_table = font["CFF "] + charstrings = cff_table.cff.topDictIndex[0].CharStrings.charStrings + cff_table.cff.topDictIndex[0].charset = new_glyph_order + cff_table.cff.topDictIndex[0].CharStrings.charStrings = { + k: charstrings.get(k) for k in new_glyph_order + }