Skip to content

Commit

Permalink
Merge pull request #866 from googlefonts/prune-zero-class-variable-kerns
Browse files Browse the repository at this point in the history
[kernFeatureWriter] ignore zero-valued class kern pairs when building variable kern
  • Loading branch information
anthrotype authored Aug 29, 2024
2 parents 27f7e9b + 22a699e commit 8ec3ef3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Lib/ufo2ft/featureWriters/kernFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,13 @@ def getVariableKerningPairs(
if default_location not in value.values:
value.values[default_location] = 0
value = collapse_varscalar(value)
result.append(KerningPair(side1, side2, value))
pair = KerningPair(side1, side2, value)
# Ignore zero-valued class kern pairs. They are the most general
# kerns, so they don't override anything else like glyph kerns would
# and zero is the default.
if pair.firstIsClass and pair.secondIsClass and pair.value == 0:
continue
result.append(pair)

return result

Expand Down
14 changes: 14 additions & 0 deletions tests/data/TestVarfea-Regular.ufo/groups.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>public.kern1.a</key>
<array>
<string>a</string>
</array>
<key>public.kern2.a</key>
<array>
<string>a</string>
</array>
</dict>
</plist>
5 changes: 5 additions & 0 deletions tests/data/TestVarfea-Regular.ufo/kerning.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
<key>alef-ar.fina</key>
<integer>15</integer>
</dict>
<key>public.kern1.a</key>
<dict>
<key>public.kern2.a</key>
<integer>0</integer>
</dict>
</dict>
</plist>
2 changes: 2 additions & 0 deletions tests/featureWriters/variableFeatureWriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ 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.a = [a];
@kern1.alef = [alef-ar.fina];
@kern2.a = [a];
@kern2.alef = [alef-ar.fina];
lookup kern_rtl {
Expand Down

0 comments on commit 8ec3ef3

Please sign in to comment.