Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """\ |
Just | 9b79e52 | 2000-01-17 18:49:34 +0000 | [diff] [blame^] | 4 | usage: %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! |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 9 | |
| 10 | Options: |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 11 | -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 |
Just | e9af618 | 2000-01-05 20:41:34 +0000 | [diff] [blame] | 14 | -x <table> specify a table to exclude from the dump. Multiple |
| 15 | -x options are allowed. -t and -x are mutually exclusive. |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 16 | -v verbose: messages will be written to stdout about what is |
| 17 | being done. |
Just | 9b79e52 | 2000-01-17 18:49:34 +0000 | [diff] [blame^] | 18 | -s split tables: save the TTX data into separate TTX files per table. |
Just | ab15e07 | 1999-12-29 13:10:59 +0000 | [diff] [blame] | 19 | 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 |
Just | 9b79e52 | 2000-01-17 18:49:34 +0000 | [diff] [blame^] | 22 | TTX-output-file argument. |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 23 | -h help: print this message |
| 24 | """ |
| 25 | |
| 26 | import sys, os, getopt |
| 27 | from fontTools import ttLib |
| 28 | |
Just | e9af618 | 2000-01-05 20:41:34 +0000 | [diff] [blame] | 29 | options, args = getopt.getopt(sys.argv[1:], "shvt:x:") |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 30 | |
| 31 | verbose = 0 |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 32 | splitTables = 0 |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 33 | tables = [] |
Just | e9af618 | 2000-01-05 20:41:34 +0000 | [diff] [blame] | 34 | skipTables = [] |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 35 | for 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) |
Just | e9af618 | 2000-01-05 20:41:34 +0000 | [diff] [blame] | 43 | 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) |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 50 | elif option == "-v": |
| 51 | verbose = 1 |
| 52 | elif option == "-h": |
| 53 | print __doc__ % sys.argv[0] |
| 54 | sys.exit(0) |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 55 | elif option == "-s": |
| 56 | splitTables = 1 |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 57 | |
Just | e9af618 | 2000-01-05 20:41:34 +0000 | [diff] [blame] | 58 | if tables and skipTables: |
| 59 | print "-t and -x options are mutually exlusive" |
| 60 | sys.exit(2) |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 61 | |
| 62 | if len(args) == 1: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 63 | ttPath = args[0] |
Just | ab15e07 | 1999-12-29 13:10:59 +0000 | [diff] [blame] | 64 | path, ext = os.path.splitext(ttPath) |
| 65 | if splitTables: |
| 66 | xmlPath = path |
| 67 | else: |
Just | 9b79e52 | 2000-01-17 18:49:34 +0000 | [diff] [blame^] | 68 | xmlPath = path + '.ttx' |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 69 | elif len(args) == 2: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 70 | ttPath, xmlPath = args |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 71 | else: |
| 72 | print __doc__ % sys.argv[0] |
| 73 | sys.exit(2) |
| 74 | |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 75 | tt = ttLib.TTFont(ttPath, verbose=verbose) |
Just | e9af618 | 2000-01-05 20:41:34 +0000 | [diff] [blame] | 76 | tt.saveXML(xmlPath, tables=tables, skipTables=skipTables, splitTables=splitTables) |