Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """\ |
| 4 | usage: %s [-h] [-v] [-t <table>] TrueType-file [XML-output-file] |
| 5 | -t <table> specify a table to dump. Multiple -t options |
| 6 | are allowed. When no -t option is specified, all tables |
| 7 | will be dumped |
| 8 | -v verbose: messages will be written to stdout about what is being done |
| 9 | -h help: print this message |
| 10 | """ |
| 11 | |
| 12 | import sys, os, getopt |
| 13 | from fontTools import ttLib |
| 14 | |
| 15 | options, args = getopt.getopt(sys.argv[1:], "hvt:") |
| 16 | |
| 17 | verbose = 0 |
| 18 | tables = [] |
| 19 | for option, value in options: |
| 20 | if option == "-t": |
| 21 | if len(value) > 4: |
| 22 | print "illegal table tag: " + value |
| 23 | sys.exit(2) |
| 24 | # normalize tag |
| 25 | value = value + (4 - len(value)) * " " |
| 26 | tables.append(value) |
| 27 | elif option == "-v": |
| 28 | verbose = 1 |
| 29 | elif option == "-h": |
| 30 | print __doc__ % sys.argv[0] |
| 31 | sys.exit(0) |
| 32 | |
| 33 | |
| 34 | if len(args) == 1: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 35 | ttPath = args[0] |
| 36 | name, ext = os.path.splitext(ttPath) |
| 37 | xmlPath = name + '.xml' |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 38 | elif len(args) == 2: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 39 | ttPath, xmlPath = args |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 40 | else: |
| 41 | print __doc__ % sys.argv[0] |
| 42 | sys.exit(2) |
| 43 | |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 44 | tt = ttLib.TTFont(ttPath, verbose=verbose) |
| 45 | tt.saveXML(xmlPath, tables=tables) |