Merge pull request #2544 from fonttools/set-glyf-glyph-order

Also update glyf's glyphOrder when calling TTFont.setGlyphOrder()
This commit is contained in:
Cosimo Lupo 2022-03-14 17:11:57 +00:00 committed by GitHub
commit 71a5bf1b51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -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."""

View File

@ -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