fonttools/tt2xml.py
Just ab15e0757e When using -s (splitting files), save the xml files in a separate directory instead of in the same dir as the font file.
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@43 4cde692c-a291-49d1-8350-778aa11640f8
1999-12-29 13:10:59 +00:00

64 lines
1.7 KiB
Python

#! /usr/bin/env python
"""\
usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
Dump a TrueType font as an XML file. If the XML-output-file argument
is omitted, the out put file name will be constructed from the input
file name, like so: *.ttf becomes *.xml. Either way, existing files
will be overwritten without warning!
Options:
-t <table> specify a table to dump. Multiple -t options
are allowed. When no -t option is specified, all tables
will be dumped
-v verbose: messages will be written to stdout about what is
being done.
-s split tables: save the XML in a separate XML file 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
XML-output-file argument.
-h help: print this message
"""
import sys, os, getopt
from fontTools import ttLib
options, args = getopt.getopt(sys.argv[1:], "shvt:")
verbose = 0
splitTables = 0
tables = []
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 == "-v":
verbose = 1
elif option == "-h":
print __doc__ % sys.argv[0]
sys.exit(0)
elif option == "-s":
splitTables = 1
if len(args) == 1:
ttPath = args[0]
path, ext = os.path.splitext(ttPath)
if splitTables:
xmlPath = path
else:
xmlPath = path + '.xml'
elif len(args) == 2:
ttPath, xmlPath = args
else:
print __doc__ % sys.argv[0]
sys.exit(2)
tt = ttLib.TTFont(ttPath, verbose=verbose)
tt.saveXML(xmlPath, tables=tables, splitTables=splitTables)