diff --git a/Tests/ttLib/tables/S_V_G__test.py b/Tests/ttLib/tables/S_V_G__test.py
index 91b0f23a6..9a6e33e30 100644
--- a/Tests/ttLib/tables/S_V_G__test.py
+++ b/Tests/ttLib/tables/S_V_G__test.py
@@ -1,3 +1,5 @@
+import gzip
+import io
import struct
from fontTools.misc import etree
@@ -12,6 +14,13 @@ def dump(table, ttFont=None):
print("\n".join(getXML(table.toXML, ttFont)))
+def compress(data: bytes) -> bytes:
+ buf = io.BytesIO()
+ with gzip.GzipFile(None, "w", fileobj=buf) as gz:
+ gz.write(data)
+ return buf.getvalue()
+
+
def strip_xml_whitespace(xml_string):
def strip_or_none(text):
text = text.strip() if text else None
@@ -45,7 +54,9 @@ SVG_DOCS = [
b"""\
""",
)
@@ -65,25 +76,25 @@ OTSVG_DATA = b"".join(
b"\x00\x02" # endGlyphID (2)
b"\x00\x00\x00\x26" # svgDocOffset (2 + 12*3 == 38 == 0x26)
+ struct.pack(">L", len(SVG_DOCS[0])) # svgDocLength
- # SVGDocumentRecord[1]
+ # SVGDocumentRecord[1] (compressed)
+ b"\x00\x03" # startGlyphID (3)
b"\x00\x03" # endGlyphID (3)
+ struct.pack(">L", 0x26 + len(SVG_DOCS[0])) # svgDocOffset
- + struct.pack(">L", len(SVG_DOCS[1])) # svgDocLength
+ + struct.pack(">L", len(compress(SVG_DOCS[1]))) # svgDocLength
# SVGDocumentRecord[2]
+ b"\x00\x04" # startGlyphID (4)
b"\x00\x04" # endGlyphID (4)
b"\x00\x00\x00\x26" # svgDocOffset (38); records 0 and 2 point to same SVG doc
+ struct.pack(">L", len(SVG_DOCS[0])) # svgDocLength
]
- + SVG_DOCS
+ + [SVG_DOCS[0], compress(SVG_DOCS[1])]
)
OTSVG_TTX = [
'',
f" ",
"",
- '',
+ '',
f" ",
"",
'',
@@ -129,3 +140,19 @@ def test_round_trip_ttx(font):
table = table_S_V_G_()
table.decompile(compiled, font)
assert getXML(table.toXML, font) == OTSVG_TTX
+
+
+def test_unpack_svg_doc_as_3_tuple():
+ # test that the legacy docList as list of 3-tuples interface still works
+ # even after the new SVGDocument class with extra `compressed` attribute
+ # was added
+ table = table_S_V_G_()
+ table.decompile(OTSVG_DATA, font)
+
+ for doc, compressed in zip(table.docList, (False, True, False)):
+ assert len(doc) == 3
+ data, startGID, endGID = doc
+ assert doc.data == data
+ assert doc.startGlyphID == startGID
+ assert doc.endGlyphID == endGID
+ assert doc.compressed == compressed