summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2017-08-24 10:43:12 +0300
committerRasmus Andersson <rasmus@notion.se>2017-08-24 10:43:12 +0300
commit3835e299be96e952ccea38b37f7e4288705d35c5 (patch)
tree435fa11b00db54ad5c0919c40995f176a1b590af /misc
parent87ef797b2515590fc7670724bdc0939de576672f (diff)
downloadinter-3835e299be96e952ccea38b37f7e4288705d35c5.tar.xz
Adds tabular numbers. Closes #10
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/gen-tnum.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/misc/gen-tnum.py b/misc/gen-tnum.py
new file mode 100755
index 000000000..627a38354
--- /dev/null
+++ b/misc/gen-tnum.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+# encoding: utf8
+from __future__ import print_function
+import os, sys
+from argparse import ArgumentParser
+from robofab.objects.objectsRF import OpenFont
+from math import ceil, floor
+
+dryRun = False
+numNames = [
+ 'zero','one','two','three','four','five','six','seven','eight','nine'
+]
+
+
+def main():
+ argparser = ArgumentParser(
+ description='Generate tabular number glyphs from regular number glyphs')
+
+ 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(
+ 'fontPaths', metavar='<ufofile>', type=str, nargs='+', help='UFO fonts')
+
+ args = argparser.parse_args()
+ dryRun = args.dryRun
+
+ # Strip trailing slashes from font paths and iterate
+ for fontPath in [s.rstrip('/ ') for s in args.fontPaths]:
+ fontName = os.path.basename(fontPath)
+ font = OpenFont(fontPath)
+
+ # Find widest glyph
+ width = 0
+ for name in numNames:
+ g = font[name]
+ width = max(width, g.width)
+
+ print('[%s] tnums width:' % fontName, width)
+
+ # Create tnum glyphs
+ for name in numNames:
+ g = font[name]
+
+ tnum = font.newGlyph(name + '.tnum')
+ tnum.width = width
+ print('[%s] gen' % fontName, tnum.name)
+
+ # calculate component x-offset
+ xoffs = 0
+ if g.width != width:
+ # center shape, ignoring existing margins
+ # xMin, yMin, xMax, yMax = g.box
+ # graphicWidth = xMax - xMin
+ # leftMargin = round((width - graphicWidth) / 2)
+ # xoffs = leftMargin - g.leftMargin
+
+ # adjust margins
+ widthDelta = width - g.width
+ leftMargin = g.leftMargin + int(floor(widthDelta / 2))
+ rightMargin = g.rightMargin + int(ceil(widthDelta / 2))
+ xoffs = leftMargin - g.leftMargin
+
+ tnum.appendComponent(name, (xoffs, 0))
+
+ if dryRun:
+ print('[%s] save [dry run]' % fontName)
+ else:
+ print('[%s] save' % fontName)
+ font.save()
+
+
+if __name__ == '__main__':
+ main()