1999-12-16 22:04:30 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""\
|
2000-01-17 18:49:34 +00:00
|
|
|
usage: %s [-hvb] [-i TrueType-input-file] TTX-file [TrueType-output-file]
|
|
|
|
Translate an TTX file (as output by ttDump.py) to a TrueType font file.
|
|
|
|
If the TTX-file argument is a directory instead of a file, all files in
|
|
|
|
that directory ending in '.ttx' will be merged into one TrueType file.
|
|
|
|
This is mostly useful in conjunction with the -s option of ttDump.py.
|
1999-12-27 19:52:01 +00:00
|
|
|
|
|
|
|
Options:
|
2000-01-17 18:49:34 +00:00
|
|
|
-i TrueType-input-file: specify a TT file to be merged with the TTX file(s)
|
1999-12-16 22:04:30 +00:00
|
|
|
-v verbose: messages will be written to stdout about what is being done
|
2000-01-17 18:49:34 +00:00
|
|
|
-b Don't recalc glyph boundig boxes: use the values in the TTX 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
|
1999-12-29 13:09:37 +00:00
|
|
|
oldDir = os.getcwd()
|
1999-12-27 19:52:01 +00:00
|
|
|
os.chdir(xmlPath)
|
2000-01-17 18:49:34 +00:00
|
|
|
files = glob.glob("*.ttx")
|
1999-12-29 13:09:37 +00:00
|
|
|
os.chdir(oldDir)
|
|
|
|
for xmlFile in files:
|
|
|
|
xmlFile = os.path.join(xmlPath, xmlFile)
|
1999-12-27 19:52:01 +00:00
|
|
|
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()))
|