Skip to content

Commit

Permalink
Merge pull request #2439 from fonttools/i2438
Browse files Browse the repository at this point in the history
Don't crash if there is no layer list
  • Loading branch information
anthrotype committed Nov 3, 2021
2 parents b11d6f7 + 6144202 commit 6373893
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Lib/fontTools/colorLib/unbuilder.py
Expand Up @@ -2,11 +2,14 @@
from .table_builder import TableUnbuilder


def unbuildColrV1(layerV1List, baseGlyphV1List):
unbuilder = LayerListUnbuilder(layerV1List.Paint)
def unbuildColrV1(layerList, baseGlyphList):
layers = []
if layerList:
layers = layerList.Paint
unbuilder = LayerListUnbuilder(layers)
return {
rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)
for rec in baseGlyphV1List.BaseGlyphPaintRecord
for rec in baseGlyphList.BaseGlyphPaintRecord
}


Expand Down
11 changes: 8 additions & 3 deletions Tests/colorLib/unbuilder_test.py
Expand Up @@ -221,11 +221,16 @@
"Glyph": "glyph00012",
},
],
},
}
}


def test_unbuildColrV1():
layersV1, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
colorGlyphs = unbuildColrV1(layersV1, baseGlyphsV1)
layers, baseGlyphs = buildColrV1(TEST_COLOR_GLYPHS)
colorGlyphs = unbuildColrV1(layers, baseGlyphs)
assert colorGlyphs == TEST_COLOR_GLYPHS

def test_unbuildColrV1_noLayers():
_, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
# Just looking to see we don't crash
unbuildColrV1(None, baseGlyphsV1)

0 comments on commit 6373893

Please sign in to comment.