From: Mikko Rasa Date: Tue, 14 Jul 2015 21:02:35 +0000 (+0300) Subject: Support more ttf2png options in makefont.py X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=89d3d10b75a42f86b224feb00b20283af66c0b01 Support more ttf2png options in makefont.py Now requires ttf2png 1.1 for the -m and -n options --- diff --git a/scripts/makefont.py b/scripts/makefont.py index 8cc9b17c..9a239571 100755 --- a/scripts/makefont.py +++ b/scripts/makefont.py @@ -29,11 +29,14 @@ def convert_def(fn): return result -def make_font(fn, size): +def make_font(fn, size, autohinter, margin, padding): import maketex import os - if os.system("ttf2png \"%s\" -o makefont-tmp.png -d makefont-tmp.def -t -p -s %d"%(fn, size)): + cmd = "ttf2png \"%s\" -o makefont-tmp.png -d makefont-tmp.def -t -p -s %d -m %d -n %d"%(fn, size, margin, padding) + if autohinter: + cmd += " -a" + if os.system(cmd): raise Exception("Could not execute ttf2png") result = "texture\n{\n" @@ -48,10 +51,17 @@ def make_font(fn, size): if __name__=="__main__": import sys + import argparse - if len(sys.argv)<4: - import os - print "Usage: %s "%os.path.basename(sys.argv[0]) - else: - out = file(sys.argv[2], "w") - out.write(make_font(sys.argv[1], int(sys.argv[3]))) + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--size", default=10, type=int, metavar="NUM", help="Font size in pixels") + 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("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))