changed the command line interface of ttdump and ttcompile ***incompatibly***; changed ttdump -s considerably: now outputs a small file containing references to the individual table file; -d is gone; etc.
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@211 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
64b5c80e80
commit
b1ad7eb139
@ -1,22 +1,17 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""\
|
"""\
|
||||||
usage: ttcompile [-hvbf] [-d output-dir] [-i TTF-input-file] TTX-1 ... TTX-N
|
usage: ttcompile [-hvbf] [-i input-TTF] scr [target]
|
||||||
|
ttcompile [-hvbf] [-i input-TTF] src1 ... srcN directory
|
||||||
|
|
||||||
Translate one or more TTX files (as output by ttDump) to a TrueType
|
Translate one or more TTX files (as output by ttDump) to a TrueType
|
||||||
font file. If a TTX-file argument is a directory instead of a file, all
|
font file.
|
||||||
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.
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h Help: print this message
|
-h Help: print this message
|
||||||
-i TrueType-input-file: specify a TT file to be merged with the TTX file.
|
-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
|
This option is only valid when at most one TTX file is specified.
|
||||||
containing separated TTX files) is specified.
|
|
||||||
-b Don't recalc glyph boundig boxes: use the values in the TTX file as-is.
|
-b Don't recalc glyph boundig boxes: use the values in the TTX file as-is.
|
||||||
-d <output-dir> Specify a directory in which the output file(s)
|
|
||||||
should end up. The directory must exist.
|
|
||||||
-f Force overwriting existing files.
|
-f Force overwriting existing files.
|
||||||
-v Verbose: messages will be written to stdout about what is being done
|
-v Verbose: messages will be written to stdout about what is being done
|
||||||
"""
|
"""
|
||||||
@ -28,6 +23,13 @@ def usage():
|
|||||||
print __doc__
|
print __doc__
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
def makeOutputFileName(xmlPath, outputDir):
|
||||||
|
dir, file = os.path.split(xmlPath)
|
||||||
|
file, ext = os.path.splitext(file)
|
||||||
|
if outputDir:
|
||||||
|
dir = outputDir
|
||||||
|
return os.path.join(dir, file + ".ttf")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
options, args = getopt.getopt(sys.argv[1:], "hvbfd:i:")
|
options, args = getopt.getopt(sys.argv[1:], "hvbfd:i:")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
@ -38,7 +40,6 @@ verbose = 0
|
|||||||
ttInFile = None
|
ttInFile = None
|
||||||
recalcBBoxes = 1
|
recalcBBoxes = 1
|
||||||
forceOverwrite = 0
|
forceOverwrite = 0
|
||||||
outputDir = None
|
|
||||||
|
|
||||||
for option, value in options:
|
for option, value in options:
|
||||||
if option == "-i":
|
if option == "-i":
|
||||||
@ -50,26 +51,35 @@ for option, value in options:
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif option == "-b":
|
elif option == "-b":
|
||||||
recalcBBoxes = 0
|
recalcBBoxes = 0
|
||||||
elif option == "-d":
|
|
||||||
outputDir = value
|
|
||||||
elif option == "-f":
|
elif option == "-f":
|
||||||
forceOverwrite = 1
|
forceOverwrite = 1
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
if ttInFile and len(args) > 1:
|
if ttInFile and len(args) > 2:
|
||||||
print "Must specify exactly one TTX file (or directory) when using -i"
|
print "Must specify exactly one TTX source file when using -i"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
for xmlPath in args:
|
nargs = len(args)
|
||||||
path, ext = os.path.splitext(xmlPath)
|
if nargs == 1:
|
||||||
if outputDir is not None:
|
files = [(args[0], makeOutputFileName(args[0], None))]
|
||||||
fileName = os.path.basename(path)
|
elif nargs == 2:
|
||||||
path = os.path.join(outputDir, fileName)
|
xmlPath = args[0]
|
||||||
ttPath = path + '.ttf'
|
outPath = args[1]
|
||||||
|
print "000", outPath
|
||||||
|
if os.path.isdir(outPath):
|
||||||
|
outPath = makeOutputFileName(xmlPath, outPath)
|
||||||
|
files = [(xmlPath, outPath)]
|
||||||
|
else:
|
||||||
|
outputDir = args[-1]
|
||||||
|
files = []
|
||||||
|
for xmlPath in args[:-1]:
|
||||||
|
files.append((xmlPath, makeOutputFileName(xmlPath, outputDir)))
|
||||||
|
|
||||||
|
|
||||||
|
for xmlPath, ttPath in files:
|
||||||
if not forceOverwrite and os.path.exists(ttPath):
|
if not forceOverwrite and os.path.exists(ttPath):
|
||||||
answer = raw_input('Overwrite "%s"? ' % ttPath)
|
answer = raw_input('Overwrite "%s"? ' % ttPath)
|
||||||
if not answer[:1] in ("Y", "y"):
|
if not answer[:1] in ("Y", "y"):
|
||||||
@ -79,16 +89,7 @@ for xmlPath in args:
|
|||||||
print 'Compiling "%s" to "%s"...' % (xmlPath, ttPath)
|
print 'Compiling "%s" to "%s"...' % (xmlPath, ttPath)
|
||||||
|
|
||||||
tt = ttLib.TTFont(ttInFile, recalcBBoxes=recalcBBoxes, verbose=verbose)
|
tt = ttLib.TTFont(ttInFile, recalcBBoxes=recalcBBoxes, verbose=verbose)
|
||||||
|
tt.importXML(xmlPath)
|
||||||
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)
|
tt.save(ttPath)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
|
68
Tools/ttdump
68
Tools/ttdump
@ -1,7 +1,8 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""\
|
"""\
|
||||||
usage: ttdump [-hvisf] [-t <table>] [-x <table>] [-d <output-dir>] TTF-1 ... TTF-N
|
usage: ttdump [-hvisf] [-t <table>] [-x <table>] src [target]
|
||||||
|
ttdump [-hvisf] [-t <table>] [-x <table>] src1 ... srcN directory
|
||||||
|
|
||||||
Dump one or more TrueType/OpenType fonts as TTX files (an XML-based
|
Dump one or more TrueType/OpenType fonts as TTX files (an XML-based
|
||||||
text format).
|
text format).
|
||||||
@ -15,13 +16,11 @@ usage: ttdump [-hvisf] [-t <table>] [-x <table>] [-d <output-dir>] TTF-1 ... TTF
|
|||||||
pre-program) will be written to the TTX file as assembly
|
pre-program) will be written to the TTX file as assembly
|
||||||
instead of hex data.
|
instead of hex data.
|
||||||
-s Split tables: save the TTX data into separate TTX files per
|
-s Split tables: save the TTX data into separate TTX files per
|
||||||
table. The files will be saved in a directory. The name of this
|
table and write one small TTX file that contains references
|
||||||
directory will be constructed from the input filename (by
|
to the individual table dumps. This file can be used as
|
||||||
dropping the extension) or can be specified by the optional
|
input to ttcompile, as long as the table files are in the
|
||||||
TTX-output-file argument. This option implies -f.
|
same directory.
|
||||||
-f Force overwriting existing files.
|
-f Force overwriting existing files.
|
||||||
-d <output-dir> Specify a directory in which the output file(s)
|
|
||||||
should end up. The directory must exist.
|
|
||||||
-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.
|
||||||
@ -36,6 +35,13 @@ def usage():
|
|||||||
print __doc__
|
print __doc__
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
def makeOutputFileName(ttPath, outputDir):
|
||||||
|
dir, file = os.path.split(ttPath)
|
||||||
|
file, ext = os.path.splitext(file)
|
||||||
|
if outputDir:
|
||||||
|
dir = outputDir
|
||||||
|
return os.path.join(dir, file + ".ttx")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
options, args = getopt.getopt(sys.argv[1:], "hvisft:x:d:")
|
options, args = getopt.getopt(sys.argv[1:], "hvisft:x:d:")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
@ -48,7 +54,7 @@ disassembleInstructions = 0
|
|||||||
forceOverwrite = 0
|
forceOverwrite = 0
|
||||||
tables = []
|
tables = []
|
||||||
skipTables = []
|
skipTables = []
|
||||||
outputDir = None
|
|
||||||
|
|
||||||
for option, value in options:
|
for option, value in options:
|
||||||
if option == "-t":
|
if option == "-t":
|
||||||
@ -65,8 +71,6 @@ for option, value in options:
|
|||||||
# normalize tag
|
# normalize tag
|
||||||
value = value + (4 - len(value)) * " "
|
value = value + (4 - len(value)) * " "
|
||||||
skipTables.append(value)
|
skipTables.append(value)
|
||||||
elif option == "-d":
|
|
||||||
outputDir = value
|
|
||||||
elif option == "-v":
|
elif option == "-v":
|
||||||
verbose = 1
|
verbose = 1
|
||||||
elif option == "-f":
|
elif option == "-f":
|
||||||
@ -86,23 +90,33 @@ if tables and skipTables:
|
|||||||
if not args:
|
if not args:
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
for ttPath in args:
|
|
||||||
path, ext = os.path.splitext(ttPath)
|
nargs = len(args)
|
||||||
if outputDir is not None:
|
if nargs == 1:
|
||||||
fileName = os.path.basename(path)
|
files = [(args[0], makeOutputFileName(args[0], None))]
|
||||||
path = os.path.join(outputDir, fileName)
|
elif nargs == 2:
|
||||||
|
ttPath = args[0]
|
||||||
if splitTables:
|
outPath = args[1]
|
||||||
xmlPath = path
|
if os.path.isdir(outPath):
|
||||||
else:
|
outPath = makeOutputFileName(ttPath, outPath)
|
||||||
xmlPath = path + ".ttx"
|
files = [(ttPath, outPath)]
|
||||||
if not forceOverwrite and os.path.exists(xmlPath):
|
else:
|
||||||
answer = raw_input('Overwrite "%s"? ' % xmlPath)
|
outputDir = args[-1]
|
||||||
if not answer[:1] in ("Y", "y"):
|
files = []
|
||||||
print "skipped."
|
for ttPath in args[:-1]:
|
||||||
continue
|
files.append((ttPath, makeOutputFileName(ttPath, outputDir)))
|
||||||
print 'Dumping "%s" to "%s"...' % (ttPath, xmlPath)
|
|
||||||
|
|
||||||
|
for ttPath, outFile in files:
|
||||||
|
if not forceOverwrite and os.path.exists(outFile):
|
||||||
|
answer = raw_input('Overwrite "%s"? ' % outFile)
|
||||||
|
if not answer[:1] in ("Y", "y"):
|
||||||
|
print "skipped."
|
||||||
|
continue
|
||||||
|
if not os.path.isdir(outFile):
|
||||||
|
os.remove(outFile)
|
||||||
|
print 'Dumping "%s" to "%s"...' % (ttPath, outFile)
|
||||||
tt = ttLib.TTFont(ttPath, 0, verbose=verbose)
|
tt = ttLib.TTFont(ttPath, 0, verbose=verbose)
|
||||||
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables,
|
tt.saveXML(outFile, tables=tables, skipTables=skipTables,
|
||||||
splitTables=splitTables, disassembleInstructions=disassembleInstructions)
|
splitTables=splitTables, disassembleInstructions=disassembleInstructions)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user