Skip to content

Commit

Permalink
Don't crash if there is no layer list
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Nov 2, 2021
1 parent b11d6f7 commit 6144202
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 6144202

Please sign in to comment.