2017-08-22 10:05:20 +03:00
|
|
|
#
|
|
|
|
# This script changes the width of all glyphs by applying a multiplier.
|
|
|
|
# It keeps the contours centered as glyphs get wider or tighter.
|
|
|
|
#
|
|
|
|
from mojo.roboFont import version
|
|
|
|
from math import ceil, floor
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
font = CurrentFont()
|
|
|
|
print "Resizing glyph margins for %r" % font
|
|
|
|
|
|
|
|
# how much to add or remove from each glyph's margin
|
2018-01-14 00:57:57 +03:00
|
|
|
A = 32
|
2017-08-22 10:05:20 +03:00
|
|
|
|
|
|
|
if font is not None:
|
2018-01-14 00:57:57 +03:00
|
|
|
errors = 0 # if >0 then changes are discarded
|
2017-08-22 10:05:20 +03:00
|
|
|
for g in font:
|
|
|
|
# skip glyphs
|
2018-01-14 00:57:57 +03:00
|
|
|
#if g.name in ('c', 'e', 'o', 'r', 'j'):
|
|
|
|
# continue
|
2017-08-22 10:05:20 +03:00
|
|
|
|
2018-01-14 00:57:57 +03:00
|
|
|
if g.width < 4:
|
2017-08-22 10:05:20 +03:00
|
|
|
print '"%s": ["ignore", "zero-width"],' % (g.name)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if g.box is None:
|
|
|
|
print '"%s": ["ignore", "empty"],' % (g.name)
|
|
|
|
continue
|
|
|
|
|
2018-01-14 00:57:57 +03:00
|
|
|
if g.width % 4 != 0:
|
|
|
|
print '"%s": ["error", "misaligned"],' % (g.name)
|
|
|
|
errors += 1
|
2017-08-22 10:05:20 +03:00
|
|
|
continue
|
|
|
|
|
2018-01-14 00:57:57 +03:00
|
|
|
#if g.leftMargin <= 0 or g.rightMargin <= 0:
|
|
|
|
# print '"%s": ["ignore", "zero-or-negative"],' % (g.name)
|
|
|
|
# continue
|
2017-08-22 10:05:20 +03:00
|
|
|
|
|
|
|
leftMargin = int(max(0, g.leftMargin + A))
|
|
|
|
rightMargin = int(max(0, g.rightMargin + A))
|
|
|
|
|
|
|
|
#print '"%s": ["update", %g, %g],' % (g.name, leftMargin, rightMargin)
|
2018-01-14 00:57:57 +03:00
|
|
|
if 'interui.spaceadjust' in g.lib:
|
|
|
|
g.lib['interui.width-adjustments'].append(A)
|
2017-08-22 10:05:20 +03:00
|
|
|
else:
|
2018-01-14 00:57:57 +03:00
|
|
|
g.lib['interui.width-adjustments'] = [A]
|
2017-08-22 10:05:20 +03:00
|
|
|
# order of assignment is probably important
|
|
|
|
g.rightMargin = int(rightMargin)
|
|
|
|
g.leftMargin = int(leftMargin)
|
|
|
|
|
2018-01-14 00:57:57 +03:00
|
|
|
if errors > 0:
|
|
|
|
print "Discarding changes because there were errors"
|
|
|
|
else:
|
|
|
|
font.update()
|
2017-08-22 10:05:20 +03:00
|
|
|
else:
|
|
|
|
print "No fonts open"
|
|
|
|
|
|
|
|
print "Done"
|