blob: 7cebfb180ea7c9c8922b9174182da7b8137d3d86 [file] [log] [blame]
Just6cc58871999-12-16 22:04:30 +00001#! /usr/bin/env python
2
3"""\
Just08ff1b41999-12-27 19:49:36 +00004usage: %s [-h] [-v] [-s] [-t <table>] TrueType-file [XML-output-file]
5 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.
16 -s split tables: save the XML in a separate XML file per table.
17 The names of these files will be constructed from the
18 XML-output-file name as follows: *.xml becomes *.<tag>.xml
Just6cc58871999-12-16 22:04:30 +000019 -h help: print this message
20"""
21
22import sys, os, getopt
23from fontTools import ttLib
24
Just08ff1b41999-12-27 19:49:36 +000025options, args = getopt.getopt(sys.argv[1:], "shvt:")
Just6cc58871999-12-16 22:04:30 +000026
27verbose = 0
Just08ff1b41999-12-27 19:49:36 +000028splitTables = 0
Just6cc58871999-12-16 22:04:30 +000029tables = []
30for option, value in options:
31 if option == "-t":
32 if len(value) > 4:
33 print "illegal table tag: " + value
34 sys.exit(2)
35 # normalize tag
36 value = value + (4 - len(value)) * " "
37 tables.append(value)
38 elif option == "-v":
39 verbose = 1
40 elif option == "-h":
41 print __doc__ % sys.argv[0]
42 sys.exit(0)
Just08ff1b41999-12-27 19:49:36 +000043 elif option == "-s":
44 splitTables = 1
Just6cc58871999-12-16 22:04:30 +000045
46
47if len(args) == 1:
Justa7b9f291999-12-18 18:11:44 +000048 ttPath = args[0]
49 name, ext = os.path.splitext(ttPath)
50 xmlPath = name + '.xml'
Just6cc58871999-12-16 22:04:30 +000051elif len(args) == 2:
Justa7b9f291999-12-18 18:11:44 +000052 ttPath, xmlPath = args
Just6cc58871999-12-16 22:04:30 +000053else:
54 print __doc__ % sys.argv[0]
55 sys.exit(2)
56
Justa7b9f291999-12-18 18:11:44 +000057tt = ttLib.TTFont(ttPath, verbose=verbose)
Just08ff1b41999-12-27 19:49:36 +000058tt.saveXML(xmlPath, tables=tables, splitTables=splitTables)