1999-12-16 22:04:30 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""\
|
2001-08-09 23:39:05 +00:00
|
|
|
usage: %s [-hvbf] [-d output-dir] [-i TTF-input-file] [TTX-file...]
|
|
|
|
|
|
|
|
Translate a TTX file (as output by ttDump) to a TrueType font file.
|
|
|
|
If a TTX-file argument is a directory instead of a file, all files in
|
2000-01-17 18:49:34 +00:00
|
|
|
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:
|
2001-08-09 23:39:05 +00:00
|
|
|
-h Help: print this message
|
|
|
|
-i TrueType-input-file: specify a TT file to be merged with the TTX file.
|
|
|
|
This option is only valid when at most one TTX file (or directory
|
|
|
|
containing separated TTX files) is specified.
|
2000-01-17 18:49:34 +00:00
|
|
|
-b Don't recalc glyph boundig boxes: use the values in the TTX file as-is.
|
2001-08-09 23:39:05 +00:00
|
|
|
-d <output-dir> Specify a directory in which the output file(s)
|
|
|
|
should end up. The directory must exist.
|
|
|
|
-f Force overwriting existing files.
|
|
|
|
-v Verbose: messages will be written to stdout about what is being done
|
1999-12-16 22:04:30 +00:00
|
|
|
"""
|
2001-08-09 23:39:05 +00:00
|
|
|
|
1999-12-16 22:04:30 +00:00
|
|
|
import sys, os, getopt
|
|
|
|
from fontTools import ttLib
|
|
|
|
|
2001-08-09 23:39:05 +00:00
|
|
|
options, args = getopt.getopt(sys.argv[1:], "hvbfd:i:")
|
1999-12-16 22:04:30 +00:00
|
|
|
|
2001-08-09 23:39:05 +00:00
|
|
|
# default values
|
1999-12-16 22:04:30 +00:00
|
|
|
verbose = 0
|
1999-12-18 18:12:15 +00:00
|
|
|
ttInFile = None
|
|
|
|
recalcBBoxes = 1
|
2001-08-09 23:39:05 +00:00
|
|
|
forceOverwrite = 0
|
|
|
|
outputDir = None
|
|
|
|
|
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
|
2001-08-09 23:39:05 +00:00
|
|
|
elif option == "-d":
|
|
|
|
outputDir = value
|
|
|
|
elif option == "-f":
|
|
|
|
forceOverwrite = 1
|
1999-12-16 22:04:30 +00:00
|
|
|
|
2001-08-09 23:39:05 +00:00
|
|
|
if not args:
|
1999-12-16 22:04:30 +00:00
|
|
|
print __doc__ % sys.argv[0]
|
|
|
|
sys.exit(2)
|
|
|
|
|
2001-08-09 23:39:05 +00:00
|
|
|
if ttInFile and len(args) > 1:
|
|
|
|
print "Must specify exactly one TTX file (or directory) when using -i"
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
|
|
|
|
for xmlPath in args:
|
|
|
|
path, ext = os.path.splitext(xmlPath)
|
|
|
|
if outputDir is not None:
|
|
|
|
fileName = os.path.basename(path)
|
|
|
|
path = os.path.join(outputDir, fileName)
|
|
|
|
ttPath = path + '.ttf'
|
|
|
|
|
|
|
|
if not forceOverwrite and os.path.exists(ttPath):
|
|
|
|
answer = raw_input('Overwrite "%s"? ' % ttPath)
|
|
|
|
if not answer[:1] in ("Y", "y"):
|
|
|
|
print "skipped."
|
|
|
|
continue
|
|
|
|
|
2001-08-09 23:45:32 +00:00
|
|
|
print 'Compiling "%s" to "%s"...' % (xmlPath, ttPath)
|
|
|
|
|
2001-08-09 23:39:05 +00:00
|
|
|
tt = ttLib.TTFont(ttInFile, recalcBBoxes=recalcBBoxes, verbose=verbose)
|
|
|
|
|
|
|
|
if os.path.isdir(xmlPath):
|
|
|
|
import glob
|
|
|
|
files = glob.glob1(xmlPath, "*.ttx")
|
|
|
|
for xmlFile in files:
|
|
|
|
xmlFile = os.path.join(xmlPath, xmlFile)
|
|
|
|
tt.importXML(xmlFile)
|
|
|
|
else:
|
|
|
|
tt.importXML(xmlPath)
|
|
|
|
|
|
|
|
tt.save(ttPath)
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
import time
|
|
|
|
print "%s finished at" % sys.argv[0], time.strftime("%H:%M:%S", time.localtime(time.time()))
|