Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """\ |
Just | ab15e07 | 1999-12-29 13:10:59 +0000 | [diff] [blame] | 4 | usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file] |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 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: |
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 | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 14 | -v verbose: messages will be written to stdout about what is |
| 15 | being done. |
Just | ab15e07 | 1999-12-29 13:10:59 +0000 | [diff] [blame] | 16 | -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. |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 21 | -h help: print this message |
| 22 | """ |
| 23 | |
| 24 | import sys, os, getopt |
| 25 | from fontTools import ttLib |
| 26 | |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 27 | options, args = getopt.getopt(sys.argv[1:], "shvt:") |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 28 | |
| 29 | verbose = 0 |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 30 | splitTables = 0 |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 31 | tables = [] |
| 32 | for 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) |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 45 | elif option == "-s": |
| 46 | splitTables = 1 |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | if len(args) == 1: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 50 | ttPath = args[0] |
Just | ab15e07 | 1999-12-29 13:10:59 +0000 | [diff] [blame] | 51 | path, ext = os.path.splitext(ttPath) |
| 52 | if splitTables: |
| 53 | xmlPath = path |
| 54 | else: |
| 55 | xmlPath = path + '.xml' |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 56 | elif len(args) == 2: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 57 | ttPath, xmlPath = args |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 58 | else: |
| 59 | print __doc__ % sys.argv[0] |
| 60 | sys.exit(2) |
| 61 | |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 62 | tt = ttLib.TTFont(ttPath, verbose=verbose) |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame] | 63 | tt.saveXML(xmlPath, tables=tables, splitTables=splitTables) |