summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2018-01-14 04:54:45 +0300
committerRasmus Andersson <rasmus@notion.se>2018-01-14 04:54:45 +0300
commitc203f51290b940cbc643070a2d33df8a28a18cb1 (patch)
treeed82c863a05928f71eb66d2294055ec5936e900d
parentdc480de3a9264919d1df247a059f49f4ce968354 (diff)
downloadinter-c203f51290b940cbc643070a2d33df8a28a18cb1.tar.xz
misc/rf-scripts/AdjustWidth.py
-rw-r--r--misc/rf-scripts/AdjustWidth.py72
1 files changed, 45 insertions, 27 deletions
diff --git a/misc/rf-scripts/AdjustWidth.py b/misc/rf-scripts/AdjustWidth.py
index d9dbc6d8b..35168b65a 100644
--- a/misc/rf-scripts/AdjustWidth.py
+++ b/misc/rf-scripts/AdjustWidth.py
@@ -10,48 +10,66 @@ if __name__ == "__main__":
print "Resizing glyph margins for %r" % font
# how much to add or remove from each glyph's margin
- A = 32
+ A = -8
if font is not None:
- errors = 0 # if >0 then changes are discarded
- for g in font:
- # skip glyphs
- #if g.name in ('c', 'e', 'o', 'r', 'j'):
- # continue
+ # first, check for errors and collect glyphs we should adjust
+ glyphs = []
+ ignored = []
+ errors = 0
+ for g in font:
if g.width < 4:
- print '"%s": ["ignore", "zero-width"],' % (g.name)
+ ignored.append((g.name, 'zero-width'))
continue
- if g.box is None:
- print '"%s": ["ignore", "empty"],' % (g.name)
- continue
+ # if g.box is None:
+ # print '"%s": ["ignore", "empty"],' % (g.name)
+ # continue
+
+ # skip glyphs
+ #if g.name in ('c', 'e', 'o', 'r', 'j'):
+ # continue
if g.width % 4 != 0:
print '"%s": ["error", "misaligned"],' % (g.name)
errors += 1
continue
- #if g.leftMargin <= 0 or g.rightMargin <= 0:
- # print '"%s": ["ignore", "zero-or-negative"],' % (g.name)
- # continue
-
- leftMargin = int(max(0, g.leftMargin + A))
- rightMargin = int(max(0, g.rightMargin + A))
-
- #print '"%s": ["update", %g, %g],' % (g.name, leftMargin, rightMargin)
- if 'interui.spaceadjust' in g.lib:
- g.lib['interui.width-adjustments'].append(A)
- else:
- g.lib['interui.width-adjustments'] = [A]
- # order of assignment is probably important
- g.rightMargin = int(rightMargin)
- g.leftMargin = int(leftMargin)
+ glyphs.append(g)
if errors > 0:
- print "Discarding changes because there were errors"
+ print "Stopping changes because there are errors"
else:
- font.update()
+
+ print '# Result from AdjustWidth.py with A=%g on %s %s' % (
+ A, font.info.familyName, font.info.styleName)
+ print '# name => [ (prevLeftMargin, prevRightMargin), (newLeft, newRight) ]'
+ print 'resized_glyphs = ['
+
+ for g in glyphs:
+ newLeftMargin = int(g.leftMargin + A)
+ newRightMargin = int(g.rightMargin + A)
+
+ print ' "%s": [(%g, %g), (%g, %g)],' % (
+ g.name, g.leftMargin, g.rightMargin, newLeftMargin, newRightMargin)
+
+ # order of assignment is probably important
+ g.rightMargin = int(newRightMargin)
+ g.leftMargin = int(newLeftMargin)
+
+ print '] # resized_glyphs'
+
+ font.update()
+
+ if len(ignored) > 0:
+ print ''
+ print '# name => [what, reason]'
+ print "ignored_glyphs = ["
+ for t in ignored:
+ print ' "%s": ["ignore", %r],' % t
+ print '] # ignored_glyphs'
+
else:
print "No fonts open"