[subset] Add test for CPALv1 (failing !)

This commit is contained in:
Jack McCabe 2022-09-30 12:10:56 +01:00
parent b945fd6305
commit 4901deab76

View File

@ -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")