예제 #1
0
def gameToFont(charstring_directory_path, ttxFilePath, out_path, mutable_game,
               smaller, feature_name):
    # type: (str,str, str, bpy.SceneTreeOutputType, bool, str) -> None

    # Don't be a jerk. Leave the logo intact
    # I've made the entire software
    # free as in freedom, all I ask is that my logo stays in the front, so I
    # can attract more people to work on open source software to make the
    # world a better place.
    game = add_code_relay_logo(mutable_game)
    parseGame(out_game=game, smaller=smaller)
    nodeId_to_list_of_frame_blank_glyph_ID, blank_glyph_ranges = get_nodeId_to_list_of_frame_blank_glyph_ID_map(
        game)
    featureFile = createFeatureFile(game,
                                    nodeId_to_list_of_frame_blank_glyph_ID,
                                    blank_glyph_ranges, feature_name)

    xmlOutput = addCharStringsToTTX(charstring_directory_path,
                                    game,
                                    nodeId_to_list_of_frame_blank_glyph_ID,
                                    smaller,
                                    ttxFilePath=ttxFilePath)

    tt = TTFont()
    tt.importXML(StringIO(xmlOutput))
    builder.addOpenTypeFeaturesFromString(tt, featureFile)
    # set the required feature index to the one we will cre
    for scriptRecord in tt['GSUB'].table.ScriptList.ScriptRecord:
        scriptRecord.Script.DefaultLangSys.ReqFeatureIndex = 0

    cff = tt['CFF ']
    cffTable = cff.cff['Fontemon']
    cffTable.Private.defaultWidthX = 0
    cffTable.Private.nominalWidthX = 0
    tt.save(out_path)
예제 #2
0
def ttCompile(input, output, options):
    log.info('Compiling "%s" to "%s"...' % (input, output))
    if options.useZopfli:
        from fontemon_blender_addon.fontTools.ttLib import sfnt
        sfnt.USE_ZOPFLI = True
    ttf = TTFont(options.mergeFile,
                 flavor=options.flavor,
                 recalcBBoxes=options.recalcBBoxes,
                 recalcTimestamp=options.recalcTimestamp,
                 allowVID=options.allowVID)
    ttf.importXML(input)

    if options.recalcTimestamp is None and 'head' in ttf:
        # use TTX file modification time for head "modified" timestamp
        mtime = os.path.getmtime(input)
        ttf['head'].modified = timestampSinceEpoch(mtime)

    ttf.save(output)
def main(args=None):
    """Optimize a font's GDEF variation store"""
    from argparse import ArgumentParser
    from fontemon_blender_addon.fontTools import configLogger
    from fontemon_blender_addon.fontTools.ttLib import TTFont
    from fontemon_blender_addon.fontTools.ttLib.tables.otBase import OTTableWriter

    parser = ArgumentParser(prog='varLib.varStore', description=main.__doc__)
    parser.add_argument('fontfile')
    parser.add_argument('outfile', nargs='?')
    options = parser.parse_args(args)

    # TODO: allow user to configure logging via command-line options
    configLogger(level="INFO")

    fontfile = options.fontfile
    outfile = options.outfile

    font = TTFont(fontfile)
    gdef = font['GDEF']
    store = gdef.table.VarStore

    writer = OTTableWriter()
    store.compile(writer, font)
    size = len(writer.getAllData())
    print("Before: %7d bytes" % size)

    varidx_map = store.optimize()

    gdef.table.remap_device_varidxes(varidx_map)
    if 'GPOS' in font:
        font['GPOS'].table.remap_device_varidxes(varidx_map)

    writer = OTTableWriter()
    store.compile(writer, font)
    size = len(writer.getAllData())
    print("After:  %7d bytes" % size)

    if outfile is not None:
        font.save(outfile)
def main(args=None):
    """Add features from a feature file (.fea) into a OTF font"""
    parser = argparse.ArgumentParser(
        description=
        "Use fontemon_blender_addon.fontTools to compile OpenType feature files (*.fea)."
    )
    parser.add_argument("input_fea",
                        metavar="FEATURES",
                        help="Path to the feature file")
    parser.add_argument("input_font",
                        metavar="INPUT_FONT",
                        help="Path to the input font")
    parser.add_argument(
        "-o",
        "--output",
        dest="output_font",
        metavar="OUTPUT_FONT",
        help="Path to the output font.",
    )
    parser.add_argument(
        "-t",
        "--tables",
        metavar="TABLE_TAG",
        choices=Builder.supportedTables,
        nargs="+",
        help="Specify the table(s) to be built.",
    )
    parser.add_argument(
        "-d",
        "--debug",
        action="store_true",
        help="Add source-level debugging information to font.",
    )
    parser.add_argument(
        "-v",
        "--verbose",
        help="increase the logger verbosity. Multiple -v "
        "options are allowed.",
        action="count",
        default=0,
    )
    parser.add_argument("--traceback",
                        help="show traceback for exceptions.",
                        action="store_true")
    options = parser.parse_args(args)

    levels = ["WARNING", "INFO", "DEBUG"]
    configLogger(level=levels[min(len(levels) - 1, options.verbose)])

    output_font = options.output_font or makeOutputFileName(options.input_font)
    log.info("Compiling features to '%s'" % (output_font))

    font = TTFont(options.input_font)
    try:
        addOpenTypeFeatures(font,
                            options.input_fea,
                            tables=options.tables,
                            debug=options.debug)
    except FeatureLibError as e:
        if options.traceback:
            raise
        log.error(e)
    font.save(output_font)
예제 #5
0
def main(args=None):
    """Instantiate a variation font"""
    from fontemon_blender_addon.fontTools import configLogger
    import argparse

    parser = argparse.ArgumentParser(
        "fontemon_blender_addon.fontTools varLib.mutator",
        description="Instantiate a variable font")
    parser.add_argument("input",
                        metavar="INPUT.ttf",
                        help="Input variable TTF file.")
    parser.add_argument(
        "locargs",
        metavar="AXIS=LOC",
        nargs="*",
        help="List of space separated locations. A location consist in "
        "the name of a variation axis, followed by '=' and a number. E.g.: "
        " wght=700 wdth=80. The default is the location of the base master.")
    parser.add_argument(
        "-o",
        "--output",
        metavar="OUTPUT.ttf",
        default=None,
        help="Output instance TTF file (default: INPUT-instance.ttf).")
    logging_group = parser.add_mutually_exclusive_group(required=False)
    logging_group.add_argument("-v",
                               "--verbose",
                               action="store_true",
                               help="Run more verbosely.")
    logging_group.add_argument("-q",
                               "--quiet",
                               action="store_true",
                               help="Turn verbosity off.")
    parser.add_argument(
        "--no-overlap",
        dest="overlap",
        action="store_false",
        help="Don't set OVERLAP_SIMPLE/OVERLAP_COMPOUND glyf flags.")
    options = parser.parse_args(args)

    varfilename = options.input
    outfile = (os.path.splitext(varfilename)[0] +
               '-instance.ttf' if not options.output else options.output)
    configLogger(level=(
        "DEBUG" if options.verbose else "ERROR" if options.quiet else "INFO"))

    loc = {}
    for arg in options.locargs:
        try:
            tag, val = arg.split('=')
            assert len(tag) <= 4
            loc[tag.ljust(4)] = float(val)
        except (ValueError, AssertionError):
            parser.error("invalid location argument format: %r" % arg)
    log.info("Location: %s", loc)

    log.info("Loading variable font")
    varfont = TTFont(varfilename)

    instantiateVariableFont(varfont,
                            loc,
                            inplace=True,
                            overlap=options.overlap)

    log.info("Saving instance font %s", outfile)
    varfont.save(outfile)