Exemplo n.º 1
0
def do_remove_anchors(EFO, orig_fonts):
	#
	read_efo_json_fontinfo(EFO, "Downstream")
	fonts = get_font_file_array(EFO)
	#
	#
	orig_fonts = split_input(orig_fonts)
	#
	source_glyphflib = os.path.join(EFO._in,"glyphlib.xml")
	glyphlib = ET.parse(source_glyphflib)
	#
	for o_f in fonts:
		#
		if o_f in orig_fonts:
			#
			for item in glyphlib.findall("glyph"):
				#
				remove_anchor(EFO._in, o_f, item.get('glif'))
Exemplo n.º 2
0
	def svgs_to_efo(self):
		#
		efo_fontinfo.read_efo_json_fontinfo(self)
		#
		print('UFO2SVG: Started Conversion of SVGs to EFO')
		#
		self.font_files = efo_fontinfo.get_font_file_array(self)
		self.given_fonts = self._fonts.split(',')
		self.current_font_family_glyphs_directory = os.path.join(self._in,self.EFO_glyphs_dir)
		self.current_font_family_vectors_directory = os.path.join(self._in,self.EFO_vectors_dir)
		#
		print(self._fonts, self.font_files)
		#
		faults = generic_tools.check_given_fonts_exist(self._fonts, self.font_files)
		#
		if faults == False:
			#
			print('\tGIVEN FONTS EXIST CONTINUING')
			#
			for gf in self.given_fonts:
				#
				self.return_temp_and_vector_dirs(gf)
				#
				if os.path.isdir(self.current_font_instance_vectors_directory):
					#
					print('\tGIVEN FONT VECTORS EXIST CONTINUING')
					#
					f = OpenFont(self._in)
					#
					UFO_to_SVG = UFO2SVG(f)
					#
					convertSVGFilesToEFO(self, f, gf)
					#
				else:
					#
					print('\tGIVEN FONT VECTORS DONT EXIST IGNORING')
					#
			#
		else:
			#
			print('\tGIVEN FONTS INCONSISTENT ABORTING')
Exemplo n.º 3
0
	def efo_to_svgs(self):
		#
		efo_fontinfo.read_efo_json_fontinfo(self)
		#
		print('UFO2SVG: Started Conversion of EFO to SVGs')
		#
		self.font_files = efo_fontinfo.get_font_file_array(self)
		self.given_fonts = self._fonts.split(',')
		self.current_font_family_glyphs_directory = os.path.join(self._in,self.EFO_glyphs_dir)
		self.current_font_family_vectors_directory = os.path.join(self._in,self.EFO_vectors_dir)
		#
		generic_tools.empty_dir(self.current_font_family_vectors_directory)
		#
		faults = generic_tools.check_given_fonts_exist(self._fonts, self.font_files)
		#
		if faults == False:
			#
			print('\tGIVEN FONTS EXIST CONTINUING')
			#
			for gf in self.given_fonts:
				#
				self.return_temp_and_vector_dirs(gf)
				#
				generic_tools.make_dir(self.current_font_family_vectors_directory)
				generic_tools.make_dir(self.current_font_instance_vectors_directory)
				#
				f = OpenFont(self.current_font_instance_temp_directory)
				#
				UFO_to_SVG = UFO2SVG(f)
				#
				convertUFOToSVGFiles(self, f, self.current_font_instance_name)
				#
			#
		else:
			#
			print('\tGIVEN FONTS INCONSISTENT ABORTING')
Exemplo n.º 4
0
	def extract_similarity(self):
		#
		efo_fontinfo.read_efo_json_fontinfo(self)
		#
		print('SIMEX: Started Similarity Extraction')
		#
		self.font_files = efo_fontinfo.get_font_file_array(self)
		self.given_fonts = self._font.split(',')
		#self.current_font_family_glyphs_directory = os.path.join(self._in,self.EFO_glyphs_dir)
		#self.current_font_family_vectors_directory = os.path.join(self._in,self.EFO_vectors_dir)
		#
		faults = generic_tools.check_given_fonts_exist(self._font, self.font_files)
		#
		#
		if faults == False:
			#
			print('\tGIVEN FONTS EXIST CONTINUING')
			#
			all_dst = []
			#
			for gf in self.given_fonts:
				#
				print('\tSIMEX: Extracting Similarity from:', gf)
				#
				self.return_self_dirs(gf)
				#
				ufo_src_path = self.current_font_instance_directory
				#
				srcUfoFont = TFSFontFromFile(ufo_src_path)
				#
				glyph_nums = get_glyphs(srcUfoFont, check_list, checking)
				#
				if self._purpose == "comp":
					max_diff = max_diff_comp
					print('\tExtracting Similarity for Components (1 to 1)')
				else:
					max_diff = max_diff_kern
					print('\tExtracting Similarity for Kerning '+str(max_diff_kern)+'[left, center, right]'+' edit : max_diff_kern in SIMEX init for custom diff values.')
				#
				in_mils = init_permut(glyph_nums, 'right', max_diff)
				#
				mil_dict = in_mils[0]
				all_mils = in_mils[1]
				#
				#
				uni_groups = unique_groups(all_mils)
				#
				r = json.dumps(uni_groups)
				#
				parsed = json.loads(r)
				parse_dumped = json.dumps(parsed, indent=4, sort_keys=False)
				#

				#
				time_now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
				filename = gf+'.json'
				#
				init_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), self.SIMEX_temp)
				#
				generic_tools.make_dir(init_path)
				#
				dst_dir = os.path.abspath(os.path.join(init_path, filename))
				#
				all_dst.append(dst_dir)
				#
				with open(dst_dir, 'w') as the_file:
					#
					the_file.write(parse_dumped)
					the_file.close()
					#
				#
				print('\n\tSIMEX: Done Extracting Similarity and Saved:', dst_dir)
				#
			#
			if self._compress == "Yes":
				#
				for x in all_dst:
					#
					if self._purpose == "comp":
						#
						print('\tCOMPRESSING to COMPONENTS PLIST: ',x)
						#
						build_component_group_plist(x, self.EFO_groups_dir)
					else:
						#
						print('\tCOMPRESSING to KERNING PLIST: ',x)
						#
						build_kerning_group_plist(x, self.EFO_groups_dir)
					#
				#
			#
			generic_tools.empty_dir(os.path.join(self._in, self.EFO_temp))
			#
		else:
			#
			print('\tGIVEN FONTS INCONSISTENT ABORTING')
Exemplo n.º 5
0
	def do_kern_for_pairs(self):
		#
		efo_fontinfo.read_efo_json_fontinfo(self)
		#
		print('AUTOKERN: Started Automatic Kerning')
		#
		self.font_files = efo_fontinfo.get_font_file_array(self)
		self.given_fonts = self._fonts.split(',')
		#
		faults = generic_tools.check_given_fonts_exist(self._fonts, self.font_files)
		#
		if faults == False:
			#
			print('\tGIVEN FONTS EXIST CONTINUING')
			#
			self.all_dst = []
			#
			x = 0
			#
			pairlist = self.extract_pairs(self._in, self.given_fonts)
			#
			for gf in self.given_fonts:
				#
				print('\tAUTOKERN: Automatic Kerning for:', gf)
				#
				self.return_self_dirs(gf)
				#
				ufo_src_path = self.current_font_instance_directory
				self.out_fnt_flat_kerned=ufo_src_path.split('.ufo')[0]+"_krn.ufo"
				#
				self.all_dst.append({gf:self.out_fnt_flat_kerned})
				#
				pseudo_argv = ('--ufo-src-path',
								ufo_src_path,
								'--ufo-dst-path',
								self.out_fnt_flat_kerned,
								'--min-distance-ems',
								str(self.current_kerning_settings["--min-distance-ems"]),
								'--max-distance-ems',
								str(self.current_kerning_settings["--max-distance-ems"]),
								'--max-x-extrema-overlap-ems',
								str(self.current_kerning_settings["--max-x-extrema-overlap-ems"]),
								'--intrusion-tolerance-ems',
								str(self.current_kerning_settings["--intrusion-tolerance-ems"]),
								'--precision-ems',
								str(self.current_kerning_settings["--precision-ems"]),
								#
								#'--log-path',
								#'/media/root/Malysh1/winshm/advent_repo/Advent/scripts/kerning_scripts/kern_log/log',
								#'--log-basic-pairs',
								#'--write-kerning-pair-logs'
								)
				#
				pairlist_tup = self.pairlist_tuple(pairlist[gf])
				#
				#parlist_test = ("A","A","A","AE","A","Aacute","A","Abreve","A","Acircumflex","A","Adieresis","A","Agrave","A","Alpha","A","Alphatonos","A","Amacron","A","Aogonek","A","Aring","A","Atilde","A","B","A","Beta","A","C")
				#
				pairlist_tuple_to_kern = ('--glyph-pairs-to-kern',*pairlist_tup)
				#
				autokernArgs = TFSMap()
				#AutokernSettings(autokernArgs).getCommandLineSettings(*pseudo_argv)
				AutokernSettings(autokernArgs).getCommandLineSettings(*(pseudo_argv+pairlist_tuple_to_kern))
				autokern = Autokern(autokernArgs)
				autokern.process()
				#
				x = x + 1
				#
				print ('Completed:'+gf+', '+str(x)+'/'+str(len(self.given_fonts))+'\n'+' Produced Kerned UFO:'+self.out_fnt_flat_kerned)
Exemplo n.º 6
0
 def do_kern_for_pairs(self):
     #
     efo_fontinfo.read_efo_json_fontinfo(self)
     #
     print('AUTOKERN: Started Automatic Kerning')
     #
     self.font_files = efo_fontinfo.get_font_file_array(self)
     self.given_fonts = self._fonts.split(',')
     #
     faults = generic_tools.check_given_fonts_exist(self._fonts,
                                                    self.font_files)
     #
     if faults == False:
         #
         print('\tGIVEN FONTS EXIST CONTINUING')
         #
         self.all_dst = []
         #
         x = 0
         #
         #
         for gf in self.given_fonts:
             #
             print('\tAUTOKERN: Automatic Kerning for:', gf)
             #
             self.return_self_dirs(gf)
             #
             ufo_src_path = self.current_font_instance_directory
             self.out_fnt_flat_kerned = ufo_src_path.split(
                 '.ufo')[0] + "_krn.ufo"
             #
             self.all_dst.append({gf: self.out_fnt_flat_kerned})
             #
             pseudo_argv = (
                 '--ufo-src-path',
                 ufo_src_path,
                 '--ufo-dst-path',
                 self.out_fnt_flat_kerned,
                 '--min-distance-ems',
                 str(self.current_kerning_settings["--min-distance-ems"]),
                 '--max-distance-ems',
                 str(self.current_kerning_settings["--max-distance-ems"]),
                 '--max-x-extrema-overlap-ems',
                 str(self.current_kerning_settings[
                     "--max-x-extrema-overlap-ems"]),
                 '--intrusion-tolerance-ems',
                 str(self.
                     current_kerning_settings["--intrusion-tolerance-ems"]),
                 '--precision-ems',
                 str(self.current_kerning_settings["--precision-ems"]),
                 #
                 '--kerning-threshold-ems',
                 str(self.
                     current_kerning_settings["--kerning-threshold-ems"]),
                 #
                 '--x-extrema-overlap-scaling',
                 str(self.current_kerning_settings[
                     "--x-extrema-overlap-scaling"]),
                 #
                 # '--do-not-modify-side-bearings',
                 # '--kerning-strength',
                 # str(0.1),
                 '--log-path',
                 os.path.join(self._in, "temp", "logs", "log"),
                 '--log-basic-pairs',
                 '--write-kerning-pair-logs')
             #
             #pairlist = self.extract_pairs(self._in, self.given_fonts)
             pairlist = self.extract_test_pairs(test_pairs_b,
                                                self.given_fonts)
             pairlist_tup = self.pairlist_tuple(pairlist[gf])
             #
             pairlist_tuple_to_kern = ('--glyph-pairs-to-kern',
                                       *pairlist_tup)
             ignore = ('--glyphs-to-ignore', *tuple(ignore_glyphs_list))
             #
             if len(pairlist[gf]) == 0:
                 #
                 pairlist_tuple_to_kern = ()
                 #
             #
             autokernArgs = TFSMap()
             #
             AutokernSettings(autokernArgs).getCommandLineSettings(
                 *(pseudo_argv + pairlist_tuple_to_kern + ignore))
             autokern = Autokern(autokernArgs)
             autokern.process()
             #
             x = x + 1
             #
             print('Completed:' + gf + ', ' + str(x) + '/' +
                   str(len(self.given_fonts)) + '\n' +
                   ' Produced Kerned UFO:' + self.out_fnt_flat_kerned)
Exemplo n.º 7
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)
Exemplo n.º 8
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()
        })