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"
|
__version__ = "1.0a6"
|
||||||
@ -205,7 +205,10 @@ class TTFont:
|
|||||||
else:
|
else:
|
||||||
print report
|
print report
|
||||||
xmltag = tag2xmltag(tag)
|
xmltag = tag2xmltag(tag)
|
||||||
writer.begintag(xmltag)
|
if hasattr(table, "ERROR"):
|
||||||
|
writer.begintag(xmltag, ERROR="decompilation error")
|
||||||
|
else:
|
||||||
|
writer.begintag(xmltag)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
if tag == "glyf":
|
if tag == "glyf":
|
||||||
table.toXML(writer, self, progress)
|
table.toXML(writer, self, progress)
|
||||||
@ -289,6 +292,7 @@ class TTFont:
|
|||||||
return self.tables[tag]
|
return self.tables[tag]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if self.reader is not None:
|
if self.reader is not None:
|
||||||
|
import traceback
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
debugmsg("reading '%s' table from disk" % tag)
|
debugmsg("reading '%s' table from disk" % tag)
|
||||||
data = self.reader[tag]
|
data = self.reader[tag]
|
||||||
@ -297,7 +301,18 @@ class TTFont:
|
|||||||
self.tables[tag] = table
|
self.tables[tag] = table
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
debugmsg("decompiling '%s' table" % tag)
|
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
|
return table
|
||||||
else:
|
else:
|
||||||
raise KeyError, "'%s' table not found" % tag
|
raise KeyError, "'%s' table not found" % tag
|
||||||
|
@ -15,6 +15,11 @@ class DefaultTable:
|
|||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
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.begintag("hexdata")
|
||||||
writer.newline()
|
writer.newline()
|
||||||
writer.dumphex(self.compile(ttFont))
|
writer.dumphex(self.compile(ttFont))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from fontTools import ttLib
|
from fontTools import ttLib
|
||||||
from fontTools.misc.textTools import safeEval
|
from fontTools.misc.textTools import safeEval
|
||||||
|
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
||||||
import types
|
import types
|
||||||
import string
|
import string
|
||||||
import Numeric, array
|
import Numeric, array
|
||||||
@ -131,8 +132,8 @@ class XMLApplication(xmlproc.Application):
|
|||||||
self.progress.set(pos / 100)
|
self.progress.set(pos / 100)
|
||||||
self.lastpos = pos
|
self.lastpos = pos
|
||||||
stack = self.locator.stack
|
stack = self.locator.stack
|
||||||
stacksize = len(stack)
|
stackSize = len(stack)
|
||||||
if not stacksize:
|
if not stackSize:
|
||||||
if name <> "ttFont":
|
if name <> "ttFont":
|
||||||
raise xml_parse_error, "illegal root tag: %s" % name
|
raise xml_parse_error, "illegal root tag: %s" % name
|
||||||
sfntVersion = attrs.get("sfntVersion", "\000\001\000\000")
|
sfntVersion = attrs.get("sfntVersion", "\000\001\000\000")
|
||||||
@ -140,7 +141,7 @@ class XMLApplication(xmlproc.Application):
|
|||||||
sfntVersion = safeEval('"' + sfntVersion + '"')
|
sfntVersion = safeEval('"' + sfntVersion + '"')
|
||||||
self.ttFont.sfntVersion = sfntVersion
|
self.ttFont.sfntVersion = sfntVersion
|
||||||
self.content_stack.append([])
|
self.content_stack.append([])
|
||||||
elif stacksize == 1:
|
elif stackSize == 1:
|
||||||
msg = "Parsing '%s' table..." % ttLib.xmltag2tag(name)
|
msg = "Parsing '%s' table..." % ttLib.xmltag2tag(name)
|
||||||
if self.progress:
|
if self.progress:
|
||||||
self.progress.setlabel(msg)
|
self.progress.setlabel(msg)
|
||||||
@ -149,17 +150,19 @@ class XMLApplication(xmlproc.Application):
|
|||||||
else:
|
else:
|
||||||
print msg
|
print msg
|
||||||
tag = ttLib.xmltag2tag(name)
|
tag = ttLib.xmltag2tag(name)
|
||||||
tableclass = ttLib.getTableClass(tag)
|
if attrs.has_key("ERROR"):
|
||||||
if tableclass is None:
|
tableClass = DefaultTable
|
||||||
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
else:
|
||||||
tableclass = DefaultTable
|
tableClass = ttLib.getTableClass(tag)
|
||||||
|
if tableClass is None:
|
||||||
|
tableClass = DefaultTable
|
||||||
if self.ttFont.has_key(tag):
|
if self.ttFont.has_key(tag):
|
||||||
self.current_table = self.ttFont[tag]
|
self.current_table = self.ttFont[tag]
|
||||||
else:
|
else:
|
||||||
self.current_table = tableclass(tag)
|
self.current_table = tableClass(tag)
|
||||||
self.ttFont[tag] = self.current_table
|
self.ttFont[tag] = self.current_table
|
||||||
self.content_stack.append([])
|
self.content_stack.append([])
|
||||||
elif stacksize == 2:
|
elif stackSize == 2:
|
||||||
self.content_stack.append([])
|
self.content_stack.append([])
|
||||||
self.root = (name, attrs, self.content_stack[-1])
|
self.root = (name, attrs, self.content_stack[-1])
|
||||||
else:
|
else:
|
||||||
@ -174,10 +177,10 @@ class XMLApplication(xmlproc.Application):
|
|||||||
def handle_end_tag(self, name):
|
def handle_end_tag(self, name):
|
||||||
del self.content_stack[-1]
|
del self.content_stack[-1]
|
||||||
stack = self.locator.stack
|
stack = self.locator.stack
|
||||||
stacksize = len(stack)
|
stackSize = len(stack)
|
||||||
if stacksize == 1:
|
if stackSize == 1:
|
||||||
self.root = None
|
self.root = None
|
||||||
elif stacksize == 2:
|
elif stackSize == 2:
|
||||||
self.current_table.fromXML(self.root, self.ttFont)
|
self.current_table.fromXML(self.root, self.ttFont)
|
||||||
self.root = None
|
self.root = None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user