diff options
author | Rasmus Andersson <rasmus@notion.se> | 2020-04-09 06:04:59 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2020-04-09 06:04:59 +0300 |
commit | 9890b2508d4e9e44cae991645461f2c7bdffeddc (patch) | |
tree | 2556f76c77449f7a1ceb0a41ccb9d50c566cd50e /misc/tools/round-kerning-in-glyphs-file.py | |
parent | f4116ac9acd9db21338bd0fb82bd8ec0c668da76 (diff) | |
download | inter-9890b2508d4e9e44cae991645461f2c7bdffeddc.tar.xz |
display: round all kerning values to integers
Diffstat (limited to 'misc/tools/round-kerning-in-glyphs-file.py')
-rw-r--r-- | misc/tools/round-kerning-in-glyphs-file.py | 45 |
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)) |