diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index 7efcb698b..7cdeb97e2 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -1244,6 +1244,28 @@ def colrv1_path(tmp_path): return output_path +@pytest.fixture +def colrv1_cpalv1_path(colrv1_path): + # upgrade CPAL from v0 to v1 by adding labels + font = TTFont(colrv1_path) + fb = FontBuilder(font=font) + fb.setupCPAL( + [ + [ + (1.0, 0.0, 0.0, 1.0), # red + (0.0, 1.0, 0.0, 1.0), # green + (0.0, 0.0, 1.0, 1.0), # blue + ], + ], + paletteLabels=["test palette"], + paletteEntryLabels=["first color", "second color", "third color"] + ) + + output_path = colrv1_path.parent / "TestCOLRv1CPALv1.ttf" + fb.save(output_path) + + return output_path + def test_subset_COLRv1_and_CPAL(colrv1_path): subset_path = colrv1_path.parent / (colrv1_path.name + ".subset") @@ -1321,6 +1343,30 @@ def test_subset_COLRv1_and_CPAL(colrv1_path): (0.0, 0.0, 1.0, 1.0), # blue ] +def test_subset_COLRv1_and_CPALv1(colrv1_cpalv1_path): + subset_path = colrv1_cpalv1_path.parent / (colrv1_cpalv1_path.name + ".subset") + + subset.main( + [ + str(colrv1_cpalv1_path), + "--glyph-names", + f"--output-file={subset_path}", + "--unicodes=E002,E003,E004", + ] + ) + subset_font = TTFont(subset_path) + + assert "CPAL" in subset_font + cpal = subset_font["CPAL"] + name_table = subset_font["name"] + import pdb + pdb.set_trace() + assert [name_table.getDebugName(name_id) for name_id in cpal.paletteEntryLabels] == [ + # "first color", # The first color was pruned + "second color", + "third color", + ] + def test_subset_COLRv1_and_CPAL_drop_empty(colrv1_path): subset_path = colrv1_path.parent / (colrv1_path.name + ".subset")