1999-12-16 22:04:30 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""\
|
2000-01-17 18:49:34 +00:00
|
|
|
usage: %s [-hvs] [-t <table>] [-x <table>] TrueType-file [TTX-output-file]
|
|
|
|
Dump a TrueType font as a TTX file (an XML-based text format). If the
|
|
|
|
TTX-output-file argument is omitted, the out put file name will be
|
|
|
|
constructed from the input file name, like so: *.ttf becomes *.ttx.
|
|
|
|
Either way, existing files will be overwritten without warning!
|
1999-12-27 19:49:36 +00:00
|
|
|
|
|
|
|
Options:
|
1999-12-16 22:04:30 +00:00
|
|
|
-t <table> specify a table to dump. Multiple -t options
|
|
|
|
are allowed. When no -t option is specified, all tables
|
|
|
|
will be dumped
|
2000-01-05 20:41:34 +00:00
|
|
|
-x <table> specify a table to exclude from the dump. Multiple
|
|
|
|
-x options are allowed. -t and -x are mutually exclusive.
|
1999-12-27 19:49:36 +00:00
|
|
|
-v verbose: messages will be written to stdout about what is
|
|
|
|
being done.
|
2000-01-17 18:49:34 +00:00
|
|
|
-s split tables: save the TTX data into separate TTX files per table.
|
1999-12-29 13:10:59 +00:00
|
|
|
The files will be saved in a directory. The name of this
|
|
|
|
directory will be constructed from the input filename (by
|
|
|
|
dropping the extension) or can be specified by the optional
|
2000-01-17 18:49:34 +00:00
|
|
|
TTX-output-file argument.
|
1999-12-16 22:04:30 +00:00
|
|
|
-h help: print this message
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys, os, getopt
|
|
|
|
from fontTools import ttLib
|
|
|
|
|
2000-01-05 20:41:34 +00:00
|
|
|
options, args = getopt.getopt(sys.argv[1:], "shvt:x:")
|
1999-12-16 22:04:30 +00:00
|
|
|
|
|
|
|
verbose = 0
|
1999-12-27 19:49:36 +00:00
|
|
|
splitTables = 0
|
1999-12-16 22:04:30 +00:00
|
|
|
tables = []
|
2000-01-05 20:41:34 +00:00
|
|
|
skipTables = []
|
1999-12-16 22:04:30 +00:00
|
|
|
for option, value in options:
|
|
|
|
if option == "-t":
|
|
|
|
if len(value) > 4:
|
|
|
|
print "illegal table tag: " + value
|
|
|
|
sys.exit(2)
|
|
|
|
# normalize tag
|
|
|
|
value = value + (4 - len(value)) * " "
|
|
|
|
tables.append(value)
|
2000-01-05 20:41:34 +00:00
|
|
|
elif option == "-x":
|
|
|
|
if len(value) > 4:
|
|
|
|
print "illegal table tag: " + value
|
|
|
|
sys.exit(2)
|
|
|
|
# normalize tag
|
|
|
|
value = value + (4 - len(value)) * " "
|
|
|
|
skipTables.append(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-27 19:49:36 +00:00
|
|
|
elif option == "-s":
|
|
|
|
splitTables = 1
|
1999-12-16 22:04:30 +00:00
|
|
|
|
2000-01-05 20:41:34 +00:00
|
|
|
if tables and skipTables:
|
|
|
|
print "-t and -x options are mutually exlusive"
|
|
|
|
sys.exit(2)
|
1999-12-16 22:04:30 +00:00
|
|
|
|
|
|
|
if len(args) == 1:
|
1999-12-18 18:11:44 +00:00
|
|
|
ttPath = args[0]
|
1999-12-29 13:10:59 +00:00
|
|
|
path, ext = os.path.splitext(ttPath)
|
|
|
|
if splitTables:
|
|
|
|
xmlPath = path
|
|
|
|
else:
|
2000-01-17 18:49:34 +00:00
|
|
|
xmlPath = path + '.ttx'
|
1999-12-16 22:04:30 +00:00
|
|
|
elif len(args) == 2:
|
1999-12-18 18:11:44 +00:00
|
|
|
ttPath, xmlPath = args
|
1999-12-16 22:04:30 +00:00
|
|
|
else:
|
|
|
|
print __doc__ % sys.argv[0]
|
|
|
|
sys.exit(2)
|
|
|
|
|
1999-12-18 18:11:44 +00:00
|
|
|
tt = ttLib.TTFont(ttPath, verbose=verbose)
|
2000-01-05 20:41:34 +00:00
|
|
|
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables, splitTables=splitTables)
|