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')
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')
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')
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')
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)
if source.tag == 'source': # print(source) # font = source.attrib['filename'].split('.ufo')[0] # dspace_fonts.append(font) # # # # xml_dspace_file.close() # dspace_fonts = ','.join(dspace_fonts) # faults = generic_tools.check_given_fonts_exist(dspace_fonts, EFO.font_files) # if faults == False: # EFO._efo_to_ufos(dspace_fonts, False, "class", True) # for x in EFO.all_exported_ufo_dst: # for k, v in x.items(): # copy_ufo_for_componentization = v.split('.ufo')[0] # for y in sources.iter(): # for source in list(y): #
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)