Skip to content

Commit

Permalink
colorLib_test: check that duplicate base glyphs share share the same …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
anthrotype committed Jan 21, 2022
1 parent eded208 commit e68a5a1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Tests/colorLib/builder_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e68a5a1

Please sign in to comment.