diff --git a/Lib/fontTools/ttLib/ttFont.py b/Lib/fontTools/ttLib/ttFont.py index 9948d4e2f..692f99ac8 100644 --- a/Lib/fontTools/ttLib/ttFont.py +++ b/Lib/fontTools/ttLib/ttFont.py @@ -451,6 +451,8 @@ class TTFont(object): self.glyphOrder = glyphOrder if hasattr(self, '_reverseGlyphOrderDict'): del self._reverseGlyphOrderDict + if self.isLoaded("glyf"): + self["glyf"].setGlyphOrder(glyphOrder) def getGlyphOrder(self): """Returns a list of glyph names ordered by their position in the font.""" diff --git a/Tests/ttLib/ttFont_test.py b/Tests/ttLib/ttFont_test.py index 5e40e2658..d40832728 100644 --- a/Tests/ttLib/ttFont_test.py +++ b/Tests/ttLib/ttFont_test.py @@ -1,6 +1,7 @@ import io import os import re +import random from fontTools.ttLib import TTFont, newTable, registerCustomTableClass, unregisterCustomTableClass from fontTools.ttLib.tables.DefaultTable import DefaultTable @@ -118,3 +119,21 @@ def test_virtualGlyphId(): font.saveXML(out) outxml = normalize_TTX(out.getvalue()).splitlines() assert xml == outxml + + +def test_setGlyphOrder_also_updates_glyf_glyphOrder(): + # https://github.com/fonttools/fonttools/issues/2060#issuecomment-1063932428 + font = TTFont() + font.importXML(os.path.join(DATA_DIR, "TestTTF-Regular.ttx")) + current_order = font.getGlyphOrder() + + assert current_order == font["glyf"].glyphOrder + + new_order = list(current_order) + while new_order == current_order: + random.shuffle(new_order) + + font.setGlyphOrder(new_order) + + assert font.getGlyphOrder() == new_order + assert font["glyf"].glyphOrder == new_order