Skip to content

Commit

Permalink
[>64k:layout] Add GSUB/GPOS version 2.0
Browse files Browse the repository at this point in the history
To fix offset overflows of LookupList itself.

Implements harfbuzz/boring-expansion-spec#58
  • Loading branch information
behdad committed Jul 12, 2022
1 parent 19f5cb7 commit 2089239
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Lib/fontTools/merge/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,6 @@ def layoutPostMerge(font):

beyond64k = len(font.getGlyphOrder()) > 65535
if beyond64k:
t.table.LookupList.upgrade64k(font.getReverseGlyphMap())
t.table.upgrade64k(font.getReverseGlyphMap())

# TODO FeatureParams nameIDs
10 changes: 9 additions & 1 deletion Lib/fontTools/merge/upgrade64k.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ def upgrade64k(self, reverseGlyphMap):
if not st: continue
st.upgrade64k(reverseGlyphMap)

@add_method(otTables.LookupList)
@add_method(otTables.LookupList32)
def upgrade64k(self, reverseGlyphMap):
for l in self.Lookup:
if not l: continue
l.upgrade64k(reverseGlyphMap)

@add_method(otTables.GSUB,
otTables.GPOS)
def upgrade64k(self, reverseGlyphMap):
if self.Version < 0x00020000:
self.LookupList32 = otTables.LookupList32()
self.LookupList32.Lookup = self.LookupList.Lookup
self.Version = 0x00020000
self.LookupList32.upgrade64k(reverseGlyphMap)
6 changes: 3 additions & 3 deletions Lib/fontTools/ttLib/tables/otBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ def getOverflowErrorRecord(self, item):
else: # who knows how far below the SubTable level we are! Climb back up to the nearest subtable.
itemName = ".".join([self.name, itemName])
p1 = self.parent
while p1 and p1.name not in ['ExtSubTable', 'SubTable']:
itemName = ".".join([p1.name, itemName])
while p1 and getattr(p1, 'name', None) not in ['ExtSubTable', 'SubTable']:
itemName = ".".join([getattr(p1, 'name', '<none>'), itemName])
p1 = p1.parent
if p1:
if p1.name == 'ExtSubTable':
if getattr(p1, 'name', None) == 'ExtSubTable':
LookupListIndex = p1.parent.parent.repeatIndex
SubTableIndex = p1.parent.repeatIndex
else:
Expand Down
2 changes: 0 additions & 2 deletions Lib/fontTools/ttLib/tables/otConverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,9 @@ class Version(SimpleValue):
staticSize = 4
def read(self, reader, font, tableDict):
value = reader.readLong()
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
return value
def write(self, writer, font, tableDict, value, repeatIndex=None):
value = fi2ve(value)
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
writer.writeLong(value)
@staticmethod
def fromString(value):
Expand Down
11 changes: 9 additions & 2 deletions Lib/fontTools/ttLib/tables/otData.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
('Offset', 'Lookup', 'LookupCount', 0, 'Array of offsets to Lookup tables-from beginning of LookupList -zero based (first lookup is Lookup index = 0)'),
]),

('LookupList32', [
('uint16', 'LookupCount', None, None, 'Number of lookups in this table'),
('Offset32', 'Lookup', 'LookupCount', 0, 'Array of offsets to Lookup tables-from beginning of LookupList -zero based (first lookup is Lookup index = 0)'),
]),

('Lookup', [
('uint16', 'LookupType', None, None, 'Different enumerations for GSUB and GPOS'),
('LookupFlag', 'LookupFlag', None, None, 'Lookup qualifiers'),
Expand Down Expand Up @@ -180,7 +185,8 @@
('Version', 'Version', None, None, 'Version of the GPOS table- 0x00010000 or 0x00010001'),
('Offset', 'ScriptList', None, None, 'Offset to ScriptList table-from beginning of GPOS table'),
('Offset', 'FeatureList', None, None, 'Offset to FeatureList table-from beginning of GPOS table'),
('Offset', 'LookupList', None, None, 'Offset to LookupList table-from beginning of GPOS table'),
('Offset', 'LookupList', None, 'Version < 0x00020000', 'Offset to LookupList table-from beginning of GPOS table'),
('Offset32', 'LookupList32', None, 'Version >= 0x00020000', 'Offset to LookupList table-from beginning of GPOS table'),
('LOffset', 'FeatureVariations', None, 'Version >= 0x00010001', 'Offset to FeatureVariations table-from beginning of GPOS table'),
]),

Expand Down Expand Up @@ -620,7 +626,8 @@
('Version', 'Version', None, None, 'Version of the GSUB table- 0x00010000 or 0x00010001'),
('Offset', 'ScriptList', None, None, 'Offset to ScriptList table-from beginning of GSUB table'),
('Offset', 'FeatureList', None, None, 'Offset to FeatureList table-from beginning of GSUB table'),
('Offset', 'LookupList', None, None, 'Offset to LookupList table-from beginning of GSUB table'),
('Offset', 'LookupList', None, 'Version < 0x00020000', 'Offset to LookupList table-from beginning of GSUB table'),
('Offset32', 'LookupList32', None, 'Version >= 0x00020000', 'Offset to LookupList table-from beginning of GSUB table'),
('LOffset', 'FeatureVariations', None, 'Version >= 0x00010001', 'Offset to FeatureVariations table-from beginning of GSUB table'),
]),

Expand Down

0 comments on commit 2089239

Please sign in to comment.