def paste_callback(self, sender): print 'pasting data from glyph %s:\n' % self.source_glyph.name bool_string = ( False, True ) foreground = self.w.foreground.get() layers = self.w.layers.get() metrics = self.w.metrics.get() anchors = self.w.anchors.get() color = self.w.color.get() print '\tforeground: %s' % bool_string[foreground] print '\tlayers: %s' % bool_string[layers] print '\tmetrics: %s' % bool_string[metrics] print '\tanchors: %s' % bool_string[anchors] print '\tcolor: %s' % bool_string[color] print print '\tpasting in', f = CurrentFont() glyph_names = get_glyphs(f) if len(glyph_names) > 0: for glyph_name in glyph_names: print glyph_name, # prepare undo f[glyph_name].prepareUndo('paste from glyph') # copy outlines in foreground layer if foreground: target_layer = f[glyph_name].getLayer('foreground') pen = target_layer.getPointPen() self.source_glyph.drawPoints(pen) # copy all other layers if layers: for layer_name in self.source_font.layerOrder: source_layer = self.source_glyph.getLayer(layer_name) target_layer = f[glyph_name].getLayer(layer_name) pen = target_layer.getPointPen() source_layer.drawPoints(pen) # copy glyph width if metrics: f[glyph_name].width = self.source_glyph.width # copy anchors if anchors: transfer_anchors(self.source_glyph, f[glyph_name]) # copy mark color if color: f[glyph_name].mark = self.source_glyph.mark # activate undo f[glyph_name].performUndo() # done with glyph f[glyph_name].update() # done f.update() print print '\n...done.\n'
def transfer_anchors(self, var, gstring=None, clear=True, verbose=False): """Transfer anchors from one variable set of fonts to another.""" axis, src, dest_list = var # define source space for param in self.parameters.keys(): if param == axis: self.parameters[param] = [src] self.build() # parse gstring if gstring is None: glyph_names = self.project.all_glyphs() else: glyph_names = self.project.parse_gstring(gstring) # batch copy print "batch transfering anchors in %s..." % self.project.name for src_path in self.ufos(): font = hFont(RFont(src_path, showUI=False)) for dest in dest_list: dest_parameters = font.parameters dest_parameters[axis] = dest dest_file = "%s_%s.ufo" % (font.project.name, font.name_from_parameters(separator="-")) dest_path = os.path.join(font.project.paths["ufos"], dest_file) if os.path.exists(dest_path): dest_ufo = RFont(dest_path, showUI=False) print if clear: print "\tremoving anchors in %s..." % get_full_name(dest_ufo) dest_font = hFont(dest_ufo) dest_font.clear_anchors(gstring) print "\tcopying anchors from %s to %s..." % (get_full_name(font.ufo), get_full_name(dest_ufo)) if verbose: print "\t\t", for glyph_name in glyph_names: if font.ufo.has_key(glyph_name): if len(font.ufo[glyph_name].anchors) > 0: if dest_ufo.has_key(glyph_name) is False: dest_ufo.newGlyph(glyph_name) if verbose: print glyph_name, transfer_anchors(font.ufo[glyph_name], dest_ufo[glyph_name]) dest_ufo.save() if verbose: print print "\n...done.\n"
def apply_callback(self, sender): if len(self.all_fonts) > 0: # get parameters source_font = self.all_fonts[self.w._source_value.get()] target_font = self.all_fonts[self.w._target_value.get()] # print info print 'transfering anchors...\n' print '\tsource: %s' % get_full_name(source_font) print '\ttarget: %s' % get_full_name(target_font) print print '\t', # batch transfer anchors skipped = [] for glyph_name in get_glyphs(source_font): if len(source_font[glyph_name].anchors) > 0: if target_font.has_key(glyph_name): print glyph_name, # prepare undo target_font[glyph_name].prepareUndo('transfer anchors') # transfer anchors transfer_anchors(source_font[glyph_name], target_font[glyph_name]) # update target_font[glyph_name].update() # activate undo target_font[glyph_name].performUndo() else: skipped.append(glyph_name) else: # glyph does not have anchors pass # done print target_font.update() if len(skipped) > 0: print '\n\tglyphs %s not in target font.\n' % skipped print '...done.\n' else: print no_font_open # 'please open at least one font.\n'
def apply_callback(self, sender): if len(self.all_fonts) > 0: # get parameters source_font = self.all_fonts[self.w._source_value.get()] target_font = self.all_fonts[self.w._target_value.get()] # print info print 'transfering anchors...\n' print '\tsource: %s' % get_full_name(source_font) print '\ttarget: %s' % get_full_name(target_font) print print '\t', # batch transfer anchors skipped = [] for glyph_name in get_glyphs(source_font): if len(source_font[glyph_name].anchors) > 0: if target_font.has_key(glyph_name): print glyph_name, # prepare undo target_font[glyph_name].prepareUndo('transfer anchors') # transfer anchors transfer_anchors(source_font[glyph_name], target_font[glyph_name]) # update target_font[glyph_name].changed() # activate undo target_font[glyph_name].performUndo() else: skipped.append(glyph_name) else: # glyph does not have anchors pass # done print target_font.changed() if len(skipped) > 0: print '\n\tglyphs %s not in target font.\n' % skipped print '...done.\n' else: print no_font_open
def apply_callback(self, sender): if len(self._all_fonts) > 0: # get parameters _source_font = self._all_fonts[self.w._source_value.get()] _target_font = self._all_fonts[self.w._target_value.get()] # print info print 'transfering anchors...\n' print '\tsource: %s' % get_full_name(_source_font) print '\ttarget: %s' % get_full_name(_target_font) print print '\t', # batch transfer anchors _skipped = [] for glyph_name in get_glyphs(_source_font): if len(_source_font[glyph_name].anchors) > 0: if _target_font.has_key(glyph_name): print glyph_name, # prepare undo _target_font[glyph_name].prepareUndo('transfer anchors') # transfer anchors transfer_anchors(_source_font[glyph_name], _target_font[glyph_name]) # update _target_font[glyph_name].update() # activate undo _target_font[glyph_name].performUndo() else: _skipped.append(glyph_name) else: # glyph does not have anchors pass # done print _target_font.update() if len(_skipped) > 0: print '\n\tglyphs %s not in target font.\n' % _skipped print '...done.\n' else: print 'please open at least one font.\n'
def paste_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: # get data foreground = self.w.foreground.get() layers = self.w.layers.get() metrics = self.w.metrics.get() anchors = self.w.anchors.get() color = self.w.color.get() # print info bool_string = [False, True] print('pasting data from glyph %s:\n' % self.source_glyph.name) print('\tforeground: %s' % bool_string[foreground]) print('\tlayers: %s' % bool_string[layers]) print('\tmetrics: %s' % bool_string[metrics]) print('\tanchors: %s' % bool_string[anchors]) print('\tcolor: %s' % bool_string[color]) print() print('\tpasting in', end=' ') # copy data for glyph_name in glyph_names: print(glyph_name, end=' ') # prepare undo f[glyph_name].prepareUndo('paste from glyph') # copy outlines in foreground layer if foreground: target_layer = f[glyph_name].getLayer('foreground') pen = target_layer.getPointPen() self.source_glyph.drawPoints(pen) # copy all other layers if layers: for layer_name in self.source_font.layerOrder: source_layer = self.source_glyph.getLayer( layer_name) target_layer = f[glyph_name].getLayer(layer_name) pen = target_layer.getPointPen() source_layer.drawPoints(pen) # copy glyph width if metrics: f[glyph_name].width = self.source_glyph.width # copy anchors if anchors: transfer_anchors(self.source_glyph, f[glyph_name]) # copy mark color if color: f[glyph_name].mark = self.source_glyph.mark # activate undo f[glyph_name].performUndo() # done with glyph f[glyph_name].update() # done f.update() print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)