Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[subset] fix AttributeError when subsetting COLRv1 font without optional ClipList #2424

Merged
merged 2 commits into from Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/fontTools/subset/__init__.py
Expand Up @@ -2089,8 +2089,9 @@ def subset_glyphs(self, s):
)
del self.ColorLayersV1

clips = self.table.ClipList.clips
self.table.ClipList.clips = {g: clips[g] for g in clips if g in s.glyphs}
if self.table.ClipList is not None:
clips = self.table.ClipList.clips
self.table.ClipList.clips = {g: clips[g] for g in clips if g in s.glyphs}

layersV0 = self.ColorLayers
if not self.table.BaseGlyphList.BaseGlyphPaintRecord:
Expand Down
17 changes: 17 additions & 0 deletions Tests/subset/subset_test.py
Expand Up @@ -1269,6 +1269,23 @@ def test_subset_COLRv1_drop_all_v0_glyphs(colrv1_path):
assert colr.table.LayerRecordCount is 0


def test_subset_COLRv1_no_ClipList(colrv1_path):
font = TTFont(colrv1_path)
font["COLR"].table.ClipList = None # empty ClipList
font.save(colrv1_path)

subset_path = colrv1_path.parent / (colrv1_path.name + ".subset")
subset.main(
[
str(colrv1_path),
f"--output-file={subset_path}",
"--unicodes=*",
]
)
subset_font = TTFont(subset_path)
assert subset_font["COLR"].table.ClipList is None


def test_subset_keep_size_drop_empty_stylistic_set():
fb = FontBuilder(unitsPerEm=1000, isTTF=True)
glyph_order = [".notdef", "a", "b", "b.ss01"]
Expand Down