| 1 |
import logging |
| 2 |
import sys |
| 3 |
from argparse import ArgumentParser |
| 4 |
|
| 5 |
import vttLib |
| 6 |
|
| 7 |
|
| 8 |
def main(args=None): |
| 9 |
parser = ArgumentParser( |
| 10 |
prog="python -m vttLib", |
| 11 |
description="Dump, merge or compile Visual TrueType data with FontTools", |
| 12 |
) |
| 13 |
parser.add_argument("--version", action="version", version=vttLib.__version__) |
| 14 |
parser_group = parser.add_subparsers(title="sub-commands") |
| 15 |
parser_dumpfile = parser_group.add_parser( |
| 16 |
"dumpfile", |
| 17 |
description="Export VTT tables and 'maxp' values from a TTF into a TTX dump", |
| 18 |
) |
| 19 |
parser_mergefile = parser_group.add_parser( |
| 20 |
"mergefile", |
| 21 |
description="Import VTT source data stored in a TTX dump into a TTF.", |
| 22 |
) |
| 23 |
parser_compile = parser_group.add_parser( |
| 24 |
"compile", |
| 25 |
description=( |
| 26 |
"Generate 'fpgm', 'prep', 'cvt ' and 'glyf' programs from VTT assembly." |
| 27 |
), |
| 28 |
) |
| 29 |
parser_dumpfile_from_ufo = parser_group.add_parser( |
| 30 |
"dumpfile_from_ufo", description="Export VTT data from UFO3 data to a TTX dump." |
| 31 |
) |
| 32 |
for subparser in ( |
| 33 |
parser_compile, |
| 34 |
parser_dumpfile, |
| 35 |
parser_mergefile, |
| 36 |
parser_dumpfile_from_ufo, |
| 37 |
): |
| 38 |
group = subparser.add_mutually_exclusive_group(required=False) |
| 39 |
group.add_argument( |
| 40 |
"-v", |
| 41 |
"--verbose", |
| 42 |
action="store_true", |
| 43 |
help="print more messages to console", |
| 44 |
) |
| 45 |
group.add_argument( |
| 46 |
"-q", |
| 47 |
"--quiet", |
| 48 |
action="store_true", |
| 49 |
help="do not print messages to console", |
| 50 |
) |
| 51 |
|
| 52 |
parser_dumpfile.add_argument("infile", metavar="INPUT.ttf") |
| 53 |
parser_dumpfile.add_argument("outfile", nargs="?", metavar="OUTPUT.ttx") |
| 54 |
parser_dumpfile.set_defaults(func=vttLib.vtt_dump_file) |
| 55 |
|
| 56 |
parser_mergefile.add_argument("--keep-cvar", action="store_true") |
| 57 |
parser_mergefile.add_argument("infile", metavar="INPUT.ttx") |
| 58 |
parser_mergefile.add_argument("outfile", metavar="OUTPUT.ttf") |
| 59 |
parser_mergefile.set_defaults(func=vttLib.vtt_merge_file) |
| 60 |
|
| 61 |
parser_compile.add_argument("--keep-cvar", action="store_true", default=False) |
| 62 |
parser_compile.add_argument( |
| 63 |
"infile", |
| 64 |
metavar="INPUT.ttf", |
| 65 |
help="the source TTF font containing VTT TSI* tables", |
| 66 |
) |
| 67 |
parser_compile.add_argument( |
| 68 |
"--ship", |
| 69 |
action="store_true", |
| 70 |
help="remove all the TSI* tables from the output font.", |
| 71 |
) |
| 72 |
parser_compile.set_defaults(func=vttLib.vtt_compile) |
| 73 |
output_group = parser_compile.add_mutually_exclusive_group() |
| 74 |
output_group.add_argument( |
| 75 |
"outfile", |
| 76 |
nargs="?", |
| 77 |
metavar="OUTPUT.ttf", |
| 78 |
help=( |
| 79 |
"the destination TTF with compiled TrueType bytecode (default: " |
| 80 |
'INTPUT + "#{n}.ttf").' |
| 81 |
), |
| 82 |
) |
| 83 |
output_group.add_argument( |
| 84 |
"-i", |
| 85 |
"--inplace", |
| 86 |
metavar=".bak", |
| 87 |
help="save input file in place, and create backup with specified extension", |
| 88 |
) |
| 89 |
output_group.add_argument( |
| 90 |
"-f", |
| 91 |
"--force-overwrite", |
| 92 |
action="store_true", |
| 93 |
help="overwrite existing input file (CAUTION!)", |
| 94 |
) |
| 95 |
|
| 96 |
parser_dumpfile_from_ufo.add_argument("infile", metavar="SOURCE.ufo") |
| 97 |
parser_dumpfile_from_ufo.add_argument("outfile", nargs="?", metavar="OUTPUT.ttx") |
| 98 |
parser_dumpfile_from_ufo.set_defaults(func=vttLib.vtt_move_ufo_data_to_file) |
| 99 |
|
| 100 |
options = parser.parse_args(args) |
| 101 |
|
| 102 |
if "quiet" in options or "verbose" in options: |
| 103 |
logging.basicConfig( |
| 104 |
level=( |
| 105 |
"ERROR" if options.quiet else "DEBUG" if options.verbose else "INFO" |
| 106 |
), |
| 107 |
format="%(name)s: %(levelname)s: %(message)s", |
| 108 |
) |
| 109 |
|
| 110 |
try: |
| 111 |
if "func" in options: |
| 112 |
options.func(**vars(options)) |
| 113 |
else: |
| 114 |
parser.print_help() |
| 115 |
except vttLib.VTTLibArgumentError as e: |
| 116 |
parser.error(e) |
| 117 |
|
| 118 |
|
| 119 |
if __name__ == "__main__": |
| 120 |
sys.exit(main()) |