don't allow duplicate glyph names when building names from cmap/agl

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@129 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
Just 2001-02-23 21:58:57 +00:00
parent ae180248fd
commit a556f51db5

View File

@ -42,7 +42,7 @@ Dumping 'prep' table...
""" """
# #
# $Id: __init__.py,v 1.16 2000-10-02 07:51:42 Just Exp $ # $Id: __init__.py,v 1.17 2001-02-23 21:58:57 Just Exp $
# #
__version__ = "1.0a6" __version__ = "1.0a6"
@ -386,16 +386,25 @@ class TTFont:
reversecmap = {} reversecmap = {}
for unicode, name in cmap.items(): for unicode, name in cmap.items():
reversecmap[name] = unicode reversecmap[name] = unicode
allNames = {}
for i in range(numGlyphs): for i in range(numGlyphs):
tempName = glyphOrder[i] tempName = glyphOrder[i]
if reversecmap.has_key(tempName): if reversecmap.has_key(tempName):
unicode = reversecmap[tempName] unicode = reversecmap[tempName]
if agl.UV2AGL.has_key(unicode): if agl.UV2AGL.has_key(unicode):
# get name from the Adobe Glyph List # get name from the Adobe Glyph List
glyphOrder[i] = agl.UV2AGL[unicode] glyphName = agl.UV2AGL[unicode]
else: else:
# create uni<CODE> name # create uni<CODE> name
glyphOrder[i] = "uni" + string.upper(string.zfill(hex(unicode)[2:], 4)) glyphName = "uni" + string.upper(string.zfill(
hex(unicode)[2:], 4))
tempName = glyphName
n = 1
while allNames.has_key(tempName):
tempName = glyphName + "#" + `n`
n = n + 1
glyphOrder[i] = tempName
allNames[tempName] = 1
# Delete the cmap table from the cache, so it can be # Delete the cmap table from the cache, so it can be
# parsed again with the right names. # parsed again with the right names.
del self.tables['cmap'] del self.tables['cmap']