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"
if __name__=="__main__":
import sys
+ import argparse
- if len(sys.argv)<4:
- import os
- print "Usage: %s <font.ttf> <outfile> <size>"%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))