new place and names for scripts/tools
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@192 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
93d048bf2f
commit
96aa48ab91
95
Tools/ttcompile
Executable file
95
Tools/ttcompile
Executable file
@ -0,0 +1,95 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""\
|
||||
usage: ttcompile [-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
|
||||
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:
|
||||
-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.
|
||||
-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.
|
||||
-v Verbose: messages will be written to stdout about what is being done
|
||||
"""
|
||||
|
||||
import sys, os, getopt
|
||||
from fontTools import ttLib
|
||||
|
||||
def usage():
|
||||
print __doc__
|
||||
sys.exit(2)
|
||||
|
||||
try:
|
||||
options, args = getopt.getopt(sys.argv[1:], "hvbfd:i:")
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
|
||||
# default values
|
||||
verbose = 0
|
||||
ttInFile = None
|
||||
recalcBBoxes = 1
|
||||
forceOverwrite = 0
|
||||
outputDir = None
|
||||
|
||||
for option, value in options:
|
||||
if option == "-i":
|
||||
ttInFile = value
|
||||
elif option == "-v":
|
||||
verbose = 1
|
||||
elif option == "-h":
|
||||
print __doc__
|
||||
sys.exit(0)
|
||||
elif option == "-b":
|
||||
recalcBBoxes = 0
|
||||
elif option == "-d":
|
||||
outputDir = value
|
||||
elif option == "-f":
|
||||
forceOverwrite = 1
|
||||
|
||||
if not args:
|
||||
usage()
|
||||
|
||||
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
|
||||
|
||||
print 'Compiling "%s" to "%s"...' % (xmlPath, ttPath)
|
||||
|
||||
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()))
|
107
Tools/ttdump
Executable file
107
Tools/ttdump
Executable file
@ -0,0 +1,107 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""\
|
||||
usage: ttdump [-hvisf] [-t <table>] [-x <table>] [-d <output-dir>] TrueType-file(s)
|
||||
|
||||
Dump TrueType fonts as TTX files (an XML-based text format).
|
||||
|
||||
Options:
|
||||
-h Help: print this message
|
||||
-v Verbose: messages will be written to stdout about what is
|
||||
being done.
|
||||
-i Disassemble TT instructions: when this option is given, all
|
||||
TrueType programs (glyph programs, the font program and the
|
||||
pre-program) will be written to the TTX file as assembly instead
|
||||
of hex data.
|
||||
-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
|
||||
directory will be constructed from the input filename (by
|
||||
dropping the extension) or can be specified by the optional
|
||||
TTX-output-file argument. This option implies -f.
|
||||
-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
|
||||
are allowed. When no -t option is specified, all tables
|
||||
will be dumped.
|
||||
-x <table> Specify a table to exclude from the dump. Multiple
|
||||
-x options are allowed. -t and -x are mutually exclusive.
|
||||
"""
|
||||
|
||||
import sys, os, getopt
|
||||
from fontTools import ttLib
|
||||
|
||||
def usage():
|
||||
print __doc__
|
||||
sys.exit(2)
|
||||
|
||||
try:
|
||||
options, args = getopt.getopt(sys.argv[1:], "hvisft:x:d:")
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
|
||||
# default values
|
||||
verbose = 0
|
||||
splitTables = 0
|
||||
disassembleInstructions = 0
|
||||
forceOverwrite = 0
|
||||
tables = []
|
||||
skipTables = []
|
||||
outputDir = None
|
||||
|
||||
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)
|
||||
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)
|
||||
elif option == "-d":
|
||||
outputDir = value
|
||||
elif option == "-v":
|
||||
verbose = 1
|
||||
elif option == "-f":
|
||||
forceOverwrite = 1
|
||||
elif option == "-h":
|
||||
print __doc__
|
||||
sys.exit(0)
|
||||
elif option == "-s":
|
||||
splitTables = 1
|
||||
elif option == "-i":
|
||||
disassembleInstructions = 1
|
||||
|
||||
if tables and skipTables:
|
||||
print "-t and -x options are mutually exlusive"
|
||||
sys.exit(2)
|
||||
|
||||
if not args:
|
||||
usage()
|
||||
|
||||
for ttPath in args:
|
||||
path, ext = os.path.splitext(ttPath)
|
||||
if outputDir is not None:
|
||||
fileName = os.path.basename(path)
|
||||
path = os.path.join(outputDir, fileName)
|
||||
|
||||
if splitTables:
|
||||
xmlPath = path
|
||||
else:
|
||||
xmlPath = path + ".ttx"
|
||||
if not forceOverwrite and os.path.exists(xmlPath):
|
||||
answer = raw_input('Overwrite "%s"? ' % xmlPath)
|
||||
if not answer[:1] in ("Y", "y"):
|
||||
print "skipped."
|
||||
continue
|
||||
print 'Dumping "%s" to "%s"...' % (ttPath, xmlPath)
|
||||
tt = ttLib.TTFont(ttPath, 0, verbose=verbose)
|
||||
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables,
|
||||
splitTables=splitTables, disassembleInstructions=disassembleInstructions)
|
||||
|
34
Tools/ttlist
Executable file
34
Tools/ttlist
Executable file
@ -0,0 +1,34 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""\
|
||||
usage: ttlist TrueType-file(s)
|
||||
List basic info for each table in one or more TrueType font files."""
|
||||
|
||||
import sys, getopt
|
||||
from fontTools.ttLib import TTFont
|
||||
|
||||
def usage():
|
||||
print __doc__
|
||||
sys.exit(2)
|
||||
|
||||
try:
|
||||
options, args = getopt.getopt(sys.argv[1:], "")
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
|
||||
if not args:
|
||||
usage()
|
||||
|
||||
for fileName in args:
|
||||
ttf = TTFont(fileName)
|
||||
reader = ttf.reader
|
||||
tags = reader.keys()
|
||||
tags.sort()
|
||||
print 'Info for "%s":' % fileName
|
||||
for tag in tags:
|
||||
entry = reader.tables[tag]
|
||||
print
|
||||
print " Tag:", `tag`
|
||||
print " Checksum:", hex(entry.checkSum)
|
||||
print " Length:", entry.length
|
||||
print " Offset:", entry.offset
|
Loading…
x
Reference in New Issue
Block a user