[merge] Handle duplicate glyph names better

Instead of appending font index to all glyph names and still potentially
have duplicates, use similar code like we use and “post” and “CFF”
tables to handle duplicate glyph names.
This commit is contained in:
Khaled Hosny 2019-09-19 00:31:29 +02:00
parent 7cb8e01eda
commit af42fc24b7

View File

@ -1012,16 +1012,18 @@ class Merger(object):
def _mergeGlyphOrders(self, glyphOrders): def _mergeGlyphOrders(self, glyphOrders):
"""Modifies passed-in glyphOrders to reflect new glyph names. """Modifies passed-in glyphOrders to reflect new glyph names.
Returns glyphOrder for the merged font.""" Returns glyphOrder for the merged font."""
# Simply append font index to the glyph name for now. mega = {}
# TODO Even this simplistic numbering can result in conflicts. for glyphOrder in glyphOrders:
# But then again, we have to improve this soon anyway.
mega = []
for n,glyphOrder in enumerate(glyphOrders):
for i,glyphName in enumerate(glyphOrder): for i,glyphName in enumerate(glyphOrder):
glyphName += "#" + repr(n) if glyphName in mega:
glyphOrder[i] = glyphName n = mega[glyphName]
mega.append(glyphName) while (glyphName + "#" + repr(n)) in mega:
return mega n += 1
mega[glyphName] = n
glyphName += "#" + repr(n)
glyphOrder[i] = glyphName
mega[glyphName] = 1
return list(mega.keys())
def mergeObjects(self, returnTable, logic, tables): def mergeObjects(self, returnTable, logic, tables):
# Right now we don't use self at all. Will use in the future # Right now we don't use self at all. Will use in the future