From 0b63b28615933a1332ea55ce4f5daedf5269192c Mon Sep 17 00:00:00 2001 From: jvr Date: Mon, 13 May 2002 11:26:38 +0000 Subject: [PATCH] don't get glyph names from CFF it it's a CID-keyed font; invent glyph name on the spot if glyphID is too high (dubious change..). git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@224 4cde692c-a291-49d1-8350-778aa11640f8 --- Lib/fontTools/ttLib/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py index de3c8f876..31ff2c30c 100644 --- a/Lib/fontTools/ttLib/__init__.py +++ b/Lib/fontTools/ttLib/__init__.py @@ -42,7 +42,7 @@ Dumping 'prep' table... """ # -# $Id: __init__.py,v 1.25 2002-05-12 17:14:50 jvr Exp $ +# $Id: __init__.py,v 1.26 2002-05-13 11:26:38 jvr Exp $ # import os @@ -335,8 +335,12 @@ class TTFont: except AttributeError: pass if self.has_key('CFF '): - # CFF OpenType font - self.glyphOrder = self['CFF '].getGlyphOrder() + cff = self['CFF '] + if cff.haveGlyphNames(): + self.glyphOrder = cff.getGlyphOrder() + else: + # CID-keyed font, use cmap + self._getGlyphNamesFromCmap() elif self.has_key('post'): # TrueType font glyphOrder = self['post'].getGlyphOrder() @@ -443,7 +447,12 @@ class TTFont: return textTools.caselessSort(self.getGlyphOrder()) def getGlyphName(self, glyphID): - return self.getGlyphOrder()[glyphID] + try: + return self.getGlyphOrder()[glyphID] + except IndexError: + # XXX The ??.W8.otf font that ships with OSX uses higher glyphIDs in + # the cmap table than there are glyphs. I don't think it's legal... + return "glyph%.5d" % glyphID def getGlyphID(self, glyphName): if not hasattr(self, "_reverseGlyphOrderDict"):