示例#1
0
    {
        "font_files": []
    },
    {
        "font_info": []
    },
    {
        "font_kerning_settings": []
    }
]
#
if faults == False:
	#
	EFO_temp = os.path.join(args.source,"temp")
	#
	EFO = EFO(args.source,EFO_temp)
	#
	EFO._efo_to_ufos(args.fonts, True, "flat")
	#
	source_efo_flat_kern_dir = os.path.join(EFO._in, "kerning/flat")
	source_efo_similarity_kern_plist = os.path.join(EFO._in, "groups/kerning.plist")
	#
	f_files_class = []
	#
	for x in EFO.all_exported_ufo_dst:
		#
		for k, v in x.items():
			#
			copy_ufo_for_class_compress = v.split('.ufo')[0]+'_class.ufo'
			#
			generic_tools.copyDirectory(v, copy_ufo_for_class_compress)
示例#2
0
				remove_anchor(EFO._in, o_f, item.get('glif'))
				#
			#
		#
	#
#
faults = False
#
if  args.source is None:
	#
	faults = True
	#
	print('=\n=> Please Provide Source EFO File: -s "/font.efo"\n=')	
	#
if  args.fonts is None:
	#
	faults = True
	#
	print('=\n=> Please Provide the Fonts to Remove Anchors: -f "thn,reg,bld"\n=')	
	#
#
if faults == False:
	#
	EFO_temp = os.path.join(args.source,"temp")
	#
	EFO = EFO(args.source,EFO_temp)
	#
	do_remove_anchors(EFO, args.fonts)
	#
#
#
faults = False
#
if args.source is None:
    #
    faults = True
    #
    print(
        '=\n=> Please Provide Source fontinfo.JSON File: -s "/fontinfo.json"\n='
    )
    #
if args.output is None:
    #
    #faults = True
    #
    print(
        '=\n=> Output Directory for EFO is fontinfo.JSON Parent Directory or Provide: -o "dir/"\n='
    )
    #
if faults == False:
    #
    EFO = EFO(args.source, args.output)
    #
    EFO._ufos_to_efo()
    #
    fontinfo_json = EFO.fontinfo
    #
    #print(fontinfo_json)
    #
#
if  args.fonts is None:
	#
	faults = True
	#
	print('=\n=> Please Provide the Font Instances to Export to UFO: -f "thn,reg,bld"\n=')	
	#
if  args.kerning_type is None:
	#
	faults = True
	#
	print('=\n=> Please Provide the Kerning Type to copy to UFOs: -k "class" / "flat" \n=')	
	#
else:
		
	if args.kerning_type not in ["class","flat"]:
		#
		faults = True
		#
		print('=\n=> Please Provide a Valid Kerning Type: -k "class" / "flat" \n=')	
		#
if faults == False:
	#
	EFO = EFO(args.source,args.output)
	#
	EFO._efo_to_ufos(args.fonts, False, args.kerning_type)
	#
	fontinfo_json = EFO.fontinfo
	#
#

示例#5
0
#
if  args.purpose is None:
	#
	faults = True
	#
	print('=\n=> Please Provide the Purpose of Similarity Extraction: component 1 to 1 similarity, or kerning groups loose similarity: -p "comp" or "kern"\n=')	
	#
#
args.compress = "Yes"
# if  args.compress is None:
# 	#
# 	faults = True
# 	#
# 	print('=\n=> Please Select to Compress to Class Based Plist: -c "Yes" or "No" \n=')	
	#
#
if faults == False:
	#
	EFO_temp = os.path.join(args.source,"temp")
	#
	EFO = EFO(args.source,EFO_temp)
	#
	EFO._efo_to_ufos(args.font, True)
	#
	SIMEX = SIMEX(args.source, args.purpose, args.compress, args.font)
	#
	SIMEX.extract_similarity()
	#
	print("Manual Crosscheck would be wise for the generated Similarity Plists")
	#
#
if  args.fonts is None:
	#
	faults = True
	#
	print('=\n=> Please Provide the Fonts to Extract Similarity: -f "thn,reg,bld"\n=')	
	#
#
if  args.compress_class_plist is None:
	#
	faults = True
	#
	print('=\n=> Please Select to Compress to Class Based Kerning through Similarity Plist (Obtained by kerning_extract_similarity.py and stored in your EFO/groups): -c "Yes"/"No" \n=')
	#
#
if faults == False:
	#
	EFO_temp = os.path.join(args.source,"temp")
	#
	EFO = EFO(args.source,EFO_temp)
	#
	EFO._efo_to_ufos(args.fonts, True, "flat")
	#
	AUTOKERN = AUTOKERN(args.source, args.fonts, args.compress_class_plist)
	#
	AUTOKERN.do_kern_for_pairs()
	#
	AUTOKERN.flat_kern_to_efo(args.source)
	#
#

示例#7
0
#
#
faults = False
#
if args.source is None:
    #
    faults = True
    #
    print('=\n=> Please Provide Source EFO File: -s "/font.efo"\n=')
    #
if faults == False:
    #
    #
    EFO_temp = os.path.join(args.source, "temp")
    #
    EFO = EFO(args.source, EFO_temp)
    #
    dspace_file = os.path.join(args.source, EFO.EFO_designspace)
    new_dspace = os.path.join(*(args.source, EFO.EFO_temp,
                                EFO.EFO_designspace))
    #
    print(dspace_file)
    #
    dspace_fonts = []
    #
    with open(dspace_file, 'r') as xml_dspace_file:
        #
        tree = ET.parse(xml_dspace_file)
        #
        sources = tree.find("sources")
        #
示例#8
0
def do_kerning_alterations(EFO, deg, orig_fonts, targ_fonts):
    #
    '''
	open flat kerning for orig_fonts
		get fontinfo capHeight
		flatten all fonts that participate
		
		for each font, for each glyphname in glyphlib not _notdef
			find highest point location for orig and targ fonts
			store to transfer_dict as glif_name : { closest y point to cap height of contour[0] point list as [x,y], index in original contour[0] point list }
		
		for each font in target and dest
	'''
    #
    read_efo_json_fontinfo(EFO, "Downstream")
    fonts = get_font_file_array(EFO)
    #
    #
    orig_fonts = split_input(orig_fonts)
    targ_fonts = split_input(targ_fonts)
    #
    EFO._efo_to_ufos(','.join(orig_fonts + targ_fonts), False, "class")
    #
    for z in orig_fonts + targ_fonts:
        #
        instance_name = generic_tools.sanitize_string(
            EFO.current_font_family_name + ' ' + z)
        instance_directory = os.path.join(EFO.current_font_family_directory,
                                          instance_name + '.ufo')
        #
        comp_tools.flatten_components(instance_directory)
        #
    #
    source_glyphflib = os.path.join(EFO._in, "glyphlib.xml")
    glyphlib = ET.parse(source_glyphflib)
    #
    t_d = get_transfer_dict(EFO, orig_fonts, targ_fonts, glyphlib)
    #
    for o_f in fonts:
        #
        if o_f in orig_fonts:
            #
            for t_f in fonts:
                #
                if t_f in targ_fonts:
                    #
                    for t_f in targ_fonts:
                        #
                        orig_flat_kerning = os.path.join(
                            EFO._in, "kerning", "flat", o_f + '.plist')
                        s_p_f = plistlib.readPlist(orig_flat_kerning)
                        #
                        targ_flat_kerning = os.path.join(
                            EFO._in, "kerning", "flat", t_f + '.plist')
                        t_p_f = plistlib.readPlist(targ_flat_kerning)
                        #
                        for x in s_p_f:
                            #print("glyph",x)
                            #print("LOFPt", LOFPt)
                            #print("LTFPt", LTFPt)
                            #
                            for y in s_p_f[x]:
                                #
                                LOFPt = t_d["orig"][o_f][get_glif_name(
                                    glyphlib,
                                    x).split(".glif")[0]]["data"][0]  # y orig
                                LTFPt = t_d["targ"][t_f][get_glif_name(
                                    glyphlib, x).split(".glif")[0]]["data"][
                                        0]  # y target
                                #
                                #
                                ROFPt = t_d["orig"][o_f][get_glif_name(
                                    glyphlib,
                                    y).split(".glif")[0]]["data"][0]  # y orig
                                RTFPt = t_d["targ"][t_f][get_glif_name(
                                    glyphlib, y).split(".glif")[0]]["data"][
                                        0]  # y target
                                #
                                #
                                Kn = s_p_f[x][y]  # orig kerning
                                #
                                i_n = generic_tools.sanitize_string(
                                    EFO.current_font_family_name + ' ' + o_f)
                                i_n_dir = os.path.join(
                                    EFO.current_font_family_directory,
                                    i_n + '.ufo')
                                #
                                OLw = get_glif_width(EFO._in, glyphlib, x,
                                                     o_f)  # orig_font_L_width
                                TLw = get_glif_width(EFO._in, glyphlib, x,
                                                     t_f)  # targ_font_L_width
                                #
                                ORw = get_glif_width(EFO._in, glyphlib, y,
                                                     o_f)  # orig_font_R_width
                                TRw = get_glif_width(EFO._in, glyphlib, y,
                                                     t_f)  # targ_font_R_width
                                #
                                DKn = get_new_kerning(Kn, OLw, TLw, ORw, TRw,
                                                      LOFPt, LTFPt, ROFPt,
                                                      RTFPt)
                                #
                                t_p_f[x][y] = DKn
                                #
                                print("\t", "Kn:", Kn, "\tDKn", DKn, "\tPAIR:",
                                      x, y)
                                #
                            #
                        #
                        plistlib.writePlist(t_p_f, targ_flat_kerning)
示例#9
0
    print('=\n=> Please Provide Source EFO File: -s "/font.efo"\n=')
    #
if args.fonts is None:
    #
    faults = True
    #
    print(
        '=\n=> Please Provide the Font Instances to Componentize: -f "thn,reg,bld"\n='
    )
    #
if faults == False:
    #
    #
    EFO_temp = os.path.join(args.source, "temp")
    #
    EFO = EFO(args.source, EFO_temp)
    #
    EFO._efo_to_ufos(args.fonts, True, "class")
    #
    f_files_class = []
    #
    for x in EFO.all_exported_ufo_dst:
        #
        for k, v in x.items():
            #
            copy_ufo_for_componentization = v.split('.ufo')[0] + '_compo.ufo'
            #
            generic_tools.copyDirectory(v, copy_ufo_for_componentization)
            #
            f_files_class.append(k + '_compo')
            #
示例#10
0
    def get_classes(self):
        #
        tree = ET.parse(os.path.join(self._efo, "glyphlib.xml"))
        root = tree.getroot()

        #
        #
        def get_uni_chr(_chr):
            #
            return str('\\u' + _chr).encode('utf-8').decode("unicode-escape")
            #

        #
        def get_glyphlib_info(name):
            #
            #
            for x in root:
                #
                if x.attrib['name'] == name:
                    #
                    uni_char = ""
                    #
                    if len(x.attrib["unicode"]):
                        #
                        uni_char = get_uni_chr(x.attrib["unicode"])
                        #
                    #
                    return [
                        x.attrib["glif"], name, uni_char, x.attrib["unicode"]
                    ]
                    #
                #
            #

        #
        def get_glyphlib():
            #
            json_glyphlib = {}
            #
            for x in root:
                #
                uni_char = ""
                #
                if len(x.attrib["unicode"]):
                    #
                    uni_char = get_uni_chr(x.attrib["unicode"])
                    #
                #
                json_glyphlib.update({
                    x.attrib["name"]:
                    [uni_char, x.attrib["glif"], x.attrib["unicode"]]
                })
                #
            #
            return json_glyphlib
            #

        #
        from Lib.efo import EFO
        from Lib.efo.efo_fontinfo import get_font_file_array
        from Lib.generic.generic_tools import plist_to_json
        #
        EFO = EFO(self._efo)
        #
        fontinfo_json = EFO.fontinfo
        #
        kerning_plist = plist_to_json(
            os.path.join(self._efo, "groups", "kerning.plist"))
        #
        new_plist = {}
        #
        for k, v in kerning_plist.items():
            #
            new_v = []
            #
            for y in v:
                #
                new_v.append(get_glyphlib_info(y))
                #
            #
            new_plist[k] = new_v
            #
        #
        return json.dumps({
            "get_classes": new_plist,
            "get_weights": get_font_file_array(EFO),
            "get_glyphlib": get_glyphlib()
        })