colorLib.unbuilder: ensure unbuildColrV1 flattens nested PaintColrLayers
This commit is contained in:
parent
fc982c643b
commit
c612b2637f
@ -13,12 +13,12 @@ def unbuildColrV1(layerList, baseGlyphList):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _flatten(lst):
|
def _flatten_layers(lst):
|
||||||
for el in lst:
|
for paint in lst:
|
||||||
if isinstance(el, list):
|
if paint["Format"] == ot.PaintFormat.PaintColrLayers:
|
||||||
yield from _flatten(el)
|
yield from _flatten_layers(paint["Layers"])
|
||||||
else:
|
else:
|
||||||
yield el
|
yield paint
|
||||||
|
|
||||||
|
|
||||||
class LayerListUnbuilder:
|
class LayerListUnbuilder:
|
||||||
@ -41,7 +41,7 @@ class LayerListUnbuilder:
|
|||||||
assert source["Format"] == ot.PaintFormat.PaintColrLayers
|
assert source["Format"] == ot.PaintFormat.PaintColrLayers
|
||||||
|
|
||||||
layers = list(
|
layers = list(
|
||||||
_flatten(
|
_flatten_layers(
|
||||||
[
|
[
|
||||||
self.unbuildPaint(childPaint)
|
self.unbuildPaint(childPaint)
|
||||||
for childPaint in self.layers[
|
for childPaint in self.layers[
|
||||||
|
@ -221,7 +221,26 @@ TEST_COLOR_GLYPHS = {
|
|||||||
"Glyph": "glyph00012",
|
"Glyph": "glyph00012",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
# When PaintColrLayers contains more than 255 layers, we build a tree
|
||||||
|
# of nested PaintColrLayers of max 255 items (NumLayers field is a uint8).
|
||||||
|
# Below we test that unbuildColrV1 restores a flat list of layers without
|
||||||
|
# nested PaintColrLayers.
|
||||||
|
"glyph00017": {
|
||||||
|
"Format": int(ot.PaintFormat.PaintColrLayers),
|
||||||
|
"Layers": [
|
||||||
|
{
|
||||||
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
||||||
|
"Paint": {
|
||||||
|
"Format": int(ot.PaintFormat.PaintSolid),
|
||||||
|
"PaletteIndex": i,
|
||||||
|
"Alpha": 1.0,
|
||||||
|
},
|
||||||
|
"Glyph": "glyph{str(18 + i).zfill(5)}",
|
||||||
}
|
}
|
||||||
|
for i in range(256)
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -230,6 +249,7 @@ def test_unbuildColrV1():
|
|||||||
colorGlyphs = unbuildColrV1(layers, baseGlyphs)
|
colorGlyphs = unbuildColrV1(layers, baseGlyphs)
|
||||||
assert colorGlyphs == TEST_COLOR_GLYPHS
|
assert colorGlyphs == TEST_COLOR_GLYPHS
|
||||||
|
|
||||||
|
|
||||||
def test_unbuildColrV1_noLayers():
|
def test_unbuildColrV1_noLayers():
|
||||||
_, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
|
_, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
|
||||||
# Just looking to see we don't crash
|
# Just looking to see we don't crash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user