From 4a38610072a9fe819c6227cae0e57f7be29816a2 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 23 Oct 2024 20:50:45 +0000 Subject: [PATCH] [subset] consider variation selectors subsetting cmap14 cmap14 subsetting code was not considering variation selectors in the input unicode set when deciding which variant glyphs to keep. This updates subsetting to only keeps variant glyphs if their variation selector code point is in the input unicodes set. --- Lib/fontTools/subset/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index 99556d49e..496eda92e 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -2873,7 +2873,9 @@ def closure_glyphs(self, s): # Close glyphs for table in tables: if table.format == 14: - for cmap in table.uvsDict.values(): + for varSelector, cmap in table.uvsDict.items(): + if varSelector not in s.unicodes_requested: + continue glyphs = {g for u, g in cmap if u in s.unicodes_requested} if None in glyphs: glyphs.remove(None) @@ -2927,7 +2929,7 @@ def subset_glyphs(self, s): for u, g in l if g in s.glyphs_requested or u in s.unicodes_requested ] - for v, l in t.uvsDict.items() + for v, l in t.uvsDict.items() if v in s.unicodes_requested } t.uvsDict = {v: l for v, l in t.uvsDict.items() if l} elif t.isUnicode(): @@ -3797,6 +3799,8 @@ def main(args=None): for t in font["cmap"].tables: if t.isUnicode(): unicodes.extend(t.cmap.keys()) + if t.format == 14: + unicodes.extend(t.uvsDict.keys()) assert "" not in glyphs log.info("Text: '%s'" % text)