def get_fonts(self): '''Get all fonts in current project.''' t = self.w.tabs[0] _masters_checkbox = t._masters.get() _instances_checkbox = t._instances.get() # build font list _masters = self._project.masters() _instances = self._project.instances() _fonts = [] if _masters_checkbox: if _masters is not None: _fonts += _masters if _instances_checkbox: if _instances is not None: _fonts += _instances _fonts.sort() # update fonts list if len(_fonts) > 0: t.fonts_list.set([]) for font in _fonts: font_name = '%s' % get_names_from_path(font)[1] t.fonts_list.extend([font_name]) else: t.fonts_list.set([ '.' ]) # update self._fonts = _fonts
def collect_fonts(self): '''Update the font names and file paths at `hProject.fonts`.''' _ufos = self.ufos() self.fonts = {} if len(_ufos) > 0: for ufo_path in _ufos: _style_name = get_names_from_path(ufo_path)[1] self.fonts[_style_name] = ufo_path
def set_names_from_path(font, prefix=None): """ Set the font naming fields using parts of the name of the font file. """ family_name, style_name = get_names_from_path(font.path) if prefix: family_name = '%s %s' % (prefix, family_name) set_font_names(font, family_name, style_name)
def set_names_from_path(font, prefix=None): """ Set the font naming fields using parts of the name of the font file. """ family_name, style_name = get_names_from_path(font.path) if prefix: family_name = "%s %s" % (prefix, family_name) set_font_names(font, family_name, style_name)
def collect_fonts(self): """Update the font names and file paths at :py:attr:`hProject.fonts`. This method is called automatically when the :py:class:`hProject` object is initialized. """ _ufos = self.ufos() self.fonts = {} if len(_ufos) > 0: for ufo_path in _ufos: _style_name = get_names_from_path(ufo_path)[1] self.fonts[_style_name] = ufo_path
def generate_css(self): # create css file css_file_name = "%s.css" % self.project.name # .lower() css_file_path = os.path.join(self.project.paths["woffs"], css_file_name) css_file = open(css_file_path, "w") # generate css rules print "generating css for space...\n" for ufo_path in self.ufos(): file_name = os.path.splitext(os.path.split(ufo_path)[1])[0] woff_path = "%s.woff" % file_name family_name, style_name = get_names_from_path(file_name) font_name = " ".join((family_name, style_name)) css = "@font-face { font-family: '%s'; src: url('%s') format('woff'); }\n" % (font_name, woff_path) css_file.write(css) css_file.close() # upload css file # ... print "...done.\n"
def actions_callback(self, sender): '''Apply batch actions to selected fonts in project.''' # get fonts and actions _fonts = self.get_font_selection() _actions = self.get_actions(self._actions_checkboxes) # apply actions to fonts if len(_fonts) > 0: self.w.bar.start() print 'batch processing selected fonts...\n' for font_path in _fonts: family, style = get_names_from_path(font_path) print '\tprocessing %s %s...\n' % (family, style) #--------------------------------- _action = 'open window' if _actions.has_key(_action): if _actions[_action]: print '\t\topening font window...' font = hFont(RFont(font_path, showUI=True)) else: print '\t\topening font...' font = hFont(RFont(font_path, showUI=False)) #--------------------------------- _action = 'build accents' if _actions.has_key(_action): if _actions[_action]: print '\t\tbuilding accents...' font.build_accents() #--------------------------------- _action = 'build composed' if _actions.has_key(_action): if _actions[_action]: print '\t\tbuilding composed glyphs...' font.build_composed() #--------------------------------- _action = 'clear features' if _actions.has_key(_action): if _actions[_action]: print '\t\tremoving features...' font.clear_features() #--------------------------------- _action = 'import features' if _actions.has_key(_action): if _actions[_action]: print '\t\timporting features...' font.import_features() #--------------------------------- _action = 'import kerning' if _actions.has_key(_action): if _actions[_action]: print '\t\timporting kerning...' font.import_kern_feature() #--------------------------------- _action = 'set font info' if _actions.has_key(_action): if _actions[_action]: print '\t\tsetting font info...' font.set_info() #--------------------------------- _action = 'set foundry info' if _actions.has_key(_action): if _actions[_action]: print '\t\tsetting foundry info... [empty]' #--------------------------------- _action = 'set vmetrics' if _actions.has_key(_action): if _actions[_action]: print '\t\tsetting vertical metrics...' font.set_vmetrics(verbose=False) #--------------------------------- _action = 'clear colors' if _actions.has_key(_action): if _actions[_action]: print '\t\tclear colors...' clear_colors(font.ufo) #--------------------------------- _action = 'create glyphs' if _actions.has_key(_action): if _actions[_action]: print '\t\tcreating glyphs...' font.create_glyphs() #--------------------------------- _action = 'import groups' if _actions.has_key(_action): if _actions[_action]: print '\t\timporting glyph groups...' font.import_groups_from_encoding() #--------------------------------- _action = 'paint groups' if _actions.has_key(_action): if _actions[_action]: print '\t\tpainting glyph groups...' font.paint_groups(crop=False) #--------------------------------- _action = 'clear colors' if _actions.has_key(_action): if _actions[_action]: print '\t\tremoving glyph colors... [empty]' # font.paint_groups(crop=False) #--------------------------------- _action = 'crop glyphset' if _actions.has_key(_action): if _actions[_action]: print '\t\tcropping glyph set...' font.order_glyphs() font.crop_glyphset() #--------------------------------- _action = 'spacing groups' if _actions.has_key(_action): if _actions[_action]: print '\t\timporting spacing groups...' font.import_spacing_groups() #--------------------------------- _action = 'paint spacing groups' if _actions.has_key(_action): if _actions[_action]: print '\t\tpaint spacing groups...' font.paint_spacing_groups() #--------------------------------- _action = 'remove overlaps' if _actions.has_key(_action): if _actions[_action]: print '\t\tremoving overlaps...' font.remove_overlap() #--------------------------------- _action = 'auto unicodes' if _actions.has_key(_action): if _actions[_action]: print '\t\tsetting unicodes...' font.auto_unicodes() #--------------------------------- _action = 'autohint PS' if _actions.has_key(_action): if _actions[_action]: print '\t\tautohinting PS... [empty]' #--------------------------------- _action = 'test install' if _actions.has_key(_action): if _actions[_action]: print '\t\ttest install...' font.ufo.testInstall() #--------------------------------- _action = 'generate otf' if _actions.has_key(_action): if _actions[_action]: print '\t\tgenerating otf...' font.generate_otf(verbose=False) #--------------------------------- _action = 'generate test otf' if _actions.has_key(_action): if _actions[_action]: print '\t\tgenerating test otf...' _options = { 'decompose' : True, 'remove overlap' : True, 'autohint' : False, 'release mode' : False, 'test folder' : True, } font.generate_otf(options=_options) #--------------------------------- _action = 'generate woff' if _actions.has_key(_action): if _actions[_action]: print '\t\tgenerating woff...' font.generate_woff() #--------------------------------- _action = 'upload woff' if _actions.has_key(_action): if _actions[_action]: print '\t\tuploading woff...' font.upload_woff() #--------------------------------- _action = 'save font' if _actions.has_key(_action): if _actions[_action]: print '\t\tsaving font...' font.ufo.save() #--------------------------------- _action = 'close window' if _actions.has_key(_action): if _actions[_action]: print '\t\tclosing font window.' font.ufo.close() #--------------------------------- print print '\t...done.\n' # done with all fonts self.w.bar.stop() print '...done.\n' else: print 'please select one or more fonts first.\n'