Be more thorough when working around font bugs in the loca/glyf tables

https://bugs.launchpad.net/ubuntu/+source/fonttools/+bug/223884

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@585 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
pabs3 2011-02-13 06:27:09 +00:00
parent df16db5bb8
commit d5721376f2
2 changed files with 12 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import ttProgram
import array
import numpy
from types import StringType, TupleType
import warnings
class table__g_l_y_f(DefaultTable.DefaultTable):
@ -30,10 +31,15 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
def decompile(self, data, ttFont):
loca = ttFont['loca']
last = int(loca[0])
noname = 0
self.glyphs = {}
self.glyphOrder = glyphOrder = ttFont.getGlyphOrder()
for i in range(0, len(loca)-1):
glyphName = glyphOrder[i]
try:
glyphName = glyphOrder[i]
except IndexError:
noname = noname + 1
glyphName = 'ttxautoglyph%s' % i
next = int(loca[i+1])
glyphdata = data[last:next]
if len(glyphdata) <> (next - last):
@ -44,6 +50,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
# this should become a warning:
#if len(data) > next:
# raise ttLib.TTLibError, "too much 'glyf' table data"
if noname:
warnings.warn('%s glyphs have no name' % i)
def compile(self, ttFont):
if not hasattr(self, "glyphOrder"):

View File

@ -4,6 +4,7 @@ import array
import numpy
from fontTools import ttLib
import struct
import warnings
class table__l_o_c_a(DefaultTable.DefaultTable):
@ -23,8 +24,8 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
if not longFormat:
locations = locations * 2
if len(locations) < (ttFont['maxp'].numGlyphs + 1):
raise ttLib.TTLibError, "corrupt 'loca' table, or wrong numGlyphs in 'maxp': %d %d" % (len(locations) - 1, ttFont['maxp'].numGlyphs)
self.locations = locations[:ttFont['maxp'].numGlyphs + 1]
warnings.warn("corrupt 'loca' table, or wrong numGlyphs in 'maxp': %d %d" % (len(locations) - 1, ttFont['maxp'].numGlyphs))
self.locations = locations
def compile(self, ttFont):
locations = self.locations