When lazy-loading tables, copy ValueFormat

Otherwise it may be overwritten before we use it.
This commit is contained in:
Behdad Esfahbod 2013-11-22 15:21:41 -05:00
parent fc10b20c25
commit d01c44a59b
2 changed files with 14 additions and 8 deletions

View File

@ -98,16 +98,19 @@ class OTTableReader:
self.valueFormat = valueFormat
self.cachingStats = cachingStats
def getSubReader(self, offset):
def getSubReader(self, offset, persistent=False):
offset = self.offset + offset
if self.cachingStats is not None:
try:
self.cachingStats[offset] = self.cachingStats[offset] + 1
except KeyError:
self.cachingStats[offset] = 1
valueFormat = self.valueFormat
if persistent:
valueFormat = tuple(ValueRecordFactory(v) for v in valueFormat)
subReader = self.__class__(self.data, self.tableType, offset,
self.valueFormat, self.cachingStats)
valueFormat, self.cachingStats)
return subReader
def readUShort(self):
@ -743,6 +746,9 @@ valueRecordFormatDict = _buildDict()
class ValueRecordFactory:
"""Given a format code, this object convert ValueRecords."""
def __init__(self, other=None):
self.format = other.format if other else None
def setFormat(self, valueFormat):
format = []

View File

@ -159,7 +159,9 @@ class Struct(BaseConverter):
class Table(Struct):
def read(self, reader, font, tableStack):
def read(self, reader, font, tableStack, lazy=True):
# For now, we lazy-decompile all tables. Perhaps we should
# use a more sophisticated heuristic here.
offset = reader.readUShort()
if offset == 0:
return None
@ -168,11 +170,9 @@ class Table(Struct):
print "*** Warning: offset is not 0, yet suspiciously low (%s). table: %s" \
% (offset, self.tableClass.__name__)
return None
subReader = reader.getSubReader(offset)
subReader = reader.getSubReader(offset, persistent=lazy)
table = self.tableClass()
# For now, we lazy-decompile all tables. Perhaps we should
# use a more sophisticated heuristic here.
if True:
if lazy:
# Lazy decompile
table.reader = subReader
table.font = font