summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2020-04-09 06:04:59 +0300
committerRasmus Andersson <rasmus@notion.se>2020-04-09 06:04:59 +0300
commit9890b2508d4e9e44cae991645461f2c7bdffeddc (patch)
tree2556f76c77449f7a1ceb0a41ccb9d50c566cd50e /misc
parentf4116ac9acd9db21338bd0fb82bd8ec0c668da76 (diff)
downloadinter-9890b2508d4e9e44cae991645461f2c7bdffeddc.tar.xz
display: round all kerning values to integers
Diffstat (limited to 'misc')
-rw-r--r--misc/tools/round-kerning-in-glyphs-file.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/misc/tools/round-kerning-in-glyphs-file.py b/misc/tools/round-kerning-in-glyphs-file.py
new file mode 100644
index 000000000..e2a6d8dde
--- /dev/null
+++ b/misc/tools/round-kerning-in-glyphs-file.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# encoding: utf8
+__doc__ = """
+Rounds all kerning values in a Glyphs file to integers
+"""
+import os, sys, re
+
+pat = re.compile(r'(.*=\s*)(\-?\d[\d\.]*);\n')
+file = sys.argv[1]
+outlines = []
+count = 0
+
+with open(file, "r") as f:
+ print(f)
+ level = 0
+ done = False
+ for lineno, line in enumerate(f):
+ if not done:
+ if level == 0:
+ if line == "kerning = {\n":
+ print("BEGIN at line", lineno)
+ level = 1
+ else:
+ if line.find("{") != -1:
+ level += 1
+ if line.find("}") != -1:
+ level -= 1
+ m = pat.match(line)
+ if m is not None:
+ val = m.group(2)
+ val2 = str(int(float(val)))
+ line = m.group(1) + val2 + ";\n"
+ if val != val2:
+ count += 1
+ if level == 0:
+ print("END at line", lineno)
+ done = True
+ outlines.append(line)
+
+if count == 0:
+ print("all kerning values in %s are integers (no change)" % file)
+else:
+ print("rounded %r kerning values in %s" % (count, file))
+ with open(file, "w") as f:
+ f.write("".join(outlines))