summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2022-06-05 00:31:56 +0300
committerRasmus Andersson <rasmus@notion.se>2022-06-05 00:31:56 +0300
commit30a2594c2f9b0b7420cb3165b7f6971808f529e5 (patch)
tree2cfd11715e01c27a61b85baf0748e75126055b8d /misc
parent4a7ceaf37439281dd6f7937ef7232809f66c03e6 (diff)
downloadinter-30a2594c2f9b0b7420cb3165b7f6971808f529e5.tar.xz
round kerning to integer values
Diffstat (limited to 'misc')
-rw-r--r--misc/glyphs-scripts/round-kerning.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/misc/glyphs-scripts/round-kerning.py b/misc/glyphs-scripts/round-kerning.py
new file mode 100644
index 000000000..239823185
--- /dev/null
+++ b/misc/glyphs-scripts/round-kerning.py
@@ -0,0 +1,33 @@
+#MenuTitle: Round Kerning of current master
+# encoding: utf-8
+import GlyphsApp
+
+__doc__="""
+Rounds kerning of the currently selected master to integer values
+and drops any kerning smaller than 4.
+"""
+
+font = Glyphs.font
+master_id = font.selectedFontMaster.id
+MIN_VALUE = 4
+to_be_removed = [] # [(L,R) ...]
+
+try:
+ Glyphs.font.disableUpdateInterface()
+ for left, r_dict in font.kerning[master_id].items():
+ if not left.startswith('@'):
+ left = font.glyphForId_(left).name
+ for right, value in r_dict.items():
+ if not right.startswith('@'):
+ right = font.glyphForId_(right).name
+ value2 = float(int(value)) # floor()
+ if abs(value2) < MIN_VALUE:
+ to_be_removed.append((left, right))
+ elif value2 != value:
+ font.setKerningForPair(master_id, left, right, value2)
+
+ for left, right in to_be_removed:
+ print("removing pair (%s, %s)" % (left, right))
+ font.removeKerningForPair(master_id, left, right)
+finally:
+ Glyphs.font.enableUpdateInterface()