blob: 921e92883a6eb001099f273e452be37e250bb6c0 [file] [log] [blame]
Just6cc58871999-12-16 22:04:30 +00001#! /usr/bin/env python
2
3"""\
Justab15e071999-12-29 13:10:59 +00004usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
Just08ff1b41999-12-27 19:49:36 +00005 Dump a TrueType font as an XML file. If the XML-output-file argument
6 is omitted, the out put file name will be constructed from the input
7 file name, like so: *.ttf becomes *.xml. Either way, existing files
8 will be overwritten without warning!
9
10 Options:
Just6cc58871999-12-16 22:04:30 +000011 -t <table> specify a table to dump. Multiple -t options
12 are allowed. When no -t option is specified, all tables
13 will be dumped
Just08ff1b41999-12-27 19:49:36 +000014 -v verbose: messages will be written to stdout about what is
15 being done.
Justab15e071999-12-29 13:10:59 +000016 -s split tables: save the XML in a separate XML file per table.
17 The files will be saved in a directory. The name of this
18 directory will be constructed from the input filename (by
19 dropping the extension) or can be specified by the optional
20 XML-output-file argument.
Just6cc58871999-12-16 22:04:30 +000021 -h help: print this message
22"""
23
24import sys, os, getopt
25from fontTools import ttLib
26
Just08ff1b41999-12-27 19:49:36 +000027options, args = getopt.getopt(sys.argv[1:], "shvt:")
Just6cc58871999-12-16 22:04:30 +000028
29verbose = 0
Just08ff1b41999-12-27 19:49:36 +000030splitTables = 0
Just6cc58871999-12-16 22:04:30 +000031tables = []
32for option, value in options:
33 if option == "-t":
34 if len(value) > 4:
35 print "illegal table tag: " + value
36 sys.exit(2)
37 # normalize tag
38 value = value + (4 - len(value)) * " "
39 tables.append(value)
40 elif option == "-v":
41 verbose = 1
42 elif option == "-h":
43 print __doc__ % sys.argv[0]
44 sys.exit(0)
Just08ff1b41999-12-27 19:49:36 +000045 elif option == "-s":
46 splitTables = 1
Just6cc58871999-12-16 22:04:30 +000047
48
49if len(args) == 1:
Justa7b9f291999-12-18 18:11:44 +000050 ttPath = args[0]
Justab15e071999-12-29 13:10:59 +000051 path, ext = os.path.splitext(ttPath)
52 if splitTables:
53 xmlPath = path
54 else:
55 xmlPath = path + '.xml'
Just6cc58871999-12-16 22:04:30 +000056elif len(args) == 2:
Justa7b9f291999-12-18 18:11:44 +000057 ttPath, xmlPath = args
Just6cc58871999-12-16 22:04:30 +000058else:
59 print __doc__ % sys.argv[0]
60 sys.exit(2)
61
Justa7b9f291999-12-18 18:11:44 +000062tt = ttLib.TTFont(ttPath, verbose=verbose)
Just08ff1b41999-12-27 19:49:36 +000063tt.saveXML(xmlPath, tables=tables, splitTables=splitTables)