diff --git a/Tests/ttLib/data/varc-6868.ttf b/Tests/ttLib/data/varc-6868.ttf index aa55df211..66cf83e30 100644 Binary files a/Tests/ttLib/data/varc-6868.ttf and b/Tests/ttLib/data/varc-6868.ttf differ diff --git a/Tests/ttLib/data/varc-ac00-ac01.ttf b/Tests/ttLib/data/varc-ac00-ac01.ttf index 1e385bad3..a8cbf6f74 100644 Binary files a/Tests/ttLib/data/varc-ac00-ac01.ttf and b/Tests/ttLib/data/varc-ac00-ac01.ttf differ diff --git a/Tests/ttLib/tables/V_A_R_C_test.py b/Tests/ttLib/tables/V_A_R_C_test.py new file mode 100644 index 000000000..9ddc107f1 --- /dev/null +++ b/Tests/ttLib/tables/V_A_R_C_test.py @@ -0,0 +1,87 @@ +from fontTools.ttLib import TTFont +from io import StringIO, BytesIO +import pytest +import os +import unittest + +CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) +DATA_DIR = os.path.join(CURR_DIR, "data") + + +class VarCompositeTest(unittest.TestCase): + def test_trim_varComposite_glyph(self): + font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-ac00-ac01.ttf") + font = TTFont(font_path) + varc = font["VARC"] + + assert varc.table.Coverage.glyphs == [ + "uniAC00", + "uniAC01", + "glyph00003", + "glyph00004", + "glyph00005", + "glyph00006", + "glyph00007", + ] + + font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-6868.ttf") + font = TTFont(font_path) + varc = font["VARC"] + + assert varc.table.Coverage.glyphs == [ + "uni6868", + "glyph00002", + "glyph00003", + "glyph00004", + ] + + 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 + + sys.exit(unittest.main()) diff --git a/Tests/ttLib/tables/_g_l_y_f_test.py b/Tests/ttLib/tables/_g_l_y_f_test.py index 39f48b266..7dbdbfd3a 100644 --- a/Tests/ttLib/tables/_g_l_y_f_test.py +++ b/Tests/ttLib/tables/_g_l_y_f_test.py @@ -719,67 +719,8 @@ class GlyphComponentTest: assert (comp.firstPt, comp.secondPt) == (1, 2) assert not hasattr(comp, "transform") - def test_trim_varComposite_glyph(self): - font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-ac00-ac01.ttf") - font = TTFont(font_path) - glyf = font["glyf"] - - glyf.glyphs["uniAC00"].trim() - glyf.glyphs["uniAC01"].trim() - - font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-6868.ttf") - font = TTFont(font_path) - glyf = font["glyf"] - - 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() - - class GlyphCubicTest: + def test_roundtrip(self): font_path = os.path.join(DATA_DIR, "NotoSans-VF-cubic.subset.ttf") font = TTFont(font_path)