Move VarComposite roundtrip tests to glyf_test

This commit is contained in:
Behdad Esfahbod 2023-02-06 11:08:53 -07:00
parent 4c201b9a42
commit b7deb93647
2 changed files with 46 additions and 28 deletions

View File

@ -2,7 +2,6 @@ from fontTools.ttLib import TTFont
from fontTools.ttLib.scaleUpem import scale_upem
import difflib
import os
from io import BytesIO
import shutil
import sys
import tempfile
@ -76,35 +75,9 @@ class ScaleUpemTest(unittest.TestCase):
expected_ttx_path = self.get_path("varc-ac00-ac01-500upem.ttx")
self.expect_ttx(font, expected_ttx_path, tables)
# 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.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
font = TTFont(self.get_path("varc-6868.ttf"))
scale_upem(font, 500)
ttf = BytesIO()
font.save(ttf)
xml = BytesIO()
font.saveXML(xml)
xml.seek(0)
font = TTFont()
font.importXML(xml)
def test_scale_upem_otf(self):

View File

@ -18,7 +18,7 @@ from fontTools.ttLib.tables._g_l_y_f import (
from fontTools.ttLib.tables import ttProgram
import sys
import array
from io import StringIO
from io import StringIO, BytesIO
import itertools
import pytest
import re
@ -678,6 +678,51 @@ class GlyphComponentTest:
glyf.glyphs["uni6868"].trim()
def test_varComposite_basic(self):
font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-ac00-ac01.ttf")
font = TTFont(font_path)
tables = [
table_tag
for table_tag in font.keys()
if table_tag not in {"head", "maxp", "hhea"}
]
xml = StringIO()
font.saveXML(xml)
xml1 = StringIO()
font.saveXML(xml1, tables=tables)
xml.seek(0)
font = TTFont()
font.importXML(xml)
ttf = BytesIO()
font.save(ttf)
ttf.seek(0)
font = TTFont(ttf)
xml2 = StringIO()
font.saveXML(xml2, tables=tables)
assert xml1.getvalue() == xml2.getvalue()
font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-6868.ttf")
font = TTFont(font_path)
tables = [
table_tag
for table_tag in font.keys()
if table_tag not in {"head", "maxp", "hhea", "name", "fvar"}
]
xml = StringIO()
font.saveXML(xml)
xml1 = StringIO()
font.saveXML(xml1, tables=tables)
xml.seek(0)
font = TTFont()
font.importXML(xml)
ttf = BytesIO()
font.save(ttf)
ttf.seek(0)
font = TTFont(ttf)
xml2 = StringIO()
font.saveXML(xml2, tables=tables)
assert xml1.getvalue() == xml2.getvalue()
if __name__ == "__main__":
import sys