Skip to content

Commit 604c5a3

Browse files
committed
a
1 parent ed79f42 commit 604c5a3

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/sfnttools/tables/loca/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from io import BytesIO
22

3-
from sfnttools.error import SfntError
43
from sfnttools.table import SfntTable
54
from sfnttools.tables.head import HeadTable, IndexToLocFormat
65
from sfnttools.tables.maxp import MaxpTable
@@ -9,7 +8,7 @@
98

109
class LocaTable(SfntTable):
1110
parse_dependencies = ['maxp', 'head']
12-
dump_dependencies = ['maxp', 'head']
11+
dump_dependencies = ['head']
1312

1413
@staticmethod
1514
def parse(data: bytes, dependencies: dict[str, SfntTable]) -> 'LocaTable':
@@ -37,11 +36,13 @@ def copy(self) -> 'LocaTable':
3736
return LocaTable(self.offsets.copy())
3837

3938
def dump(self, dependencies: dict[str, SfntTable]) -> tuple[bytes, dict[str, SfntTable]]:
40-
maxp_table: MaxpTable = dependencies['maxp']
4139
head_table: HeadTable = dependencies['head']
4240

43-
if len(self.offsets) - 1 != maxp_table.num_glyphs:
44-
raise SfntError('[loca] bad offsets length')
41+
max_offset = max(self.offsets, default=0)
42+
if max_offset <= 0xFFFF * 2 and all(offset % 2 == 0 for offset in self.offsets):
43+
head_table.index_to_loc_format = IndexToLocFormat.SHORT
44+
else:
45+
head_table.index_to_loc_format = IndexToLocFormat.LONG
4546

4647
buffer = BytesIO()
4748
stream = Stream(buffer)

src/sfnttools/woff2/reader.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ def _reconstruct_glyf_and_loca_tables(self):
143143
loca_table: LocaTable = generated_tables['loca']
144144

145145
if self.verify_checksum:
146-
loca_table_data, _ = loca_table.dump({
147-
'maxp': maxp_table,
148-
'head': head_table,
149-
})
146+
updated_head_table = head_table.copy()
147+
loca_table_data, _ = loca_table.dump({'head': updated_head_table})
148+
assert head_table.index_to_loc_format == updated_head_table.index_to_loc_format
150149
glyf_checksum = calculate_checksum(glyf_table_data)
151150
loca_checksum = calculate_checksum(loca_table_data)
152151
else:

0 commit comments

Comments
 (0)