Added code to fall back to the DefaultTable (and therefore to hex XML dumps) when an exception occurs during decompilation.
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@44 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
ab15e0757e
commit
f8fd4777d2
@ -41,7 +41,7 @@ Dumping 'prep' table...
|
||||
"""
|
||||
|
||||
#
|
||||
# $Id: __init__.py,v 1.9 1999-12-29 13:06:08 Just Exp $
|
||||
# $Id: __init__.py,v 1.10 2000-01-03 22:58:42 Just Exp $
|
||||
#
|
||||
|
||||
__version__ = "1.0a6"
|
||||
@ -205,7 +205,10 @@ class TTFont:
|
||||
else:
|
||||
print report
|
||||
xmltag = tag2xmltag(tag)
|
||||
writer.begintag(xmltag)
|
||||
if hasattr(table, "ERROR"):
|
||||
writer.begintag(xmltag, ERROR="decompilation error")
|
||||
else:
|
||||
writer.begintag(xmltag)
|
||||
writer.newline()
|
||||
if tag == "glyf":
|
||||
table.toXML(writer, self, progress)
|
||||
@ -289,6 +292,7 @@ class TTFont:
|
||||
return self.tables[tag]
|
||||
except KeyError:
|
||||
if self.reader is not None:
|
||||
import traceback
|
||||
if self.verbose:
|
||||
debugmsg("reading '%s' table from disk" % tag)
|
||||
data = self.reader[tag]
|
||||
@ -297,7 +301,18 @@ class TTFont:
|
||||
self.tables[tag] = table
|
||||
if self.verbose:
|
||||
debugmsg("decompiling '%s' table" % tag)
|
||||
table.decompile(data, self)
|
||||
try:
|
||||
table.decompile(data, self)
|
||||
except:
|
||||
print "An exception accurred during the decompilation of the '%s' table" % tag
|
||||
from tables.DefaultTable import DefaultTable
|
||||
import StringIO
|
||||
file = StringIO.StringIO()
|
||||
traceback.print_exc(file=file)
|
||||
table = DefaultTable(tag)
|
||||
table.ERROR = file.getvalue()
|
||||
self.tables[tag] = table
|
||||
table.decompile(data, self)
|
||||
return table
|
||||
else:
|
||||
raise KeyError, "'%s' table not found" % tag
|
||||
|
@ -15,6 +15,11 @@ class DefaultTable:
|
||||
return self.data
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
if hasattr(self, "ERROR"):
|
||||
writer.comment("An error occurred during the decompilation of this table")
|
||||
writer.newline()
|
||||
writer.comment(self.ERROR)
|
||||
writer.newline()
|
||||
writer.begintag("hexdata")
|
||||
writer.newline()
|
||||
writer.dumphex(self.compile(ttFont))
|
||||
|
@ -1,5 +1,6 @@
|
||||
from fontTools import ttLib
|
||||
from fontTools.misc.textTools import safeEval
|
||||
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
||||
import types
|
||||
import string
|
||||
import Numeric, array
|
||||
@ -131,8 +132,8 @@ class XMLApplication(xmlproc.Application):
|
||||
self.progress.set(pos / 100)
|
||||
self.lastpos = pos
|
||||
stack = self.locator.stack
|
||||
stacksize = len(stack)
|
||||
if not stacksize:
|
||||
stackSize = len(stack)
|
||||
if not stackSize:
|
||||
if name <> "ttFont":
|
||||
raise xml_parse_error, "illegal root tag: %s" % name
|
||||
sfntVersion = attrs.get("sfntVersion", "\000\001\000\000")
|
||||
@ -140,7 +141,7 @@ class XMLApplication(xmlproc.Application):
|
||||
sfntVersion = safeEval('"' + sfntVersion + '"')
|
||||
self.ttFont.sfntVersion = sfntVersion
|
||||
self.content_stack.append([])
|
||||
elif stacksize == 1:
|
||||
elif stackSize == 1:
|
||||
msg = "Parsing '%s' table..." % ttLib.xmltag2tag(name)
|
||||
if self.progress:
|
||||
self.progress.setlabel(msg)
|
||||
@ -149,17 +150,19 @@ class XMLApplication(xmlproc.Application):
|
||||
else:
|
||||
print msg
|
||||
tag = ttLib.xmltag2tag(name)
|
||||
tableclass = ttLib.getTableClass(tag)
|
||||
if tableclass is None:
|
||||
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
||||
tableclass = DefaultTable
|
||||
if attrs.has_key("ERROR"):
|
||||
tableClass = DefaultTable
|
||||
else:
|
||||
tableClass = ttLib.getTableClass(tag)
|
||||
if tableClass is None:
|
||||
tableClass = DefaultTable
|
||||
if self.ttFont.has_key(tag):
|
||||
self.current_table = self.ttFont[tag]
|
||||
else:
|
||||
self.current_table = tableclass(tag)
|
||||
self.current_table = tableClass(tag)
|
||||
self.ttFont[tag] = self.current_table
|
||||
self.content_stack.append([])
|
||||
elif stacksize == 2:
|
||||
elif stackSize == 2:
|
||||
self.content_stack.append([])
|
||||
self.root = (name, attrs, self.content_stack[-1])
|
||||
else:
|
||||
@ -174,10 +177,10 @@ class XMLApplication(xmlproc.Application):
|
||||
def handle_end_tag(self, name):
|
||||
del self.content_stack[-1]
|
||||
stack = self.locator.stack
|
||||
stacksize = len(stack)
|
||||
if stacksize == 1:
|
||||
stackSize = len(stack)
|
||||
if stackSize == 1:
|
||||
self.root = None
|
||||
elif stacksize == 2:
|
||||
elif stackSize == 2:
|
||||
self.current_table.fromXML(self.root, self.ttFont)
|
||||
self.root = None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user