From d3eeee0fc1bc0698bcc8bc49469985bb546af30f Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Thu, 23 May 2024 18:22:31 +0100 Subject: [PATCH 1/2] Convert groups back --- .../featureWriters/kernFeatureWriter2.py | 33 ++++++++++++++++++- .../variableFeatureWriter_test.py | 9 +++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py b/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py index 13c8c959..deb92ec4 100644 --- a/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py +++ b/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py @@ -251,7 +251,38 @@ def getKerningPairs(font, side1Classes, side2Classes, glyphSet=None, options=Non glyphSet or {}, options or SimpleNamespace(**KernFeatureWriter.options), ) - return [KerningPair(pair.side1, pair.side2, pair.value) for pair in pairs] + side1toClass: Mapping[tuple[str, ...], ast.GlyphClassDefinition] = { + tuple( + glyph + for glyphs in glyph_defs.glyphSet() + for glyph in glyphs.glyphSet() + ): glyph_defs + for glyph_defs in side1Classes.values() + } + side2toClass: Mapping[tuple[str, ...], ast.GlyphClassDefinition] = { + tuple( + glyph + for glyphs in glyph_defs.glyphSet() + for glyph in glyphs.glyphSet() + ): glyph_defs + for glyph_defs in side2Classes.values() + } + return [ + KerningPair( + ( + side1toClass[pair.side1] + if isinstance(pair.side1, tuple) + else pair.side1 + ), + ( + side2toClass[pair.side2] + if isinstance(pair.side2, tuple) + else pair.side2 + ), + pair.value, + ) + for pair in pairs + ] if glyphSet: allGlyphs = set(glyphSet.keys()) diff --git a/tests/featureWriters/variableFeatureWriter_test.py b/tests/featureWriters/variableFeatureWriter_test.py index 077fd4f3..b501c033 100644 --- a/tests/featureWriters/variableFeatureWriter_test.py +++ b/tests/featureWriters/variableFeatureWriter_test.py @@ -90,6 +90,11 @@ def test_variable_features_old_kern_writer(FontClass): "class": "CursFeatureWriter", }, ] + for index, source in enumerate(designspace.sources): + font = source.font + font.groups["public.kern1.alef"] = ["alef-ar.fina"] + font.groups["public.kern2.alef"] = ["alef-ar.fina"] + font.kerning[("public.kern1.alef", "public.kern2.alef")] = index _ = compileVariableTTF(designspace, debugFeatureFile=tmp) @@ -98,9 +103,13 @@ def test_variable_features_old_kern_writer(FontClass): markClass dotabove-ar @MC_top; markClass gravecmb @MC_top; + @kern1.alef = [alef-ar.fina]; + @kern2.alef = [alef-ar.fina]; + lookup kern_rtl { lookupflag IgnoreMarks; pos alef-ar.fina alef-ar.fina <(wght=100:15 wght=1000:35) 0 (wght=100:15 wght=1000:35) 0>; + pos @kern1.alef @kern2.alef <(wght=100:0 wght=1000:1) 0 (wght=100:0 wght=1000:1) 0>; } kern_rtl; feature kern { From 3df2b8ab73087a63b0e95b235ed25a3dc9fe38cf Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Fri, 24 May 2024 14:37:03 +0100 Subject: [PATCH 2/2] Sort kerning pairs --- Lib/ufo2ft/featureWriters/kernFeatureWriter2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py b/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py index deb92ec4..de4eb663 100644 --- a/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py +++ b/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py @@ -251,6 +251,7 @@ def getKerningPairs(font, side1Classes, side2Classes, glyphSet=None, options=Non glyphSet or {}, options or SimpleNamespace(**KernFeatureWriter.options), ) + pairs.sort() side1toClass: Mapping[tuple[str, ...], ast.GlyphClassDefinition] = { tuple( glyph