1999-12-16 22:04:30 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""\
|
1999-12-18 18:12:15 +00:00
|
|
|
usage: %s [-h] [-v] [-i TrueType-input-file] XML-file [TrueType-output-file]
|
1999-12-27 19:52:01 +00:00
|
|
|
Translate an XML file (as output by tt2xml.py) to a TrueType font file.
|
|
|
|
If the XML-file argument is a directory instead of a file, all files
|
|
|
|
ending in '.xml' will be merged into one TrueType file. This is mostly
|
|
|
|
useful in conjunction with the -s option of tt2xml.py.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-i TrueType-input-file: specify a TT file to be merged with the XML file(s)
|
1999-12-16 22:04:30 +00:00
|
|
|
-v verbose: messages will be written to stdout about what is being done
|
1999-12-18 18:12:15 +00:00
|
|
|
-b Don't recalc glyph boundig boxes: use the values in the XML file as-is.
|
1999-12-16 22:04:30 +00:00
|
|
|
-h help: print this message
|
|
|
|
"""
|
|
|
|
import sys, os, getopt
|
|
|
|
from fontTools import ttLib
|
|
|
|
|
1999-12-18 18:12:15 +00:00
|
|
|
options, args = getopt.getopt(sys.argv[1:], "hvi:b")
|
1999-12-16 22:04:30 +00:00
|
|
|
|
|
|
|
verbose = 0
|
1999-12-18 18:12:15 +00:00
|
|
|
ttInFile = None
|
|
|
|
recalcBBoxes = 1
|
1999-12-16 22:04:30 +00:00
|
|
|
for option, value in options:
|
|
|
|
if option == "-i":
|
1999-12-18 18:12:15 +00:00
|
|
|
ttInFile = value
|
1999-12-16 22:04:30 +00:00
|
|
|
elif option == "-v":
|
|
|
|
verbose = 1
|
|
|
|
elif option == "-h":
|
|
|
|
print __doc__ % sys.argv[0]
|
|
|
|
sys.exit(0)
|
1999-12-18 18:12:15 +00:00
|
|
|
elif option == "-b":
|
|
|
|
recalcBBoxes = 0
|
1999-12-16 22:04:30 +00:00
|
|
|
|
|
|
|
if len(args) == 1:
|
1999-12-18 18:12:15 +00:00
|
|
|
xmlPath = args[0]
|
|
|
|
name, ext = os.path.splitext(xmlPath)
|
|
|
|
ttPath = name + '.ttf'
|
1999-12-16 22:04:30 +00:00
|
|
|
elif len(args) == 2:
|
1999-12-18 18:12:15 +00:00
|
|
|
xmlPath, ttPath = args
|
1999-12-16 22:04:30 +00:00
|
|
|
else:
|
|
|
|
print __doc__ % sys.argv[0]
|
|
|
|
sys.exit(2)
|
|
|
|
|
1999-12-23 12:31:19 +00:00
|
|
|
tt = ttLib.TTFont(ttInFile, recalcBBoxes=recalcBBoxes, verbose=verbose)
|
1999-12-27 19:52:01 +00:00
|
|
|
|
|
|
|
if os.path.isdir(xmlPath):
|
|
|
|
import glob
|
|
|
|
os.chdir(xmlPath)
|
|
|
|
for xmlFile in glob.glob("*.xml"):
|
|
|
|
tt.importXML(xmlFile)
|
|
|
|
else:
|
|
|
|
tt.importXML(xmlPath)
|
1999-12-23 12:31:19 +00:00
|
|
|
tt.save(ttPath)
|
1999-12-27 15:40:43 +00:00
|
|
|
del tt
|
|
|
|
if verbose:
|
|
|
|
import time
|
|
|
|
print "%s finished at" % sys.argv[0], time.strftime("%H:%M:%S", time.localtime(time.time()))
|