From 3535b65a6523abe89f3e008c8c885fcdd64a97ad Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 20 Sep 2015 14:14:41 +0300 Subject: [PATCH] Add option for the range of characters to use from a font --- scripts/makefont.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/makefont.py b/scripts/makefont.py index 9a239571..64c8e684 100755 --- a/scripts/makefont.py +++ b/scripts/makefont.py @@ -29,11 +29,13 @@ def convert_def(fn): return result -def make_font(fn, size, autohinter, margin, padding): +def make_font(fn, size, ch_range, autohinter, margin, padding): import maketex import os cmd = "ttf2png \"%s\" -o makefont-tmp.png -d makefont-tmp.def -t -p -s %d -m %d -n %d"%(fn, size, margin, padding) + if ch_range: + cmd += " -r %d,%d"%ch_range if autohinter: cmd += " -a" if os.system(cmd): @@ -49,6 +51,9 @@ def make_font(fn, size, autohinter, margin, padding): return result +def parse_range(s): + return tuple(map(int, s.split(',', 1))) + if __name__=="__main__": import sys import argparse @@ -58,10 +63,11 @@ if __name__=="__main__": parser.add_argument("-a", "--autohinter", action="store_const", const=True, default=False, help="Force autohinter") parser.add_argument("-m", "--margin", default=0, type=int, metavar="NUM", help="Margin around image edge in pixels") parser.add_argument("-n", "--padding", default=1, type=int, metavar="NUM", help="Padding between glyphs in pixels") + parser.add_argument("-r", "--range", type=parse_range, metavar="START,END", help="Range of code points to include") parser.add_argument("ttf", metavar="font.ttf", help="TrueType file to read") parser.add_argument("outfile", help="MspGL font file to write") args = parser.parse_args() out = file(args.outfile, "w") - out.write(make_font(args.ttf, args.size, args.autohinter, args.margin, args.padding)) + out.write(make_font(args.ttf, args.size, args.range, args.autohinter, args.margin, args.padding)) -- 2.45.2