예제 #1
0
	def return_self_dirs(self, gf):
		#
		self.current_font_file_name = gf
		self.current_font_family_directory = os.path.join(os.path.join(self._in, self.EFO_temp),self.current_font_family_name)
		self.current_font_instance_name = generic_tools.sanitize_string(self.current_font_family_name+' '+self.current_font_file_name)
		self.current_font_instance_directory = os.path.join(self.current_font_family_directory,self.current_font_instance_name+'.ufo')
		self.current_fontinfo = efo_fontinfo.get_font_info_for_weight(self)
		#
		self.EFO_groups_dir = os.path.join(self._in, self.EFO_groups)
		#
예제 #2
0
	def return_temp_and_vector_dirs(self, gf):
		#
		self.current_font_file_name = gf
		self.current_font_family_directory = os.path.join(self._in,self.EFO_temp)
		self.current_font_family_vectors_directory = os.path.join(self._in,self.EFO_vectors_dir)
		self.current_font_instance_name = generic_tools.sanitize_string(self.current_font_family_name+' '+self.current_font_file_name)
		#
		self.current_font_family_temp_directory = os.path.join(self.current_font_family_directory,self.current_font_family_name)
		self.current_font_instance_temp_directory = os.path.join(self.current_font_family_temp_directory,self.current_font_instance_name+'.ufo')
		#
		self.current_font_family_vectors_directory = os.path.join(self.current_font_family_vectors_directory,self.current_font_family_name)
		self.current_font_instance_vectors_directory = os.path.join(self.current_font_family_vectors_directory,self.current_font_instance_name)
예제 #3
0
def get_shared_info(self):
    #
    f_i = self.fontinfo
    #
    for data in f_i:
        #
        for key, value in data.items():
            #
            if key == "shared_info":
                #
                self.shared_info = value
                #
                self.current_font_family_name = generic_tools.sanitize_string(
                    value["familyName"])
예제 #4
0
def get_transfer_dict(EFO, orig_fonts, targ_fonts, glyphlib):
    #
    transfer_dict = {"orig": {}, "targ": {}}
    #
    cap_height = EFO.fontinfo[0]["shared_info"]["capHeight"]
    #
    for weight_name in orig_fonts + targ_fonts:
        #
        for f_k in glyphlib.iter():
            #
            if f_k.tag == "glyph":
                #
                g = f_k.attrib.get("glif")
                #
                if g not in ["_notdef", "space"]:
                    #
                    glif_filename = f_k.attrib.get("glif") + '.glif'
                    glif_name = f_k.attrib.get("name")
                    #
                    i_n = generic_tools.sanitize_string(
                        EFO.current_font_family_name + ' ' + weight_name)
                    i_n_dir = os.path.join(EFO.current_font_family_directory,
                                           i_n + '.ufo')
                    #
                    equiv_font = None
                    #
                    if weight_name in orig_fonts:
                        #
                        instance = "orig"
                        #
                    elif weight_name in targ_fonts:
                        #
                        instance = "targ"
                        #
                        equiv_font = orig_fonts[targ_fonts.index(weight_name)]
                        #
                    #
                    transfer_dict = get_glif_top_point(
                        i_n_dir, cap_height, glif_filename, glif_name,
                        weight_name, instance, transfer_dict,
                        equiv_font)  # source_font_L_width
                    #
                #
            #
        #
    #
    return transfer_dict
예제 #5
0
	def flat_kern_to_efo(self, _source_efo):
		#
		source_efo_flat_kern_dir = os.path.join(_source_efo, "kerning/flat")
		source_efo_similarity_kern_plist = os.path.join(_source_efo, "groups/kerning.plist")
		#
		for x in self.all_dst:
			#
			for k, v in x.items():
				#
				print(">>", k, v)
				#
				current_font_flat_kerning = os.path.join(v,'kerning'+'.plist')
				#
				source_font_flat_kerning = os.path.join(source_efo_flat_kern_dir,k+'.plist')
				#
				shutil.copyfile(current_font_flat_kerning, source_font_flat_kerning)
				#
				current_font = generic_tools.sanitize_string(self.current_font_family_name+' '+k)
				#
				print('\tREPLACED FLAT KERNING FOR EFO:', current_font, ' AT:', source_font_flat_kerning)
				#
			#
		#
		if self._compress_class_plist == "Yes":
			#
			print('Hello')
			#
			for x in self.all_dst:
				#
				for k, v in x.items():
					#
					copy_ufo_for_class_compress = v.split('.ufo')[0]+'_class.ufo'
					#
					source_font_flat_kerning = os.path.join(source_efo_flat_kern_dir,k+'.plist')
					#
					generic_tools.copyDirectory(v, copy_ufo_for_class_compress)
					#
					_COMPRESS = COMPRESS(k,v, copy_ufo_for_class_compress, source_efo_similarity_kern_plist)
					#EFO = EFO(args.source,EFO_temp)
					#
					_COMPRESS.do_class_kern_replacement()
예제 #6
0
 def return_self_dirs(self, gf):
     #
     self.current_font_file_name = gf
     self.current_font_family_directory = os.path.join(
         os.path.join(self._in, self.EFO_temp),
         self.current_font_family_name)
     self.current_font_instance_name = generic_tools.sanitize_string(
         self.current_font_family_name + ' ' + self.current_font_file_name)
     self.current_font_instance_directory = os.path.join(
         self.current_font_family_directory,
         self.current_font_instance_name + '.ufo')
     self.current_fontinfo = efo_fontinfo.get_font_info_for_weight(self)
     #
     for x in self.kerning_settings:
         #
         for k, v in x.items():
             #
             if k == gf:
                 #
                 self.current_kerning_settings = v
                 #
             #
         #
     #
예제 #7
0
    def _ufos_to_efo(self,
                     _to_copy=[
                         "metainfo", "features", "glyphs", "fontinfo",
                         "kerning", "lib"
                     ],
                     _ufos_to_temp=True,
                     _from_compress=False):
        #
        read_efo_json_fontinfo(self, "Upstream")
        #
        self.font_files = get_font_file_array(self)
        #
        print('UFOs to EFO')
        #
        self.current_font_family_name = generic_tools.sanitize_string(
            self.fontinfo[0]["shared_info"]["familyName"])
        #
        if self._out != "Current":
            #
            self.new_efo_dir = self._out  #os.path.join(*Path(self._in).parts[:-1])
            #
        else:
            #
            self.new_efo_dir = os.path.join(*Path(self._in).parts[:-1])
            #
        #
        temp_dir = os.path.join(self.new_efo_dir, self.EFO_temp)
        vectors_dir = os.path.join(self.new_efo_dir, self.EFO_vectors)
        features_dir = os.path.join(self.new_efo_dir, self.EFO_features_dir)
        #
        EFO_fontinfo_data = {}
        #
        new_info = copy.deepcopy(self.fontinfo)
        #
        x = 0
        #
        for f in self.font_files:
            #
            self.current_font_file_name = f
            self.current_font_instance_name = generic_tools.sanitize_string(
                self.current_font_family_name + ' ' +
                self.current_font_file_name)
            #
            if _from_compress:
                #
                self.current_source_ufo = os.path.join(
                    self.current_source_ufo_family,
                    self.current_font_instance_name + '.ufo')
                #
            else:
                #
                self.current_source_ufo_family = os.path.join(
                    self.new_efo_dir, self.current_font_family_name)
                #
            #
            self.current_source_ufo = os.path.join(
                self.current_source_ufo_family,
                self.current_font_instance_name + '.ufo')
            #
            self.current_source_ufo_glyphs_dir = os.path.join(
                self.current_source_ufo, 'glyphs')
            self.current_source_efo_features_dir = os.path.join(
                self.new_efo_dir, 'features')

            self.current_source_ufo_lib = os.path.join(
                *(self.new_efo_dir, self.current_font_family_name,
                  self.current_font_instance_name + '.ufo', 'lib.plist'))
            EFO_glyphlib_xml = os.path.join(self.new_efo_dir, 'glyphlib.xml')
            #
            #
            if x == 0:  # once
                #
                if "metainfo" in _to_copy:
                    #
                    copy_metainfo(self, "Upstream")
                    #
                #
                if "lib" in _to_copy:
                    #
                    lib_to_glyphlib.lib_to_glyphlib(
                        self.current_source_ufo_lib, EFO_glyphlib_xml)
                    #
                #
                generic_tools.make_dir(temp_dir)
                generic_tools.make_dir(vectors_dir)
                #
                if "features" in _to_copy:
                    #
                    generic_tools.make_dir(features_dir)
                    #
                #
            #
            if "glyphs" in _to_copy:
                #
                copy_glif_files(self, "Upstream")
                #
            #
            if "fontinfo" in _to_copy:
                #
                update_font_info(self, new_info, f)
                #
            #
            if "features" in _to_copy:
                #
                generic_tools.make_dir(
                    os.path.join(self.current_source_efo_features_dir,
                                 "kern_fea"))
                #
                #
                split_fea(self, _from_compress)
                #
            #
            has_groups = generic_tools.determine_kerning_type_ufo(
                self.current_source_ufo)
            #
            if has_groups:
                #
                if "kerning" in _to_copy:
                    #
                    copy_kerning(self, "class", "Upstream")
                    copy_groups_class_kerning(self, "Upstream")
                    #
                #
            else:
                #
                if "kerning" in _to_copy:
                    #
                    copy_kerning(self, "flat", "Upstream")
                    #
                #
            #
            x = x + 1
            #
        if "fontinfo" in _to_copy:
            # Save updated font info
            EFO_json_fontinfo = os.path.join(self.new_efo_dir, 'fontinfo.json')
            #
            with open(EFO_json_fontinfo, "w") as fi:
                #
                json.dump(new_info, fi, indent=4, sort_keys=True)
                #
            #
        #
        if _ufos_to_temp:
            #Move UFO Source font family to EFO temp
            copy_tree(self.current_source_ufo_family,
                      os.path.join(temp_dir, self.current_font_family_name))
            #
            #Remove UFO Source font family from root EFO dir
            generic_tools.rm_dir(self.current_source_ufo_family)
            #
            print("UFO Family Transfered To EFO/temp: ",
                  self.current_source_ufo_family)
예제 #8
0
    def _efo_to_ufos(self, _fonts='', _flatten=False, _kerning_type="class"):
        #
        '''
		Export UFOs from EFO:
			
			Read /EFO/font_info.json

				For Every weight/font:

					Actions: 
						features.fea:
							combine all .fea files in /features folder
						fontinfo.plist
							read /font_info.json
							generate combined "shared" and per weight fontinfo.plist
						groups.plist
							copy /groups/kerning.plist to every UFO renamed as groups.plist
						kerning.plist
							copy /kerning/class/weight.plist to every UFO renamed as kerning.plist
						lib.plist
							read /glyphlib.xml and create lib.plist for every UFO
						metainfo.plist
							copy metainfo.plist to every UFO
						metainfo.plist
							read /glyphlib.xml and create glyphs/contents.plist for every UFO
						glyphs
							copy EFO glyphs to UFO glyphs for every UFO
							

		'''
        #
        #
        if _fonts != '':

            self._fonts = _fonts
            self.font_files = self._fonts.split(',')
            faults = generic_tools.check_given_fonts_exist(
                _fonts, self.font_files)
            _font_files = self.font_files

        else:

            faults = False
            _font_files = self.font_files
        #
        #
        #
        if faults == False:
            #
            print('\tGIVEN FONTS EXIST CONTINUING')
            #
            self.all_exported_ufo_dst = []
            #
            for f in _font_files:
                #
                self.current_font_file_name = f
                self.current_font_instance_name = generic_tools.sanitize_string(
                    self.current_font_family_name + ' ' +
                    self.current_font_file_name)
                self.current_font_instance_directory = os.path.join(
                    self.current_font_family_directory,
                    self.current_font_instance_name + '.ufo')
                self.current_fontinfo = get_font_info_for_weight(self)
                #
                generic_tools.make_dir(self.current_font_family_directory)
                generic_tools.make_dir(self.current_font_instance_directory)
                #
                self.all_exported_ufo_dst.append(
                    {f: self.current_font_instance_directory})
                #
                print('______________________________\n')
                print(self.current_font_instance_name)
                print('\n')
                #
                generate_fontinfo(self)
                combine_fea(self)
                #
                kerning_to_copy = _kerning_type  # class / flat
                #
                if kerning_to_copy == "class":
                    #
                    copy_kerning(self, "class", "Downstream")
                    copy_groups_class_kerning(self, "Downstream")
                    #
                else:
                    #
                    copy_kerning(self, "flat", "Downstream")
                    remove_groups_class_kerning(self)
                    #
                #
                generate_lib(self)
                copy_metainfo(self, "Downstream")
                #
                generate_contents_plist(self)
                copy_glif_files(self, "Downstream")
                #
                if _flatten == True:
                    #
                    comp_tools.flatten_components(
                        self.current_font_instance_directory)
                    #
                #
            #
        else:
            #
            print('\tGIVEN FONTS INCONSISTENT ABORTING')
예제 #9
0
 def flat_kern_to_efo(self, _source_efo, EFO):
     #
     new_class_fontinfo = [{
         "shared_info": {
             "familyName": ""
         }
     }, {
         "font_files": []
     }, {
         "font_info": []
     }, {
         "font_kerning_settings": []
     }]
     #
     source_efo_flat_kern_dir = os.path.join(_source_efo, "kerning/flat")
     source_efo_similarity_kern_plist = os.path.join(
         _source_efo, "groups/kerning.plist")
     #
     for x in self.all_dst:
         #
         for k, v in x.items():
             #
             #print(">>", k, v)
             #
             current_font_flat_kerning = os.path.join(
                 v, 'kerning' + '.plist')
             #
             source_font_flat_kerning = os.path.join(
                 source_efo_flat_kern_dir, k + '.plist')
             #
             shutil.copyfile(current_font_flat_kerning,
                             source_font_flat_kerning)
             #
             current_font = generic_tools.sanitize_string(
                 self.current_font_family_name + ' ' + k)
             #
             print('\tREPLACED FLAT KERNING FOR EFO:', current_font, ' AT:',
                   source_font_flat_kerning)
             #
         #
     #
     if self._compress_class_plist == "Yes":
         #
         print('\tCompressing')
         #
         f_files_class = []
         #
         for x in self.all_dst:
             #
             for k, v in x.items():
                 #
                 copy_ufo_for_class_compress = v.split(
                     '.ufo')[0] + '_class.ufo'
                 #
                 source_font_flat_kerning = os.path.join(
                     source_efo_flat_kern_dir, k + '.plist')
                 #
                 generic_tools.copyDirectory(v, copy_ufo_for_class_compress)
                 #
                 f_files_class.append(k + '_krn_class')
                 #
                 print(source_efo_similarity_kern_plist)
                 #
                 #_COMPRESS = COMPRESS(k,v, copy_ufo_for_class_compress, source_efo_similarity_kern_plist, args.compress_pattern)
                 _COMPRESS = COMPRESS(EFO, k, v,
                                      copy_ufo_for_class_compress,
                                      source_efo_similarity_kern_plist)
                 #EFO = EFO(args.source,EFO_temp)
                 #
                 _COMPRESS.do_class_kern_replacement()
                 #
         #
         new_class_fontinfo[0]["shared_info"][
             "familyName"] = self.current_font_family_name
         new_class_fontinfo[1]["font_files"] = f_files_class
         #
         print(new_class_fontinfo)
         #
         c_fontinfo_dir = os.path.join(*(EFO._in, "temp",
                                         EFO.current_font_family_name,
                                         "fontinfo.json"))
         #
         with open(c_fontinfo_dir, 'w') as outfile:
             #
             json.dump(new_class_fontinfo, outfile)
             #
         #
         #print(c_fontinfo_dir,args.source)
         #
         c_source_ufo_family = os.path.join(*(EFO._in, "temp",
                                              EFO.current_font_family_name))
         #
         EFO._out = EFO._in
         EFO._in = c_fontinfo_dir
         EFO.current_source_ufo_family = c_source_ufo_family
         #
         EFO._ufos_to_efo(["kerning", "features"], False, True, False)
예제 #10
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)