diff --git a/Lib/fontTools/ttLib/ttFont.py b/Lib/fontTools/ttLib/ttFont.py index dbfcb6e89..e6fe9a673 100644 --- a/Lib/fontTools/ttLib/ttFont.py +++ b/Lib/fontTools/ttLib/ttFont.py @@ -487,6 +487,13 @@ class TTFont(object): # in combination with the Adobe Glyph List (AGL). # self._getGlyphNamesFromCmap() + elif len(glyphOrder) < self['maxp'].numGlyphs: + # + # Not enough names found in the 'post' table. + # Can happen when 'post' format 1 is improperly used on a font that + # has more than 258 glyphs (the lenght of 'standardGlyphOrder'). + # + self._getGlyphNamesFromCmap() else: self.glyphOrder = glyphOrder else: diff --git a/Tests/ttLib/data/bogus_post_format_1.ttf b/Tests/ttLib/data/bogus_post_format_1.ttf new file mode 100644 index 000000000..62b80213c Binary files /dev/null and b/Tests/ttLib/data/bogus_post_format_1.ttf differ diff --git a/Tests/ttLib/ttFont_test.py b/Tests/ttLib/ttFont_test.py index ad0810612..3cf7075e3 100644 --- a/Tests/ttLib/ttFont_test.py +++ b/Tests/ttLib/ttFont_test.py @@ -4,6 +4,7 @@ import re import random from fontTools.feaLib.builder import addOpenTypeFeaturesFromString from fontTools.ttLib import TTFont, TTLibError, newTable, registerCustomTableClass, unregisterCustomTableClass +from fontTools.ttLib.standardGlyphOrder import standardGlyphOrder from fontTools.ttLib.tables.DefaultTable import DefaultTable from fontTools.ttLib.tables._c_m_a_p import CmapSubtable import pytest @@ -143,6 +144,13 @@ def test_setGlyphOrder_also_updates_glyf_glyphOrder(): assert font["glyf"].glyphOrder == new_order +def test_getGlyphOrder_not_true_post_format_1(): + # https://github.com/fonttools/fonttools/issues/2736 + font = TTFont(os.path.join(DATA_DIR, "bogus_post_format_1.ttf")) + hmtx = font["hmtx"] + assert len(hmtx.metrics) > len(standardGlyphOrder) + + @pytest.mark.parametrize("lazy", [None, True, False]) def test_ensureDecompiled(lazy): # test that no matter the lazy value, ensureDecompiled decompiles all tables