From 11871673ff68f36f4e9e8379ab62e8551d57e802 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 22 Jul 2021 12:56:22 +0100 Subject: [PATCH] [subset] fixed CPAL pruning after removal of ColorIndex --- Lib/fontTools/subset/__init__.py | 6 +++--- Tests/subset/subset_test.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index 8fa98f40e..8616053b6 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -2117,11 +2117,11 @@ def prune_post_subset(self, font, options): colors_by_index = defaultdict(list) def collect_colors_by_index(paint): - if hasattr(paint, "Color"): # either solid colors... - colors_by_index[paint.Color.PaletteIndex].append(paint.Color) + if hasattr(paint, "PaletteIndex"): # either solid colors... + colors_by_index[paint.PaletteIndex].append(paint) elif hasattr(paint, "ColorLine"): # ... or gradient color stops 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: for layers in colr.ColorLayers.values(): diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index feee47b24..aa96fb7cb 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -1013,7 +1013,7 @@ def colrv1_path(tmp_path): }, { "Format": ot.PaintFormat.PaintGlyph, - "Paint": (ot.PaintFormat.PaintSolid, (2, 0.3)), + "Paint": (ot.PaintFormat.PaintSolid, 2, 0.3), "Glyph": "glyph00011", }, ], @@ -1044,7 +1044,7 @@ def colrv1_path(tmp_path): }, { "Format": ot.PaintFormat.PaintGlyph, - "Paint": (ot.PaintFormat.PaintSolid, (1, 0.5)), + "Paint": (ot.PaintFormat.PaintSolid, 1, 0.5), "Glyph": "glyph00013", }, ], @@ -1159,9 +1159,9 @@ def test_subset_COLRv1_and_CPAL(colrv1_path): ] assert len(layers) == 2 # check v1 palette indices were remapped - assert layers[0].Paint.Paint.ColorLine.ColorStop[0].Color.PaletteIndex == 0 - assert layers[0].Paint.Paint.ColorLine.ColorStop[1].Color.PaletteIndex == 1 - assert layers[1].Paint.Color.PaletteIndex == 0 + assert layers[0].Paint.Paint.ColorLine.ColorStop[0].PaletteIndex == 0 + assert layers[0].Paint.Paint.ColorLine.ColorStop[1].PaletteIndex == 1 + assert layers[1].Paint.PaletteIndex == 0 baseRecV0 = colr.BaseGlyphRecordArray.BaseGlyphRecord[0] assert baseRecV0.BaseGlyph == "uniE004"