blob: 1d504791ad344493f77d58d9d01d2795595354de [file] [log] [blame]
Just6cc58871999-12-16 22:04:30 +00001#! /usr/bin/env python
2
3"""\
Justaf5694e2000-02-01 15:53:37 +00004usage: %s [-hvis] [-t <table>] [-x <table>] TrueType-file [TTX-output-file]
Just9b79e522000-01-17 18:49:34 +00005 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:
Justaf5694e2000-02-01 15:53:37 +000011 -h help: print this message
Just08ff1b41999-12-27 19:49:36 +000012 -v verbose: messages will be written to stdout about what is
13 being done.
Justaf5694e2000-02-01 15:53:37 +000014 -i disassemble TT instructions: when this option is given, all
15 TrueType programs (glyph programs, the font program and the
16 pre-program) will be written to the TTX file as assembly instead
17 of hex data.
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.
Justaf5694e2000-02-01 15:53:37 +000023 -t <table> specify a table to dump. Multiple -t options
24 are allowed. When no -t option is specified, all tables
25 will be dumped
26 -x <table> specify a table to exclude from the dump. Multiple
27 -x options are allowed. -t and -x are mutually exclusive.
Just6cc58871999-12-16 22:04:30 +000028"""
29
30import sys, os, getopt
31from fontTools import ttLib
32
Justaf5694e2000-02-01 15:53:37 +000033options, args = getopt.getopt(sys.argv[1:], "hvist:x:")
Just6cc58871999-12-16 22:04:30 +000034
35verbose = 0
Just08ff1b41999-12-27 19:49:36 +000036splitTables = 0
Justaf5694e2000-02-01 15:53:37 +000037disassembleInstructions = 0
Just6cc58871999-12-16 22:04:30 +000038tables = []
Juste9af6182000-01-05 20:41:34 +000039skipTables = []
Just6cc58871999-12-16 22:04:30 +000040for option, value in options:
41 if option == "-t":
42 if len(value) > 4:
43 print "illegal table tag: " + value
44 sys.exit(2)
45 # normalize tag
46 value = value + (4 - len(value)) * " "
47 tables.append(value)
Juste9af6182000-01-05 20:41:34 +000048 elif option == "-x":
49 if len(value) > 4:
50 print "illegal table tag: " + value
51 sys.exit(2)
52 # normalize tag
53 value = value + (4 - len(value)) * " "
54 skipTables.append(value)
Just6cc58871999-12-16 22:04:30 +000055 elif option == "-v":
56 verbose = 1
57 elif option == "-h":
58 print __doc__ % sys.argv[0]
59 sys.exit(0)
Just08ff1b41999-12-27 19:49:36 +000060 elif option == "-s":
61 splitTables = 1
Justaf5694e2000-02-01 15:53:37 +000062 elif option == "-i":
63 disassembleInstructions = 1
Just6cc58871999-12-16 22:04:30 +000064
Juste9af6182000-01-05 20:41:34 +000065if tables and skipTables:
66 print "-t and -x options are mutually exlusive"
67 sys.exit(2)
Just6cc58871999-12-16 22:04:30 +000068
69if len(args) == 1:
Justa7b9f291999-12-18 18:11:44 +000070 ttPath = args[0]
Justab15e071999-12-29 13:10:59 +000071 path, ext = os.path.splitext(ttPath)
72 if splitTables:
73 xmlPath = path
74 else:
Just9b79e522000-01-17 18:49:34 +000075 xmlPath = path + '.ttx'
Just6cc58871999-12-16 22:04:30 +000076elif len(args) == 2:
Justa7b9f291999-12-18 18:11:44 +000077 ttPath, xmlPath = args
Just6cc58871999-12-16 22:04:30 +000078else:
79 print __doc__ % sys.argv[0]
80 sys.exit(2)
81
Justaf5694e2000-02-01 15:53:37 +000082tt = ttLib.TTFont(ttPath, 0, verbose=verbose)
83tt.saveXML(xmlPath, tables=tables, skipTables=skipTables,
84 splitTables=splitTables, disassembleInstructions=disassembleInstructions)
85