misc/rf-scripts/AdjustWidth.py

This commit is contained in:
Rasmus Andersson 2018-01-13 18:42:32 -08:00
parent 64f4aaed31
commit 093cc3047c

View file

@ -10,11 +10,12 @@ if __name__ == "__main__":
print "Resizing glyph margins for %r" % font print "Resizing glyph margins for %r" % font
# how much to add or remove from each glyph's margin # how much to add or remove from each glyph's margin
A = -8 A = 16
if font is not None: if font is not None:
# first, check for errors and collect glyphs we should adjust # first, check for errors and collect glyphs we should adjust
glyphs = [] glyphs = []
glyphNamesToAdjust = set()
ignored = [] ignored = []
errors = 0 errors = 0
@ -37,6 +38,7 @@ if __name__ == "__main__":
continue continue
glyphs.append(g) glyphs.append(g)
glyphNamesToAdjust.add(g.name)
if errors > 0: if errors > 0:
print "Stopping changes because there are errors" print "Stopping changes because there are errors"
@ -47,28 +49,45 @@ if __name__ == "__main__":
print '# name => [ (prevLeftMargin, prevRightMargin), (newLeft, newRight) ]' print '# name => [ (prevLeftMargin, prevRightMargin), (newLeft, newRight) ]'
print 'resized_glyphs = [' print 'resized_glyphs = ['
adjustments = dict()
onlyGlyphs = None # ['A', 'Lambda'] # DEBUG
count = 0
for g in glyphs: for g in glyphs:
if onlyGlyphs is not None:
if not g.name in onlyGlyphs:
continue
if len(onlyGlyphs) == count:
break
count += 1
for comp in g.components:
# adjust offset of any components which are being adjusted
if comp.baseGlyph in glyphNamesToAdjust:
# x, y -- counter-balance x offset
comp.offset = (comp.offset[0] - A, comp.offset[1])
newLeftMargin = int(g.leftMargin + A) newLeftMargin = int(g.leftMargin + A)
newRightMargin = int(g.rightMargin + A) newRightMargin = int(g.rightMargin + A)
print ' "%s": [(%g, %g), (%g, %g)],' % ( print ' "%s": [(%g, %g), (%g, %g)],' % (
g.name, g.leftMargin, g.rightMargin, newLeftMargin, newRightMargin) g.name, g.leftMargin, g.rightMargin, newLeftMargin, newRightMargin)
# order of assignment is probably important
g.rightMargin = int(newRightMargin)
g.leftMargin = int(newLeftMargin) g.leftMargin = int(newLeftMargin)
g.rightMargin = int(newRightMargin)
print '] # resized_glyphs' print '] # resized_glyphs'
font.update() font.update()
if len(ignored) > 0: # if len(ignored) > 0:
print '' # print ''
print '# name => [what, reason]' # print '# name => [what, reason]'
print "ignored_glyphs = [" # print "ignored_glyphs = ["
for t in ignored: # for t in ignored:
print ' "%s": ["ignore", %r],' % t # print ' "%s": ["ignore", %r],' % t
print '] # ignored_glyphs' # print '] # ignored_glyphs'
else: else:
print "No fonts open" print "No fonts open"