I’m using “Remove Small Kerning Pairs” from @mekkablue and it’s seems that removeKerningForPair() method is really slow.
Maybe something could be optimized in the method.
With this script, it took less than 1 second, whereas removing small kerning pairs took several minutes.
# Initialize the selected font master and threshold for kerning adjustment
selected_master_id = Font.selectedFontMaster.id
kerning_threshold = 5
adjusted_kerning = {}
pairs_deleted = 0
# Iterate through the kerning pairs of the selected font master
for left_glyph, right_pairs in Font.kerning[selected_master_id].items():
# Filter kerning pairs that exceed the specified threshold
valid_pairs = {pair: value for pair, value in right_pairs.items() if abs(value) >= kerning_threshold}
if valid_pairs:
adjusted_kerning[left_glyph] = valid_pairs
else:
pairs_deleted += len(right_pairs)
# Update the font's kerning with the adjusted values
Font.kerning[selected_master_id] = adjusted_kerning
# Output the result
print(f"{pairs_deleted} pairs deleted in {Font.selectedFontMaster.name}")
I suppose that pressing the [-] button in the Kerning Panel also triggers removeKerningForPair(), because when I select a lot of pairs, it’s also very slow to delete them.