Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """\ |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame^] | 4 | usage: %s [-h] [-v] [-s] [-t <table>] TrueType-file [XML-output-file] |
| 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. |
| 16 | -s split tables: save the XML in a separate XML file per table. |
| 17 | The names of these files will be constructed from the |
| 18 | XML-output-file name as follows: *.xml becomes *.<tag>.xml |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 19 | -h help: print this message |
| 20 | """ |
| 21 | |
| 22 | import sys, os, getopt |
| 23 | from fontTools import ttLib |
| 24 | |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame^] | 25 | options, args = getopt.getopt(sys.argv[1:], "shvt:") |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 26 | |
| 27 | verbose = 0 |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame^] | 28 | splitTables = 0 |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 29 | tables = [] |
| 30 | for option, value in options: |
| 31 | if option == "-t": |
| 32 | if len(value) > 4: |
| 33 | print "illegal table tag: " + value |
| 34 | sys.exit(2) |
| 35 | # normalize tag |
| 36 | value = value + (4 - len(value)) * " " |
| 37 | tables.append(value) |
| 38 | elif option == "-v": |
| 39 | verbose = 1 |
| 40 | elif option == "-h": |
| 41 | print __doc__ % sys.argv[0] |
| 42 | sys.exit(0) |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame^] | 43 | elif option == "-s": |
| 44 | splitTables = 1 |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | if len(args) == 1: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 48 | ttPath = args[0] |
| 49 | name, ext = os.path.splitext(ttPath) |
| 50 | xmlPath = name + '.xml' |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 51 | elif len(args) == 2: |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 52 | ttPath, xmlPath = args |
Just | 6cc5887 | 1999-12-16 22:04:30 +0000 | [diff] [blame] | 53 | else: |
| 54 | print __doc__ % sys.argv[0] |
| 55 | sys.exit(2) |
| 56 | |
Just | a7b9f29 | 1999-12-18 18:11:44 +0000 | [diff] [blame] | 57 | tt = ttLib.TTFont(ttPath, verbose=verbose) |
Just | 08ff1b4 | 1999-12-27 19:49:36 +0000 | [diff] [blame^] | 58 | tt.saveXML(xmlPath, tables=tables, splitTables=splitTables) |