Add test for compile/decompile toXML/fromXML of VarComposites

This commit is contained in:
Behdad Esfahbod 2023-02-03 14:02:08 -07:00
parent fcc4f379fb
commit 07096d4af4

View File

@ -2,6 +2,7 @@ from fontTools.ttLib import TTFont
from fontTools.ttLib.scaleUpem import scale_upem from fontTools.ttLib.scaleUpem import scale_upem
import difflib import difflib
import os import os
from io import BytesIO
import shutil import shutil
import sys import sys
import tempfile import tempfile
@ -75,9 +76,24 @@ class ScaleUpemTest(unittest.TestCase):
expected_ttx_path = self.get_path("varc-ac00-ac01-500upem.ttx") expected_ttx_path = self.get_path("varc-ac00-ac01-500upem.ttx")
self.expect_ttx(font, expected_ttx_path, tables) self.expect_ttx(font, expected_ttx_path, tables)
# While here just test that we can read the ttx # While here, test a couple roundtrips
tables = [
table_tag for table_tag in tables if table_tag not in {"maxp", "hhea"}
]
xml = BytesIO()
font.saveXML(xml)
xml1 = BytesIO()
font.saveXML(xml1, tables=tables)
xml.seek(0)
font = TTFont() font = TTFont()
font.importXML(expected_ttx_path) font.importXML(xml)
ttf = BytesIO()
font.save(ttf)
ttf.seek(0)
font = TTFont(ttf)
xml2 = BytesIO()
font.saveXML(xml2, tables=tables)
assert xml1.getvalue() == xml2.getvalue()
# Scale our other varComposite font as well; without checking the expected # Scale our other varComposite font as well; without checking the expected
font = TTFont(self.get_path("varc-6868.ttf")) font = TTFont(self.get_path("varc-6868.ttf"))