diff options
author | Rasmus Andersson <rasmus@notion.se> | 2018-09-03 22:55:49 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2018-09-03 22:55:49 +0300 |
commit | c833e252c925e8dd68108660710ca835d95daa6f (patch) | |
tree | 6b2e28264ed45efd7f054e453b622098d0d875b8 /misc/tools/glyf-props.py | |
parent | 8c1a4c181ef12000179dfec541f1af87e9b03122 (diff) | |
download | inter-c833e252c925e8dd68108660710ca835d95daa6f.tar.xz |
Major overhaul, moving from UFO2 to Glyphs and UFO3, plus a brand new and much simpler fontbuild
Diffstat (limited to 'misc/tools/glyf-props.py')
-rwxr-xr-x | misc/tools/glyf-props.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/misc/tools/glyf-props.py b/misc/tools/glyf-props.py new file mode 100755 index 000000000..8783a422d --- /dev/null +++ b/misc/tools/glyf-props.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# encoding: utf8 +from __future__ import print_function +import os, sys +from argparse import ArgumentParser +from robofab.objects.objectsRF import OpenFont + + +dryRun = False + +def renameProps(font, renames): + for g in font: + for currname, newname in renames: + if currname in g.lib: + if newname in g.lib: + raise Exception('property %r already exist in glyph %r' % (newname, g)) + g.lib[newname] = g.lib[currname] + del g.lib[currname] + + +def main(): + argparser = ArgumentParser( + description='Operate on UFO glyf "lib" properties') + + argparser.add_argument( + '-dry', dest='dryRun', action='store_const', const=True, default=False, + help='Do not modify anything, but instead just print what would happen.') + + argparser.add_argument( + '-m', dest='renameProps', metavar='<currentName>=<newName>[,...]', type=str, + help='Rename properties') + + argparser.add_argument( + 'fontPaths', metavar='<ufofile>', type=str, nargs='+', help='UFO fonts to update') + + args = argparser.parse_args() + dryRun = args.dryRun + + renames = [] + if args.renameProps: + renames = [tuple(s.split('=')) for s in args.renameProps.split(',')] + # TODO: verify data structure + print('renaming properties:') + for rename in renames: + print(' %r => %r' % rename) + + # Strip trailing slashes from font paths and iterate + for fontPath in [s.rstrip('/ ') for s in args.fontPaths]: + font = OpenFont(fontPath) + + if len(renames): + print('Renaming properties in %s' % fontPath) + renameProps(font, renames) + + if dryRun: + print('Saving changes to %s (dry run)' % fontPath) + if not dryRun: + print('Saving changes to %s' % fontPath) + font.save() + + +if __name__ == '__main__': + main() |