The code that is being removed is untested and does not seem to make
fixing an overflow any easier. The fixer code just needs to know
which subtable caused the overflow and does not care about the item
within. As such, no point in trying to find a "right" item.
In fact, leaving item as is, is more useful in debugging overflows
as it reflects which item's offset actually overflowed.
Part of fixing https://github.com/behdad/fonttools/issues/537
otherwise `not NotImplemented` (always False) is returned from __ne__ when `type(self) != type(other)`, leading to illogic results like:
>>> from fontTools.ttLib.tables.DefaultTable import DefaultTable
>>> t = DefaultTable('test')
>>> t == 0
False
>>> t != 0
False
The latter of course should return True.
Apparently string slices are not as smart as I was hoping for.
Slicing a looong (say, 1MB) string and holding onto it is not a
good idea if done thousands of times. So, do fewer slicings and
decompile subtables immediately instead of holding onto data.
This makes me want to rethink the kind of data structures we use
for lazy processing.
Fixes https://github.com/behdad/fonttools/issues/317
self.data is usually set by decompileHeader as "the data after the header"; while here
it also included `headerdata`. This produced corrupt data if the compile method was called
again, as the header data is added again to self.data.
Moreover, in none of the subtable classes' `compile` methods, the re-compiled data is
stored in self.data, so we shall not do that for format 14 either.
Fixes#389
Ie, now we get:
...
assert 0 <= value < 0x10000, value
AssertionError: (None, 'LookupListIndex', 'SubstLookupRecord[0]', 'ChainContextSubst[1]', 'Lookup[3]', 'LookupList')
The common stacktrace like this:
File "fonttools/Lib/fontTools/ttLib/__init__.py", line 202, in save
self._writeTable(tag, writer, done)
File "fonttools/Lib/fontTools/ttLib/__init__.py", line 631, in _writeTable
tabledata = self.getTableData(tag)
File "fonttools/Lib/fontTools/ttLib/__init__.py", line 644, in getTableData
return self.tables[tag].compile(self)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 86, in compile
self.table.compile(writer, font)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 681, in compile
conv.write(writer, font, table, value)
File "fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 354, in write
value.compile(subWriter, font)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 661, in compile
conv.write(writer, font, table, value, i)
File "fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 354, in write
value.compile(subWriter, font)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 661, in compile
conv.write(writer, font, table, value, i)
File "fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 354, in write
value.compile(subWriter, font)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 661, in compile
conv.write(writer, font, table, value, i)
File "fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 277, in write
value.compile(writer, font)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 681, in compile
conv.write(writer, font, table, value)
File "fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 175, in write
writer.writeUShort(value)
File "fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 457, in writeUShort
assert 0 <= value < 0x10000, value
AssertionError: None
now has this as the last line:
AssertionError: (None, 'LookupListIndex', 'SubstLookupRecord', 'ChainContextSubst', 'Lookup', 'LookupList')
which means a value of None was tried for writing a LookupListIndex from a ChainContextSubset...
It's a hack, but a very useful one.