first step of changing the command line usage to something more
sensible: it is now possible to do batches, as in ./ttDump.py *.ttf This is not b/w compatible. (The new -d option is not yet implemented) git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@148 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
c0cd826447
commit
3860d6e470
40
ttDump.py
40
ttDump.py
@ -1,11 +1,8 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""\
|
"""\
|
||||||
usage: %s [-hvis] [-t <table>] [-x <table>] TrueType-file [TTX-output-file]
|
usage: %s [-hvisf] [-t <table>] [-x <table>] [-d <output-dir>] TrueType-file(s)
|
||||||
Dump a TrueType font as a TTX file (an XML-based text format). If the
|
Dump TrueType fonts as TTX files (an XML-based text format).
|
||||||
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!
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h help: print this message
|
-h help: print this message
|
||||||
@ -20,9 +17,10 @@ usage: %s [-hvis] [-t <table>] [-x <table>] TrueType-file [TTX-output-file]
|
|||||||
directory will be constructed from the input filename (by
|
directory will be constructed from the input filename (by
|
||||||
dropping the extension) or can be specified by the optional
|
dropping the extension) or can be specified by the optional
|
||||||
TTX-output-file argument.
|
TTX-output-file argument.
|
||||||
|
-f force overwriting existing files.
|
||||||
-t <table> specify a table to dump. Multiple -t options
|
-t <table> specify a table to dump. Multiple -t options
|
||||||
are allowed. When no -t option is specified, all tables
|
are allowed. When no -t option is specified, all tables
|
||||||
will be dumped
|
will be dumped.
|
||||||
-x <table> specify a table to exclude from the dump. Multiple
|
-x <table> specify a table to exclude from the dump. Multiple
|
||||||
-x options are allowed. -t and -x are mutually exclusive.
|
-x options are allowed. -t and -x are mutually exclusive.
|
||||||
"""
|
"""
|
||||||
@ -30,11 +28,12 @@ usage: %s [-hvis] [-t <table>] [-x <table>] TrueType-file [TTX-output-file]
|
|||||||
import sys, os, getopt
|
import sys, os, getopt
|
||||||
from fontTools import ttLib
|
from fontTools import ttLib
|
||||||
|
|
||||||
options, args = getopt.getopt(sys.argv[1:], "hvist:x:")
|
options, args = getopt.getopt(sys.argv[1:], "hvisft:x:")
|
||||||
|
|
||||||
verbose = 0
|
verbose = 0
|
||||||
splitTables = 0
|
splitTables = 0
|
||||||
disassembleInstructions = 0
|
disassembleInstructions = 0
|
||||||
|
forceOverwrite = 0
|
||||||
tables = []
|
tables = []
|
||||||
skipTables = []
|
skipTables = []
|
||||||
for option, value in options:
|
for option, value in options:
|
||||||
@ -54,6 +53,8 @@ for option, value in options:
|
|||||||
skipTables.append(value)
|
skipTables.append(value)
|
||||||
elif option == "-v":
|
elif option == "-v":
|
||||||
verbose = 1
|
verbose = 1
|
||||||
|
elif option == "-f":
|
||||||
|
forceOverwrite = 1
|
||||||
elif option == "-h":
|
elif option == "-h":
|
||||||
print __doc__ % sys.argv[0]
|
print __doc__ % sys.argv[0]
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@ -66,20 +67,23 @@ if tables and skipTables:
|
|||||||
print "-t and -x options are mutually exlusive"
|
print "-t and -x options are mutually exlusive"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
if len(args) == 1:
|
if not args:
|
||||||
ttPath = args[0]
|
print __doc__ % sys.argv[0]
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
for ttPath in args:
|
||||||
path, ext = os.path.splitext(ttPath)
|
path, ext = os.path.splitext(ttPath)
|
||||||
if splitTables:
|
if splitTables:
|
||||||
xmlPath = path
|
xmlPath = path
|
||||||
else:
|
else:
|
||||||
xmlPath = path + '.ttx'
|
xmlPath = path + ".ttx"
|
||||||
elif len(args) == 2:
|
if not forceOverwrite and os.path.exists(xmlPath):
|
||||||
ttPath, xmlPath = args
|
answer = raw_input('Overwrite "%s"? ' % xmlPath)
|
||||||
else:
|
if not answer[:1] in ("Y", "y"):
|
||||||
print __doc__ % sys.argv[0]
|
print "skipped."
|
||||||
sys.exit(2)
|
continue
|
||||||
|
print 'Dumping "%s" to "%s"...' % (ttPath, xmlPath)
|
||||||
tt = ttLib.TTFont(ttPath, 0, verbose=verbose)
|
tt = ttLib.TTFont(ttPath, 0, verbose=verbose)
|
||||||
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables,
|
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables,
|
||||||
splitTables=splitTables, disassembleInstructions=disassembleInstructions)
|
splitTables=splitTables, disassembleInstructions=disassembleInstructions)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user