jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 1 | """\ |
| 2 | usage: ttx [options] inputfile1 [... inputfileN] |
| 3 | |
| 4 | TTX %s -- From OpenType To XML And Back |
| 5 | |
| 6 | If an input file is a TrueType or OpenType font file, it will be |
| 7 | dumped to an TTX file (an XML-based text format). |
| 8 | If an input file is a TTX file, it will be compiled to a TrueType |
| 9 | or OpenType font file. |
| 10 | |
| 11 | Output files are created so they are unique: an existing file is |
pabs3 | ca75e43 | 2011-10-30 12:26:09 +0000 | [diff] [blame] | 12 | never overwritten. |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 13 | |
| 14 | General options: |
| 15 | -h Help: print this message |
| 16 | -d <outputfolder> Specify a directory where the output files are |
| 17 | to be created. |
pabs3 | 5f41933 | 2013-06-22 06:47:34 +0000 | [diff] [blame] | 18 | -o <outputfile> Specify a file to write the output to. |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 19 | -v Verbose: more messages will be written to stdout about what |
| 20 | is being done. |
Dave Crossland | b158597 | 2013-09-04 13:16:39 +0100 | [diff] [blame] | 21 | -q Quiet: No messages will be written to stdout about what |
| 22 | is being done. |
jvr | 823f8cd | 2006-10-21 14:12:38 +0000 | [diff] [blame] | 23 | -a allow virtual glyphs ID's on compile or decompile. |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 24 | |
| 25 | Dump options: |
| 26 | -l List table info: instead of dumping to a TTX file, list some |
| 27 | minimal info about each table. |
| 28 | -t <table> Specify a table to dump. Multiple -t options |
| 29 | are allowed. When no -t option is specified, all tables |
| 30 | will be dumped. |
| 31 | -x <table> Specify a table to exclude from the dump. Multiple |
| 32 | -x options are allowed. -t and -x are mutually exclusive. |
| 33 | -s Split tables: save the TTX data into separate TTX files per |
| 34 | table and write one small TTX file that contains references |
| 35 | to the individual table dumps. This file can be used as |
| 36 | input to ttx, as long as the table files are in the |
| 37 | same directory. |
| 38 | -i Do NOT disassemble TT instructions: when this option is given, |
| 39 | all TrueType programs (glyph programs, the font program and the |
| 40 | pre-program) will be written to the TTX file as hex data |
| 41 | instead of assembly. This saves some time and makes the TTX |
| 42 | file smaller. |
Matt Fontaine | 7baa136 | 2013-08-09 13:25:15 -0700 | [diff] [blame] | 43 | -z <format> Specify a bitmap data export option for EBDT: |
| 44 | {'raw', 'row', 'bitwise', 'extfile'} or for the CBDT: |
| 45 | {'raw', 'extfile'} Each option does one of the following: |
| 46 | -z raw |
| 47 | * export the bitmap data as a hex dump |
| 48 | -z row |
| 49 | * export each row as hex data |
| 50 | -z bitwise |
| 51 | * export each row as binary in an ASCII art style |
| 52 | -z extfile |
| 53 | * export the data as external files with XML refences |
| 54 | If no export format is specified 'raw' format is used. |
jvr | 1bcc11d | 2008-03-01 09:42:58 +0000 | [diff] [blame] | 55 | -e Don't ignore decompilation errors, but show a full traceback |
| 56 | and abort. |
pabs3 | 0a6dea0 | 2009-11-08 15:53:24 +0000 | [diff] [blame] | 57 | -y <number> Select font number for TrueType Collection, |
pabs3 | 7e91e77 | 2009-02-22 08:55:00 +0000 | [diff] [blame] | 58 | starting from 0. |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 59 | |
| 60 | Compile options: |
| 61 | -m Merge with TrueType-input-file: specify a TrueType or OpenType |
| 62 | font file to be merged with the TTX file. This option is only |
| 63 | valid when at most one TTX file is specified. |
pabs3 | ca75e43 | 2011-10-30 12:26:09 +0000 | [diff] [blame] | 64 | -b Don't recalc glyph bounding boxes: use the values in the TTX |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 65 | file as-is. |
| 66 | """ |
| 67 | |
| 68 | |
Behdad Esfahbod | 1ae2959 | 2014-01-14 15:07:50 +0800 | [diff] [blame] | 69 | from __future__ import print_function, division, absolute_import |
Behdad Esfahbod | 30e691e | 2013-11-27 17:27:45 -0500 | [diff] [blame] | 70 | from fontTools.misc.py23 import * |
Olivier Berten | 70343cc | 2013-11-19 10:32:09 +0100 | [diff] [blame] | 71 | from fontTools.ttLib import TTFont, TTLibError |
jvr | 45d1f3b | 2008-03-01 11:34:54 +0000 | [diff] [blame] | 72 | from fontTools.misc.macCreatorType import getMacCreatorAndType |
Behdad Esfahbod | 30e691e | 2013-11-27 17:27:45 -0500 | [diff] [blame] | 73 | import os |
| 74 | import sys |
| 75 | import getopt |
| 76 | import re |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 77 | |
| 78 | def usage(): |
Behdad Esfahbod | 153ec40 | 2013-12-04 01:15:46 -0500 | [diff] [blame] | 79 | from fontTools import version |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 80 | print(__doc__ % version) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 81 | sys.exit(2) |
| 82 | |
jvr | 2e838ce | 2003-08-22 18:50:44 +0000 | [diff] [blame] | 83 | |
Behdad Esfahbod | eac107f | 2013-11-01 00:43:06 +0000 | [diff] [blame] | 84 | numberAddedRE = re.compile("#\d+$") |
pabs3 | 278d4d8 | 2013-06-22 08:16:33 +0000 | [diff] [blame] | 85 | opentypeheaderRE = re.compile('''sfntVersion=['"]OTTO["']''') |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 86 | |
| 87 | def makeOutputFileName(input, outputDir, extension): |
Behdad Esfahbod | 153ec40 | 2013-12-04 01:15:46 -0500 | [diff] [blame] | 88 | dirName, fileName = os.path.split(input) |
| 89 | fileName, ext = os.path.splitext(fileName) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 90 | if outputDir: |
Behdad Esfahbod | 153ec40 | 2013-12-04 01:15:46 -0500 | [diff] [blame] | 91 | dirName = outputDir |
| 92 | fileName = numberAddedRE.split(fileName)[0] |
| 93 | output = os.path.join(dirName, fileName + extension) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 94 | n = 1 |
| 95 | while os.path.exists(output): |
Behdad Esfahbod | 153ec40 | 2013-12-04 01:15:46 -0500 | [diff] [blame] | 96 | output = os.path.join(dirName, fileName + "#" + repr(n) + extension) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 97 | n = n + 1 |
| 98 | return output |
| 99 | |
| 100 | |
Behdad Esfahbod | e388db5 | 2013-11-28 14:26:58 -0500 | [diff] [blame] | 101 | class Options(object): |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 102 | |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 103 | listTables = False |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 104 | outputDir = None |
pabs3 | fb37a24 | 2013-06-22 06:43:01 +0000 | [diff] [blame] | 105 | outputFile = None |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 106 | verbose = False |
| 107 | quiet = False |
| 108 | splitTables = False |
| 109 | disassembleInstructions = True |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 110 | mergeFile = None |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 111 | recalcBBoxes = True |
| 112 | allowVID = False |
jvr | 1bcc11d | 2008-03-01 09:42:58 +0000 | [diff] [blame] | 113 | ignoreDecompileErrors = True |
Matt Fontaine | 7baa136 | 2013-08-09 13:25:15 -0700 | [diff] [blame] | 114 | bitmapGlyphDataFormat = 'raw' |
jvr | 1bcc11d | 2008-03-01 09:42:58 +0000 | [diff] [blame] | 115 | |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 116 | def __init__(self, rawOptions, numFiles): |
| 117 | self.onlyTables = [] |
| 118 | self.skipTables = [] |
pabs3 | 7e91e77 | 2009-02-22 08:55:00 +0000 | [diff] [blame] | 119 | self.fontNumber = -1 |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 120 | for option, value in rawOptions: |
| 121 | # general options |
| 122 | if option == "-h": |
Behdad Esfahbod | 153ec40 | 2013-12-04 01:15:46 -0500 | [diff] [blame] | 123 | from fontTools import version |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 124 | print(__doc__ % version) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 125 | sys.exit(0) |
| 126 | elif option == "-d": |
| 127 | if not os.path.isdir(value): |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 128 | print("The -d option value must be an existing directory") |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 129 | sys.exit(2) |
| 130 | self.outputDir = value |
pabs3 | fb37a24 | 2013-06-22 06:43:01 +0000 | [diff] [blame] | 131 | elif option == "-o": |
| 132 | self.outputFile = value |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 133 | elif option == "-v": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 134 | self.verbose = True |
Dave Crossland | b158597 | 2013-09-04 13:16:39 +0100 | [diff] [blame] | 135 | elif option == "-q": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 136 | self.quiet = True |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 137 | # dump options |
| 138 | elif option == "-l": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 139 | self.listTables = True |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 140 | elif option == "-t": |
| 141 | self.onlyTables.append(value) |
| 142 | elif option == "-x": |
| 143 | self.skipTables.append(value) |
| 144 | elif option == "-s": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 145 | self.splitTables = True |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 146 | elif option == "-i": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 147 | self.disassembleInstructions = False |
Matt Fontaine | 7baa136 | 2013-08-09 13:25:15 -0700 | [diff] [blame] | 148 | elif option == "-z": |
| 149 | validOptions = ('raw', 'row', 'bitwise', 'extfile') |
| 150 | if value not in validOptions: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 151 | print("-z does not allow %s as a format. Use %s" % (option, validOptions)) |
Matt Fontaine | 7baa136 | 2013-08-09 13:25:15 -0700 | [diff] [blame] | 152 | sys.exit(2) |
| 153 | self.bitmapGlyphDataFormat = value |
pabs3 | 7e91e77 | 2009-02-22 08:55:00 +0000 | [diff] [blame] | 154 | elif option == "-y": |
| 155 | self.fontNumber = int(value) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 156 | # compile options |
| 157 | elif option == "-m": |
| 158 | self.mergeFile = value |
| 159 | elif option == "-b": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 160 | self.recalcBBoxes = False |
jvr | 823f8cd | 2006-10-21 14:12:38 +0000 | [diff] [blame] | 161 | elif option == "-a": |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 162 | self.allowVID = True |
jvr | 1bcc11d | 2008-03-01 09:42:58 +0000 | [diff] [blame] | 163 | elif option == "-e": |
| 164 | self.ignoreDecompileErrors = False |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 165 | if self.onlyTables and self.skipTables: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 166 | print("-t and -x options are mutually exclusive") |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 167 | sys.exit(2) |
| 168 | if self.mergeFile and numFiles > 1: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 169 | print("Must specify exactly one TTX source file when using -m") |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 170 | sys.exit(2) |
| 171 | |
| 172 | |
| 173 | def ttList(input, output, options): |
Behdad Esfahbod | 188f2a3 | 2013-11-24 19:04:25 -0500 | [diff] [blame] | 174 | ttf = TTFont(input, fontNumber=options.fontNumber, lazy=True) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 175 | reader = ttf.reader |
Behdad Esfahbod | ac1b435 | 2013-11-27 04:15:34 -0500 | [diff] [blame] | 176 | tags = sorted(reader.keys()) |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 177 | print('Listing table info for "%s":' % input) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 178 | format = " %4s %10s %7s %7s" |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 179 | print(format % ("tag ", " checksum", " length", " offset")) |
| 180 | print(format % ("----", "----------", "-------", "-------")) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 181 | for tag in tags: |
| 182 | entry = reader.tables[tag] |
Behdad Esfahbod | 7cc6d27 | 2013-11-27 04:00:15 -0500 | [diff] [blame] | 183 | checkSum = int(entry.checkSum) |
jvr | e0912bb | 2004-12-24 15:59:35 +0000 | [diff] [blame] | 184 | if checkSum < 0: |
Behdad Esfahbod | ecbe4c8 | 2013-11-27 03:37:29 -0500 | [diff] [blame] | 185 | checkSum = checkSum + 0x100000000 |
Behdad Esfahbod | 14fb031 | 2013-11-27 05:47:34 -0500 | [diff] [blame] | 186 | checksum = "0x%08X" % checkSum |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 187 | print(format % (tag, checksum, entry.length, entry.offset)) |
| 188 | print() |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 189 | ttf.close() |
| 190 | |
| 191 | |
| 192 | def ttDump(input, output, options): |
Dave Crossland | b158597 | 2013-09-04 13:16:39 +0100 | [diff] [blame] | 193 | if not options.quiet: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 194 | print('Dumping "%s" to "%s"...' % (input, output)) |
jvr | 1bcc11d | 2008-03-01 09:42:58 +0000 | [diff] [blame] | 195 | ttf = TTFont(input, 0, verbose=options.verbose, allowVID=options.allowVID, |
Dave Crossland | d7efd56 | 2013-09-04 14:51:16 +0100 | [diff] [blame] | 196 | quiet=options.quiet, |
pabs3 | 7e91e77 | 2009-02-22 08:55:00 +0000 | [diff] [blame] | 197 | ignoreDecompileErrors=options.ignoreDecompileErrors, |
| 198 | fontNumber=options.fontNumber) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 199 | ttf.saveXML(output, |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 200 | quiet=options.quiet, |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 201 | tables=options.onlyTables, |
Behdad Esfahbod | 38fdae6 | 2013-11-24 18:49:35 -0500 | [diff] [blame] | 202 | skipTables=options.skipTables, |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 203 | splitTables=options.splitTables, |
Matt Fontaine | 7baa136 | 2013-08-09 13:25:15 -0700 | [diff] [blame] | 204 | disassembleInstructions=options.disassembleInstructions, |
| 205 | bitmapGlyphDataFormat=options.bitmapGlyphDataFormat) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 206 | ttf.close() |
| 207 | |
| 208 | |
| 209 | def ttCompile(input, output, options): |
Dave Crossland | 85af40e | 2013-09-04 13:30:21 +0100 | [diff] [blame] | 210 | if not options.quiet: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 211 | print('Compiling "%s" to "%s"...' % (input, output)) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 212 | ttf = TTFont(options.mergeFile, |
| 213 | recalcBBoxes=options.recalcBBoxes, |
jvr | 823f8cd | 2006-10-21 14:12:38 +0000 | [diff] [blame] | 214 | verbose=options.verbose, allowVID=options.allowVID) |
Dave Crossland | 85af40e | 2013-09-04 13:30:21 +0100 | [diff] [blame] | 215 | ttf.importXML(input, quiet=options.quiet) |
Behdad Esfahbod | 95f795f | 2013-12-20 21:52:28 -0500 | [diff] [blame] | 216 | ttf.save(output) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 217 | |
| 218 | if options.verbose: |
| 219 | import time |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 220 | print("finished at", time.strftime("%H:%M:%S", time.localtime(time.time()))) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 221 | |
| 222 | |
| 223 | def guessFileType(fileName): |
jvr | 2e838ce | 2003-08-22 18:50:44 +0000 | [diff] [blame] | 224 | base, ext = os.path.splitext(fileName) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 225 | try: |
| 226 | f = open(fileName, "rb") |
| 227 | except IOError: |
| 228 | return None |
jvr | 45d1f3b | 2008-03-01 11:34:54 +0000 | [diff] [blame] | 229 | cr, tp = getMacCreatorAndType(fileName) |
| 230 | if tp in ("sfnt", "FFIL"): |
| 231 | return "TTF" |
| 232 | if ext == ".dfont": |
| 233 | return "TTF" |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 234 | header = f.read(256) |
Behdad Esfahbod | ac4672e | 2013-11-27 16:44:53 -0500 | [diff] [blame] | 235 | head = Tag(header[:4]) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 236 | if head == "OTTO": |
| 237 | return "OTF" |
pabs3 | 7e91e77 | 2009-02-22 08:55:00 +0000 | [diff] [blame] | 238 | elif head == "ttcf": |
| 239 | return "TTC" |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 240 | elif head in ("\0\1\0\0", "true"): |
| 241 | return "TTF" |
Behdad Esfahbod | ac4672e | 2013-11-27 16:44:53 -0500 | [diff] [blame] | 242 | elif head == "wOFF": |
Behdad Esfahbod | 8c35239 | 2013-11-26 12:58:28 -0500 | [diff] [blame] | 243 | return "WOFF" |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 244 | elif head.lower() == "<?xm": |
Behdad Esfahbod | c076261 | 2013-11-28 06:46:59 -0500 | [diff] [blame] | 245 | # Use 'latin1' because that can't fail. |
| 246 | header = tostr(header, 'latin1') |
Behdad Esfahbod | eac107f | 2013-11-01 00:43:06 +0000 | [diff] [blame] | 247 | if opentypeheaderRE.search(header): |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 248 | return "OTX" |
| 249 | else: |
| 250 | return "TTX" |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 251 | return None |
| 252 | |
| 253 | |
| 254 | def parseOptions(args): |
| 255 | try: |
Dave Crossland | 5ffb91e | 2013-09-04 14:49:37 +0100 | [diff] [blame] | 256 | rawOptions, files = getopt.getopt(args, "ld:o:vqht:x:sim:z:baey:") |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 257 | except getopt.GetoptError: |
| 258 | usage() |
| 259 | |
| 260 | if not files: |
| 261 | usage() |
| 262 | |
| 263 | options = Options(rawOptions, len(files)) |
| 264 | jobs = [] |
| 265 | |
| 266 | for input in files: |
| 267 | tp = guessFileType(input) |
Behdad Esfahbod | 8c35239 | 2013-11-26 12:58:28 -0500 | [diff] [blame] | 268 | if tp in ("OTF", "TTF", "TTC", "WOFF"): |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 269 | extension = ".ttx" |
| 270 | if options.listTables: |
| 271 | action = ttList |
| 272 | else: |
| 273 | action = ttDump |
| 274 | elif tp == "TTX": |
| 275 | extension = ".ttf" |
| 276 | action = ttCompile |
| 277 | elif tp == "OTX": |
| 278 | extension = ".otf" |
| 279 | action = ttCompile |
| 280 | else: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 281 | print('Unknown file type: "%s"' % input) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 282 | continue |
| 283 | |
pabs3 | fb37a24 | 2013-06-22 06:43:01 +0000 | [diff] [blame] | 284 | if options.outputFile: |
| 285 | output = options.outputFile |
| 286 | else: |
| 287 | output = makeOutputFileName(input, options.outputDir, extension) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 288 | jobs.append((action, input, output)) |
jvr | 2921bb2 | 2002-09-12 20:05:23 +0000 | [diff] [blame] | 289 | return jobs, options |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 290 | |
| 291 | |
| 292 | def process(jobs, options): |
| 293 | for action, input, output in jobs: |
| 294 | action(input, output, options) |
| 295 | |
| 296 | |
| 297 | def waitForKeyPress(): |
| 298 | """Force the DOS Prompt window to stay open so the user gets |
| 299 | a chance to see what's wrong.""" |
| 300 | import msvcrt |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 301 | print('(Hit any key to exit)') |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 302 | while not msvcrt.kbhit(): |
| 303 | pass |
| 304 | |
| 305 | |
| 306 | def main(args): |
| 307 | jobs, options = parseOptions(args) |
| 308 | try: |
| 309 | process(jobs, options) |
| 310 | except KeyboardInterrupt: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 311 | print("(Cancelled.)") |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 312 | except SystemExit: |
| 313 | if sys.platform == "win32": |
| 314 | waitForKeyPress() |
| 315 | else: |
| 316 | raise |
Behdad Esfahbod | 223273f | 2013-11-27 05:09:00 -0500 | [diff] [blame] | 317 | except TTLibError as e: |
Behdad Esfahbod | 3ec6a25 | 2013-11-27 04:57:33 -0500 | [diff] [blame] | 318 | print("Error:",e) |
jvr | 1c803b6 | 2002-09-12 17:33:12 +0000 | [diff] [blame] | 319 | except: |
| 320 | if sys.platform == "win32": |
| 321 | import traceback |
| 322 | traceback.print_exc() |
| 323 | waitForKeyPress() |
| 324 | else: |
| 325 | raise |
| 326 | |
| 327 | |
| 328 | if __name__ == "__main__": |
| 329 | main(sys.argv[1:]) |