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 flatten_components(ufo_dir): # print('COMP: Flatten UFO Components') # reader = ufoLib.UFOReader(ufo_dir, validate=True) # source_dir = os.path.join(ufo_dir,'glyphs') target_dir = os.path.join(ufo_dir,'glyphs_flat') generic_tools.make_dir(target_dir) # copy_tree(source_dir, target_dir) # t_dir = target_dir#/media/root/Malysh1/winshm/advent_repo/Advent/_/exp/advent_pro_fmm/test.ufo/glyphs' #print('INPUT', ufo_dir) #print('OUTPUT', t_dir) # ufoWriter = ufoLib.GlyphSet(t_dir) # inGlyphSet = reader.getGlyphSet() # for glyphName in inGlyphSet.keys(): # g = inGlyphSet[glyphName] # text = inGlyphSet.getGLIF(glyphName) comp = ufoLib.glifLib._fetchComponentBases(text) # if len(comp): # new_outline = [] # source_glyph = os.path.join(t_dir,generic_tools.glyphNameToFileName(glyphName)) # target_elem = ET.parse(source_glyph) target_dest = target_elem.find('outline') # for co in comp: # comp_source = inGlyphSet.getGLIF(co) tree = ET.fromstring(comp_source) outl = tree.find('outline') # for x in outl: # contour = ET.Element("contour") # for point in x: # contour.append(point) # # if len(contour): # target_dest.append(contour) # # # # for elem in target_elem.iter(): for child in list(elem): if child.tag == 'component': elem.remove(child) elif child.tag == 'contour': # for point in list(child): # if "move" in str(point.attrib): elem.remove(child) break # xml_str = ET.tostring(target_elem.getroot(), method='xml').decode().replace("'", '"') #print(ElementTree.tostring(svgGlyph, method='xml')) # #data = ET.tostring(target_elem.getroot()) f = open(source_glyph, "w") f.write('<?xml version="1.0" encoding="UTF-8"?>\n'+xml_str) #target_elem.write(source_glyph, encoding='utf8') # else: g.drawPoints(None) ufoWriter.writeGlyph(glyphName, g, g.drawPoints) # # ufoWriter.writeContents() # time.sleep(2) # generic_tools.empty_dir(source_dir) # generic_tools.rm_dir(source_dir) os.rename(target_dir, source_dir)
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')
EFO.current_font_file_name = k # UFO_to_COMPUFO = COMPS(args.source, copy_ufo_for_componentization, EFO) # UFO_to_COMPUFO.ufos_comp() # # # new_class_fontinfo[0]["shared_info"][ "familyName"] = EFO.current_font_family_name new_class_fontinfo[1]["font_files"] = f_files_class # c_fontinfo_dir = os.path.join(*(EFO._in, "temp", "fontinfo.json")) # with open(c_fontinfo_dir, 'w') as outfile: # json.dump(new_class_fontinfo, outfile) # # c_source_ufo_family = os.path.join(*(EFO._in, "temp", EFO.current_font_family_name)) # EFO._in = c_fontinfo_dir EFO._out = args.source EFO.current_source_ufo_family = c_source_ufo_family # EFO._ufos_to_efo(["glyphs"], False, False, True) # generic_tools.empty_dir(EFO_temp) #
def flatten_components(ufo_dir, export=True, save_glif=True): # print('COMP: Flatten UFO Components') # print(ufo_dir) # reader = ufoLib.UFOReader(ufo_dir, validate=True) # if export == True: # source_dir = os.path.join(ufo_dir, 'glyphs') target_dir = os.path.join(ufo_dir, 'glyphs_flat') generic_tools.make_dir(target_dir) # copy_tree(source_dir, target_dir) # t_dir = target_dir #/media/root/Malysh1/winshm/advent_repo/Advent/_/exp/advent_pro_fmm/test.ufo/glyphs' print('INPUT', ufo_dir) print('OUTPUT', t_dir) # ufoWriter = ufoLib.GlyphSet(t_dir) # inGlyphSet = reader.getGlyphSet() # for glyphName in inGlyphSet.keys(): # #print(glyphName, get_name) # g = inGlyphSet[glyphName] # text = inGlyphSet.getGLIF(glyphName) comp = ufoLib.glifLib._fetchComponentBases(text) # source_glyph = os.path.join( t_dir, generic_tools.glyphNameToFileName(glyphName) + '.glif') # g.drawPoints(None) # if export: # ufoWriter.writeGlyph(glyphName, g, g.drawPoints) # #ufoWriter.writeContents() # with open(source_glyph, 'r') as rf: # glif_data = rf.read() # with open(source_glyph, 'w') as wf: # target_elem = ET.fromstring(glif_data) target_dest = target_elem.find('outline') # for co in comp: # comp_source = inGlyphSet.getGLIF(co) tree = ET.fromstring(comp_source) outl = tree.find('outline') # for x in outl: # contour = ET.Element("contour") # for point in x: # contour.append(point) # # if len(contour): # target_dest.append(contour) # # # # for elem in target_elem.iter(): # #print(elem.tag) # for child in list(elem): if child.tag == 'component': elem.remove(child) elif child.tag == 'contour': # for point in list(child): # if "move" in str(point.attrib): elem.remove(child) break # anchors = target_elem.findall('anchor') # for anchor in anchors: target_elem.remove(anchor) # xml_str = ET.tostring( target_elem, method='xml').decode().replace("'", '"').replace( '</contour><contour>', '</contour>\n <contour>').replace( '<contour><point', ' <contour>\n <point') new_xml = LET.fromstring(xml_str) new_xml_str = LET.tostring(new_xml, encoding='utf8', method="xml", xml_declaration=False, pretty_print=True).decode() clean_xml_str = BeautifulSoup(xml_str, "xml").prettify( ) #minidom.parseString(xml_str).toprettyxml(indent=" ") # if save_glif == True: # f = open(source_glyph, "w") f.write(clean_xml_str) f.close() # else: # f.close() # # #if get_name == glyphName: # #return clean_xml_str # # # # # if export == True: # time.sleep(2) # generic_tools.empty_dir(source_dir) # generic_tools.rm_dir(source_dir) os.rename(target_dir, source_dir) #