Skip to content

Commit

Permalink
Merge pull request #845 from googlefonts/fix-kerning-pair-conversion
Browse files Browse the repository at this point in the history
Old kern writer: Convert groups back
  • Loading branch information
madig authored May 24, 2024
2 parents 8c895d0 + 3df2b8a commit df592b1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Lib/ufo2ft/featureWriters/kernFeatureWriter2.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,39 @@ 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]
pairs.sort()
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())
Expand Down
9 changes: 9 additions & 0 deletions tests/featureWriters/variableFeatureWriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -98,9 +103,13 @@ def test_variable_features_old_kern_writer(FontClass):
markClass dotabove-ar <anchor (wght=100:100 wght=1000:125) (wght=100:320 wght=1000:416)> @MC_top;
markClass gravecmb <anchor 250 400> @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 {
Expand Down

0 comments on commit df592b1

Please sign in to comment.