示例#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)
示例#3
0
def _open_font(path, master_finder=lambda s: s):
	# load TTFont masters from given 'path': this can be either a .TTX or an
	# OpenType binary font; or if neither of these, try use the 'master_finder'
	# callable to resolve the path to a valid .TTX or OpenType font binary.
	from fontemon_blender_addon.fontTools.ttx import guessFileType

	master_path = os.path.normpath(path)
	tp = guessFileType(master_path)
	if tp is None:
		# not an OpenType binary/ttx, fall back to the master finder.
		master_path = master_finder(master_path)
		tp = guessFileType(master_path)
	if tp in ("TTX", "OTX"):
		font = TTFont()
		font.importXML(master_path)
	elif tp in ("TTF", "OTF", "WOFF", "WOFF2"):
		font = TTFont(master_path)
	else:
		raise VarLibValidationError("Invalid master path: %r" % master_path)
	return font