diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py index f75284504..0e1e1f7aa 100644 --- a/Lib/fontTools/ttLib/tables/otBase.py +++ b/Lib/fontTools/ttLib/tables/otBase.py @@ -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 = [] diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py index dfd3b300c..544a7eefb 100644 --- a/Lib/fontTools/ttLib/tables/otConverters.py +++ b/Lib/fontTools/ttLib/tables/otConverters.py @@ -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