diff options
Diffstat (limited to 'Lib/fontTools/mtiLib/__init__.py')
-rw-r--r-- | Lib/fontTools/mtiLib/__init__.py | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/Lib/fontTools/mtiLib/__init__.py b/Lib/fontTools/mtiLib/__init__.py index beec5cb5..667a216d 100644 --- a/Lib/fontTools/mtiLib/__init__.py +++ b/Lib/fontTools/mtiLib/__init__.py @@ -6,9 +6,6 @@ # http://monotype.github.io/OpenType_Table_Source/otl_source.html # https://github.com/Monotype/OpenType_Table_Source/ -from __future__ import print_function, division, absolute_import -from __future__ import unicode_literals -from fontTools.misc.py23 import * from fontTools import ttLib from fontTools.ttLib.tables._c_m_a_p import cmap_classes from fontTools.ttLib.tables import otTables as ot @@ -856,7 +853,7 @@ def parseLookup(lines, tableTag, font, lookupMap=None): lookup.SubTable = subtables lookup.SubTableCount = len(lookup.SubTable) - if lookup.SubTableCount is 0: + if lookup.SubTableCount == 0: # Remove this return when following is fixed: # https://github.com/fonttools/fonttools/issues/789 return None @@ -1148,11 +1145,33 @@ class Tokenizer(object): return line def build(f, font, tableTag=None): + """Convert a Monotype font layout file to an OpenType layout object + + A font object must be passed, but this may be a "dummy" font; it is only + used for sorting glyph sets when making coverage tables and to hold the + OpenType layout table while it is being built. + + Args: + f: A file object. + font (TTFont): A font object. + tableTag (string): If provided, asserts that the file contains data for the + given OpenType table. + + Returns: + An object representing the table. (e.g. ``table_G_S_U_B_``) + """ lines = Tokenizer(f) return parseTable(lines, font, tableTag=tableTag) def main(args=None, font=None): + """Convert a FontDame OTL file to TTX XML. + + Writes XML output to stdout. + + Args: + args: Command line arguments (``--font``, ``--table``, input files). + """ import sys from fontTools import configLogger from fontTools.misc.testTools import MockFont @@ -1165,17 +1184,31 @@ def main(args=None, font=None): # comment this out to enable debug messages from mtiLib's logger # log.setLevel(logging.DEBUG) + import argparse + parser = argparse.ArgumentParser( + "fonttools mtiLib", + description=main.__doc__, + ) + + parser.add_argument('--font', '-f', metavar='FILE', dest="font", + help="Input TTF files (used for glyph classes and sorting coverage tables)") + parser.add_argument('--table', '-t', metavar='TABLE', dest="tableTag", + help="Table to fill (sniffed from input file if not provided)") + parser.add_argument('inputs', metavar='FILE', type=str, nargs='+', + help="Input FontDame .txt files") + + args = parser.parse_args(args) + if font is None: - font = MockFont() + if args.font: + font = ttLib.TTFont(args.font) + else: + font = MockFont() - tableTag = None - if args[0].startswith('-t'): - tableTag = args[0][2:] - del args[0] - for f in args: + for f in args.inputs: log.debug("Processing %s", f) with open(f, 'rt', encoding="utf-8") as f: - table = build(f, font, tableTag=tableTag) + table = build(f, font, tableTag=args.tableTag) blob = table.compile(font) # Make sure it compiles decompiled = table.__class__() decompiled.decompile(blob, font) # Make sure it decompiles! |