Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash if there is no layer list #2439

Merged
merged 1 commit into from Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)