From 05f95f0f584d1df3439d5fa51c44b93f4313ee9d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 11:04:48 -0700 Subject: [PATCH] [otBase] Try ExtensionLookup if other offset-overflow methods fail If offset overflow happens other than between Lookup and SubTable, or within SubTable, then we don't know how to fix it currently. Now we try to put that lookup in an Extension lookup anyway, since that will isolate it and sharing with other lookups won't happen, hopefully avoiding the overflow. This is really a bandaid... What we want is the 99proof branch to be finished and replace our current packing algorithm. Fixes https://github.com/fonttools/fonttools/issues/1296 --- Lib/fontTools/ttLib/tables/otBase.py | 8 +++++++- Lib/fontTools/ttLib/tables/otTables.py | 9 +++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py index 7606572f2..04b82fef7 100644 --- a/Lib/fontTools/ttLib/tables/otBase.py +++ b/Lib/fontTools/ttLib/tables/otBase.py @@ -87,7 +87,13 @@ class BaseTTXConverter(DefaultTable): from .otTables import fixSubTableOverFlows ok = fixSubTableOverFlows(font, overflowRecord) if not ok: - raise + # Try upgrading lookup to Extension and hope + # that cross-lookup sharing not happening would + # fix overflow... + from .otTables import fixLookupOverFlows + ok = fixLookupOverFlows(font, overflowRecord) + if not ok: + raise def toXML(self, writer, font): self.table.toXML2(writer, font) diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 2e7b06ca2..d12f7e65c 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -1370,7 +1370,6 @@ def fixSubTableOverFlows(ttf, overflowRecord): """ An offset has overflowed within a sub-table. We need to divide this subtable into smaller parts. """ - ok = 0 table = ttf[overflowRecord.tableType].table lookup = table.LookupList.Lookup[overflowRecord.LookupListIndex] subIndex = overflowRecord.SubTableIndex @@ -1391,7 +1390,7 @@ def fixSubTableOverFlows(ttf, overflowRecord): newExtSubTableClass = lookupTypes[overflowRecord.tableType][extSubTable.__class__.LookupType] newExtSubTable = newExtSubTableClass() newExtSubTable.Format = extSubTable.Format - lookup.SubTable.insert(subIndex + 1, newExtSubTable) + toInsert = newExtSubTable newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType] newSubTable = newSubTableClass() @@ -1400,7 +1399,7 @@ def fixSubTableOverFlows(ttf, overflowRecord): subTableType = subtable.__class__.LookupType newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType] newSubTable = newSubTableClass() - lookup.SubTable.insert(subIndex + 1, newSubTable) + toInsert = newSubTable if hasattr(lookup, 'SubTableCount'): # may not be defined yet. lookup.SubTableCount = lookup.SubTableCount + 1 @@ -1413,9 +1412,11 @@ def fixSubTableOverFlows(ttf, overflowRecord): overflowRecord.tableType, subTableType, ) - return ok + return False ok = splitFunc(subtable, newSubTable, overflowRecord) + if ok: + lookup.SubTable.insert(subIndex + 1, toInsert) return ok # End of OverFlow logic