[subset] fixed CPAL pruning after removal of ColorIndex

This commit is contained in:
Cosimo Lupo 2021-07-22 12:56:22 +01:00
parent 6ba0163614
commit 11871673ff
2 changed files with 8 additions and 8 deletions

View File

@ -2117,11 +2117,11 @@ def prune_post_subset(self, font, options):
colors_by_index = defaultdict(list) colors_by_index = defaultdict(list)
def collect_colors_by_index(paint): def collect_colors_by_index(paint):
if hasattr(paint, "Color"): # either solid colors... if hasattr(paint, "PaletteIndex"): # either solid colors...
colors_by_index[paint.Color.PaletteIndex].append(paint.Color) colors_by_index[paint.PaletteIndex].append(paint)
elif hasattr(paint, "ColorLine"): # ... or gradient color stops elif hasattr(paint, "ColorLine"): # ... or gradient color stops
for stop in paint.ColorLine.ColorStop: for stop in paint.ColorLine.ColorStop:
colors_by_index[stop.Color.PaletteIndex].append(stop.Color) colors_by_index[stop.PaletteIndex].append(stop)
if colr.version == 0: if colr.version == 0:
for layers in colr.ColorLayers.values(): for layers in colr.ColorLayers.values():

View File

@ -1013,7 +1013,7 @@ def colrv1_path(tmp_path):
}, },
{ {
"Format": ot.PaintFormat.PaintGlyph, "Format": ot.PaintFormat.PaintGlyph,
"Paint": (ot.PaintFormat.PaintSolid, (2, 0.3)), "Paint": (ot.PaintFormat.PaintSolid, 2, 0.3),
"Glyph": "glyph00011", "Glyph": "glyph00011",
}, },
], ],
@ -1044,7 +1044,7 @@ def colrv1_path(tmp_path):
}, },
{ {
"Format": ot.PaintFormat.PaintGlyph, "Format": ot.PaintFormat.PaintGlyph,
"Paint": (ot.PaintFormat.PaintSolid, (1, 0.5)), "Paint": (ot.PaintFormat.PaintSolid, 1, 0.5),
"Glyph": "glyph00013", "Glyph": "glyph00013",
}, },
], ],
@ -1159,9 +1159,9 @@ def test_subset_COLRv1_and_CPAL(colrv1_path):
] ]
assert len(layers) == 2 assert len(layers) == 2
# check v1 palette indices were remapped # check v1 palette indices were remapped
assert layers[0].Paint.Paint.ColorLine.ColorStop[0].Color.PaletteIndex == 0 assert layers[0].Paint.Paint.ColorLine.ColorStop[0].PaletteIndex == 0
assert layers[0].Paint.Paint.ColorLine.ColorStop[1].Color.PaletteIndex == 1 assert layers[0].Paint.Paint.ColorLine.ColorStop[1].PaletteIndex == 1
assert layers[1].Paint.Color.PaletteIndex == 0 assert layers[1].Paint.PaletteIndex == 0
baseRecV0 = colr.BaseGlyphRecordArray.BaseGlyphRecord[0] baseRecV0 = colr.BaseGlyphRecordArray.BaseGlyphRecord[0]
assert baseRecV0.BaseGlyph == "uniE004" assert baseRecV0.BaseGlyph == "uniE004"