• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from __future__ import print_function, division, absolute_import
2from fontTools.misc.py23 import *
3from fontTools.ttLib import TTFont
4from fontTools.feaLib.builder import addOpenTypeFeatures, Builder
5from fontTools import configLogger
6from fontTools.misc.cliTools import makeOutputFileName
7import sys
8import argparse
9import logging
10
11
12log = logging.getLogger("fontTools.feaLib")
13
14
15def main(args=None):
16    parser = argparse.ArgumentParser(
17        description="Use fontTools to compile OpenType feature files (*.fea).")
18    parser.add_argument(
19        "input_fea", metavar="FEATURES", help="Path to the feature file")
20    parser.add_argument(
21        "input_font", metavar="INPUT_FONT", help="Path to the input font")
22    parser.add_argument(
23        "-o", "--output", dest="output_font", metavar="OUTPUT_FONT",
24        help="Path to the output font.")
25    parser.add_argument(
26        "-t", "--tables", metavar="TABLE_TAG", choices=Builder.supportedTables,
27        nargs='+', help="Specify the table(s) to be built.")
28    parser.add_argument(
29        "-v", "--verbose", help="increase the logger verbosity. Multiple -v "
30        "options are allowed.", action="count", default=0)
31    options = parser.parse_args(args)
32
33    levels = ["WARNING", "INFO", "DEBUG"]
34    configLogger(level=levels[min(len(levels) - 1, options.verbose)])
35
36    output_font = options.output_font or makeOutputFileName(options.input_font)
37    log.info("Compiling features to '%s'" % (output_font))
38
39    font = TTFont(options.input_font)
40    addOpenTypeFeatures(font, options.input_fea, tables=options.tables)
41    font.save(output_font)
42
43
44if __name__ == '__main__':
45    sys.exit(main())
46