diff --git a/Lib/fontTools/cffLib/__init__.py b/Lib/fontTools/cffLib/__init__.py index 84e616fe4..d67bc13e8 100644 --- a/Lib/fontTools/cffLib/__init__.py +++ b/Lib/fontTools/cffLib/__init__.py @@ -1319,6 +1319,20 @@ class CharsetConverter(SimpleConverter): raise NotImplementedError assert len(charset) == numGlyphs log.log(DEBUG, " charset end at %s", file.tell()) + # make sure glyph names are unique + allNames = {} + newCharset = [] + for glyphName in charset: + if glyphName in allNames: + # make up a new glyphName that's unique + n = allNames[glyphName] + while (glyphName + "#" + str(n)) in allNames: + n += 1 + allNames[glyphName] = n + 1 + glyphName = glyphName + "#" + str(n) + allNames[glyphName] = 1 + newCharset.append(glyphName) + charset = newCharset else: # offset == 0 -> no charset data. if isCID or "CharStrings" not in parent.rawDict: # We get here only when processing fontDicts from the FDArray of diff --git a/Tests/cffLib/cffLib_test.py b/Tests/cffLib/cffLib_test.py index 339458dc9..7a6e92169 100644 --- a/Tests/cffLib/cffLib_test.py +++ b/Tests/cffLib/cffLib_test.py @@ -92,6 +92,21 @@ class CffLibTest(DataFilesHandler): self.assertEqual(topDict2.FDSelect.format, 4) self.assertEqual(topDict2.FDSelect.gidArray, [0, 0, 1]) + def test_unique_glyph_names(self): + font_path = self.getpath('LinLibertine_RBI.otf') + font = TTFont(font_path, recalcBBoxes=False, recalcTimestamp=False) + + glyphOrder = font.getGlyphOrder() + self.assertEqual(len(glyphOrder), len(set(glyphOrder))) + + self.temp_dir() + save_path = os.path.join(self.tempdir, 'TestOTF.otf') + font.save(save_path) + + font2 = TTFont(save_path) + glyphOrder = font2.getGlyphOrder() + self.assertEqual(len(glyphOrder), len(set(glyphOrder))) + if __name__ == "__main__": sys.exit(unittest.main()) diff --git a/Tests/cffLib/data/LinLibertine_RBI.otf b/Tests/cffLib/data/LinLibertine_RBI.otf new file mode 100755 index 000000000..c1a4ff72a Binary files /dev/null and b/Tests/cffLib/data/LinLibertine_RBI.otf differ