subset: explicitly subset ClipList, avoids warning when lazy-loading

relying on ClipList.compile to drop unused clips based on updated glyphOrder won't work when font is loaded lazily (default for subsetter), because ClipList gets decompiled too late (after glyphOrder has already been modified) and this produces warnings about missing glyphIDs.
Better to make the subsetter explicilty prune unused clips.
This commit is contained in:
Cosimo Lupo 2021-08-18 09:42:10 +02:00
parent f04cb29fc4
commit 99743c14df
2 changed files with 12 additions and 0 deletions

View File

@ -2089,6 +2089,9 @@ def subset_glyphs(self, s):
) )
del self.ColorLayersV1 del self.ColorLayersV1
clips = self.table.ClipList.clips
self.table.ClipList.clips = {g: clips[g] for g in clips if g in s.glyphs}
layersV0 = self.ColorLayers layersV0 = self.ColorLayers
if not self.table.BaseGlyphList.BaseGlyphPaintRecord: if not self.table.BaseGlyphList.BaseGlyphPaintRecord:
# no more COLRv1 glyphs: downgrade to version 0 # no more COLRv1 glyphs: downgrade to version 0

View File

@ -1092,6 +1092,12 @@ def colrv1_path(tmp_path):
("glyph00018", 2), ("glyph00018", 2),
], ],
}, },
clipBoxes={
"uniE000": (0, 0, 200, 300),
"uniE001": (0, 0, 500, 500),
"uniE002": (100, 100, 400, 400),
"uniE003": (-50, -50, 350, 350),
},
) )
fb.setupCPAL( fb.setupCPAL(
[ [
@ -1171,6 +1177,9 @@ def test_subset_COLRv1_and_CPAL(colrv1_path):
assert layersV0[1].PaletteIndex == 0xFFFF assert layersV0[1].PaletteIndex == 0xFFFF
assert layersV0[2].PaletteIndex == 1 assert layersV0[2].PaletteIndex == 1
clipBoxes = colr.ClipList.clips
assert {"uniE001", "uniE002", "uniE003"} == set(clipBoxes)
assert "CPAL" in subset_font assert "CPAL" in subset_font
cpal = subset_font["CPAL"] cpal = subset_font["CPAL"]
assert [ assert [