blob: 9d0ea1befabdaef2fe89933139f0d666ef74c4d9 [file] [log] [blame]
Just6cc58871999-12-16 22:04:30 +00001#! /usr/bin/env python
2
3"""\
Just9b79e522000-01-17 18:49:34 +00004usage: %s [-hvs] [-t <table>] [-x <table>] TrueType-file [TTX-output-file]
5 Dump a TrueType font as a TTX file (an XML-based text format). If the
6 TTX-output-file argument is omitted, the out put file name will be
7 constructed from the input file name, like so: *.ttf becomes *.ttx.
8 Either way, existing files will be overwritten without warning!
Just08ff1b41999-12-27 19:49:36 +00009
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
Juste9af6182000-01-05 20:41:34 +000014 -x <table> specify a table to exclude from the dump. Multiple
15 -x options are allowed. -t and -x are mutually exclusive.
Just08ff1b41999-12-27 19:49:36 +000016 -v verbose: messages will be written to stdout about what is
17 being done.
Just9b79e522000-01-17 18:49:34 +000018 -s split tables: save the TTX data into separate TTX files per table.
Justab15e071999-12-29 13:10:59 +000019 The files will be saved in a directory. The name of this
20 directory will be constructed from the input filename (by
21 dropping the extension) or can be specified by the optional
Just9b79e522000-01-17 18:49:34 +000022 TTX-output-file argument.
Just6cc58871999-12-16 22:04:30 +000023 -h help: print this message
24"""
25
26import sys, os, getopt
27from fontTools import ttLib
28
Juste9af6182000-01-05 20:41:34 +000029options, args = getopt.getopt(sys.argv[1:], "shvt:x:")
Just6cc58871999-12-16 22:04:30 +000030
31verbose = 0
Just08ff1b41999-12-27 19:49:36 +000032splitTables = 0
Just6cc58871999-12-16 22:04:30 +000033tables = []
Juste9af6182000-01-05 20:41:34 +000034skipTables = []
Just6cc58871999-12-16 22:04:30 +000035for option, value in options:
36 if option == "-t":
37 if len(value) > 4:
38 print "illegal table tag: " + value
39 sys.exit(2)
40 # normalize tag
41 value = value + (4 - len(value)) * " "
42 tables.append(value)
Juste9af6182000-01-05 20:41:34 +000043 elif option == "-x":
44 if len(value) > 4:
45 print "illegal table tag: " + value
46 sys.exit(2)
47 # normalize tag
48 value = value + (4 - len(value)) * " "
49 skipTables.append(value)
Just6cc58871999-12-16 22:04:30 +000050 elif option == "-v":
51 verbose = 1
52 elif option == "-h":
53 print __doc__ % sys.argv[0]
54 sys.exit(0)
Just08ff1b41999-12-27 19:49:36 +000055 elif option == "-s":
56 splitTables = 1
Just6cc58871999-12-16 22:04:30 +000057
Juste9af6182000-01-05 20:41:34 +000058if tables and skipTables:
59 print "-t and -x options are mutually exlusive"
60 sys.exit(2)
Just6cc58871999-12-16 22:04:30 +000061
62if len(args) == 1:
Justa7b9f291999-12-18 18:11:44 +000063 ttPath = args[0]
Justab15e071999-12-29 13:10:59 +000064 path, ext = os.path.splitext(ttPath)
65 if splitTables:
66 xmlPath = path
67 else:
Just9b79e522000-01-17 18:49:34 +000068 xmlPath = path + '.ttx'
Just6cc58871999-12-16 22:04:30 +000069elif len(args) == 2:
Justa7b9f291999-12-18 18:11:44 +000070 ttPath, xmlPath = args
Just6cc58871999-12-16 22:04:30 +000071else:
72 print __doc__ % sys.argv[0]
73 sys.exit(2)
74
Justa7b9f291999-12-18 18:11:44 +000075tt = ttLib.TTFont(ttPath, verbose=verbose)
Juste9af6182000-01-05 20:41:34 +000076tt.saveXML(xmlPath, tables=tables, skipTables=skipTables, splitTables=splitTables)