From b74ffb4cda018c05cf8002e6718041d8b2eb6469 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 23 Jul 2021 17:25:05 +0100 Subject: [PATCH] test roundtripping variable COLRv1 with a working VarIndexMap and VarStore --- Tests/ttLib/tables/C_O_L_R_test.py | 77 ++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/Tests/ttLib/tables/C_O_L_R_test.py b/Tests/ttLib/tables/C_O_L_R_test.py index 73ba74d75..f170dbe58 100644 --- a/Tests/ttLib/tables/C_O_L_R_test.py +++ b/Tests/ttLib/tables/C_O_L_R_test.py @@ -159,7 +159,7 @@ COLR_V1_SAMPLE = ( (b"\x00\x01\x00\x00", "VarAffine2x3.yy (1.0)"), (b"\x01\x2c\x00\x00", "VarAffine2x3.dx (300.0)"), (b"\x00\x00\x00\x00", "VarAffine2x3.dy (0.0)"), - (b"\xff\xff\xff\xff", "VarIndexBase (0xFFFFFFF)"), + (b"\x00\x00\x00\x00", "VarIndexBase (0)"), (b"\x0a", "BaseGlyphPaintRecord[1].Paint.SourcePaint.Format (10)"), (b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"), (b"\x00\x0b", "BaseGlyphPaintRecord[1].Paint.SourcePaint.Glyph (11)"), @@ -203,7 +203,7 @@ COLR_V1_SAMPLE = ( (b"\x03", "LayerList.Paint[0].Paint.Format (3)"), (b"\x00\x02", "Paint.PaletteIndex (2)"), (b" \x00", "Paint.Alpha.value (0.5)"), - (b"\xff\xff\xff\xff", "VarIndexBase (0xFFFFFFFF)"), + (b"\x00\x00\x00\x06", "VarIndexBase (6)"), # PaintGlyph glyph00012 (b"\x0a", "LayerList.Paint[1].Format (10)"), (b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"), @@ -248,12 +248,12 @@ COLR_V1_SAMPLE = ( (b"\x00\x00", "ColorLine.ColorStop[0].StopOffset.value (0.0)"), (b"\x00\x06", "ColorLine.ColorStop[0].PaletteIndex (6)"), (b"@\x00", "ColorLine.ColorStop[0].Alpha.value (1.0)"), - (b"\x00\x00\x00\x00", "VarIndexBase (0)"), + (b"\xff\xff\xff\xff", "VarIndexBase (0xFFFFFFFF)"), (b"@\x00", "ColorLine.ColorStop[1].StopOffset.value (1.0)"), (b"\x00\x07", "ColorLine.ColorStop[1].PaletteIndex (7)"), (b"\x19\x9a", "ColorLine.ColorStop[1].Alpha.value (0.4)"), - (b"\x00\x00\x00\x01", "VarIndexBase (1)"), + (b"\x00\x00\x00\x07", "VarIndexBase (7)"), (b"\xff\xf3\x00\x00", "Affine2x3.xx (-13)"), (b"\x00\x0e\x00\x00", "Affine2x3.xy (14)"), (b"\x00\x0f\x00\x00", "Affine2x3.yx (15)"), @@ -351,7 +351,7 @@ COLR_V1_XML = [ ' ', ' ', ' ', - ' ', + ' ', " ", " ", " ", @@ -389,7 +389,7 @@ COLR_V1_XML = [ ' ', ' ', ' ', - ' ', + ' ', " ", ' ', " ", @@ -433,13 +433,13 @@ COLR_V1_XML = [ ' ', ' ', ' ', - ' ', + " ", " ", ' ', ' ', ' ', ' ', - ' ', + ' ', " ", " ", ' ', @@ -448,7 +448,7 @@ COLR_V1_XML = [ ' ', ' ', ' ', - ' ', + " ", " ", " ", ' ', @@ -484,6 +484,52 @@ COLR_V1_XML = [ "", ] +COLR_V1_VAR_XML = [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + "", + '', + ' ', + " ", + " ", + " ", + ' ', + ' ', + ' ', + ' ', + ' ', + " ", + " ", + " ", + " ", + ' ', + " ", + ' ', + " ", + ' ', + ' ', + ' ', + ' ', + " ", + ' ', + " ", + ' ', + " ", + ' ', + ' ', + ' ', + " ", + "", +] + class COLR_V1_Test(object): def test_decompile_and_compile(self, font): @@ -513,3 +559,16 @@ class COLR_V1_Test(object): colr = table_C_O_L_R_() colr.decompile(compiled, font) assert getXML(colr.toXML, font) == COLR_V1_XML + + +class COLR_V1_Variable_Test(object): + def test_round_trip_xml(self, font): + colr = table_C_O_L_R_() + xml = COLR_V1_XML + COLR_V1_VAR_XML + for name, attrs, content in parseXML(xml): + colr.fromXML(name, attrs, content, font) + compiled = colr.compile(font) + + colr = table_C_O_L_R_() + colr.decompile(compiled, font) + assert getXML(colr.toXML, font) == xml