From e68a5a173c87419728b2e534226c03791ec49ca0 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 21 Jan 2022 19:02:31 +0000 Subject: [PATCH] colorLib_test: check that duplicate base glyphs share share the same PaintColrLayers this test currently fails; currently the second, third, etc. base glyphs with the same layers gets a unique PaintColrLayers with NumLayers:1 that in turn contains the shared PaintColrLayers. They should instead all share the same PaintColrLayers. Fix in the next commit --- Tests/colorLib/builder_test.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Tests/colorLib/builder_test.py b/Tests/colorLib/builder_test.py index f0a09924f4..9fa8fac7a6 100644 --- a/Tests/colorLib/builder_test.py +++ b/Tests/colorLib/builder_test.py @@ -1,3 +1,4 @@ +from copy import deepcopy from fontTools.ttLib import newTable from fontTools.ttLib.tables import otTables as ot from fontTools.colorLib import builder @@ -1692,6 +1693,33 @@ def test_build_clip_list(self): assert clipBoxes["a"].Format == 2 assert clipBoxes["c"].Format == 1 + def test_duplicate_base_glyphs(self): + # If > 1 base glyphs refer to equivalent list of layers we expect them to share + # the same PaintColrLayers. + layers = { + "Format": ot.PaintFormat.PaintColrLayers, + "Layers": [ + (ot.PaintFormat.PaintGlyph, (ot.PaintFormat.PaintSolid, 0), "d"), + (ot.PaintFormat.PaintGlyph, (ot.PaintFormat.PaintSolid, 1), "e"), + ], + } + # I copy the layers to ensure equality is by content, not by identity + colr = builder.buildCOLR( + {"a": layers, "b": deepcopy(layers), "c": deepcopy(layers)} + ).table + + baseGlyphs = colr.BaseGlyphList.BaseGlyphPaintRecord + assert len(baseGlyphs) == 3 + + assert baseGlyphs[0].BaseGlyph == "a" + assert baseGlyphs[1].BaseGlyph == "b" + assert baseGlyphs[2].BaseGlyph == "c" + + expected = {"Format": 1, "FirstLayerIndex": 0, "NumLayers": 2} + assert baseGlyphs[0].Paint.__dict__ == expected + assert baseGlyphs[1].Paint.__dict__ == expected + assert baseGlyphs[2].Paint.__dict__ == expected + class TrickyRadialGradientTest: @staticmethod