def select_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: glyph_name = get_glyphs(f)[0] color = f[glyph_name].mark print 'selecting glyphs:\n' print '\t', # print '\tcolor: %s %s %s %s' % color glyph_names = [] for glyph in f: if glyph.mark == color: print glyph.name, glyph_names.append(glyph.name) #print '\tglyphs: %s' % glyph_names f.selection = glyph_names print print '\n...done.\n' # no glyph selected else: print 'please select a glyph first.\n' # no font open else: print 'please open a font first.\n'
def skew_glyphs(self, angle): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) if len(glyph_names) > 0: if self.offset_x: self.offset_x = math.tan(math.radians(angle)) * (font.info.xHeight / 2.0) else: self.offset_x = 0 for glyph_name in glyph_names: font[glyph_name].prepareUndo('skew') # RF 2.0 if version[0] == '2': font[glyph_name].skewBy(angle, origin=(self.offset_x, 0)) # RF 1.8.X else: font[glyph_name].skew(angle, offset=(self.offset_x, 0)) font[glyph_name].performUndo() # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def copy_callback(self, sender): f = CurrentFont() glyph_name = get_glyphs(f)[0] print 'copied glyph %s' % glyph_name self.source_font = f self.source_glyph = self.source_font[glyph_name] print
def _clear_callback(self, sender): font = CurrentFont() if font is not None: for glyph_name in get_glyphs(font): font[glyph_name].prepareUndo('clear mask') mask_layer = font[glyph_name].getLayer(self.background_layer) mask_layer.clear() font[glyph_name].performUndo() # RF 2.0 if version[0] == '2': font[glyph_name].changed() # RF 1.8.X else: font[glyph_name].update() # RF 2.0 if version[0] == '2': font.changed() # RF 1.8.X else: font.update() else: print no_font_open
def apply_callback(self, sender): f = CurrentFont() if f is not None: if len(f.selection) > 0: # get parameters _old = self.w._old_name_value.get() _new = self.w._new_name_value.get() boolstring = (False, True) # print info print 'renaming anchors in glyphs...\n' print '\told name: %s' % _old print '\tnew name: %s' % _new print print '\t', # batch change anchors names glyph_names = get_glyphs(f) for glyph_name in glyph_names: print glyph_name, # rename anchor f[glyph_name].prepareUndo('rename anchor') has_name = rename_anchor(f[glyph_name], _old, _new) f[glyph_name].performUndo() f[glyph_name].update() # done f.update() print print '\n...done.\n' # no glyph selected else: print 'please select one or more glyphs before running the script.\n' # no glyph selected else: print 'please open a font first.\n'
def apply_callback(self, sender): f = CurrentFont() if f is not None: print 'applying actions to selected glyphs...\n' for action in self.actions.keys(): if self.actions[action]: print '\t%s' % action print print '\t', for glyph in get_glyphs(f, mode='glyphs'): print glyph.name, # current layer only if not self.actions['all layers']: self._apply_actions(glyph) # all layers else: for layer_name in f.layerOrder: layer_glyph = f[glyph.name].getLayer(layer_name) self._apply_actions(layer_glyph) # done glyph glyph.update() # done font print print '\n...done.\n' # no font open else: print 'please open a font first.\n'
def update(self): self.glyph_window = CurrentGlyphWindow() if self.glyph_window is not None: self.glyph = CurrentGlyph() self.font = self.glyph.getParent() self.glyph_index = self.font.glyphOrder.index(self.glyph.name) self.font_index = self.all_fonts.index(self.font) self._update_text_box() return True else: f = CurrentFont() if f is not None: self.font = f self.font_index = self.all_fonts.index(self.font) glyph_names = get_glyphs(f) if len(glyph_names) > 0: self.glyph = self.font[glyph_names[0]] self.glyph_index = self.font.glyphOrder.index( self.glyph.name) self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False) self._update_text_box() return True else: print(no_glyph_selected) return False else: print(no_font_open) return False
def apply_callback(self, sender): if len(self._all_fonts) > 0: # get parameters _source_font = self._all_fonts[self.w._source_value.get()] _target_layer_name = self._target_layer_name _target_font = self._all_fonts[self.w._target_value.get()] # print info print 'copying glyphs to mask...\n' print '\tsource font: %s (foreground)' % get_full_name(_source_font) print '\ttarget font: %s (%s)' % (get_full_name(_target_font), self._target_layer_name) print print '\t', # batch copy glyphs to mask for glyph_name in get_glyphs(_source_font): print glyph_name, # prepare undo _target_font[glyph_name].prepareUndo('copy glyphs to mask') # copy oulines to mask _target_glyph_layer = _target_font[glyph_name].getLayer(_target_layer_name) pen = _target_glyph_layer.getPointPen() _source_font[glyph_name].drawPoints(pen) # update _target_font[glyph_name].update() # activate undo _target_font[glyph_name].performUndo() # done print _target_font.update() print '\n...done.\n' # no font open else: print 'please open at least one font.\n'
def apply_callback(self, sender): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) # transform glyphs if len(glyph_names) > 0: # get parameters delta = int(self.w.delta_spinner.value.get()) join = self.w.join.get() cap = self.w.cap.get() # print info print 'applying stroke to skeletons...\n' print '\tdelta: %s' % delta print '\tjoin style: %s' % self.stroke_parameters[join] print '\tcap style: %s' % self.stroke_parameters[cap] print print '\t', # apply outline for glyph_name in glyph_names: src_glyph = dst_glyph = font[glyph_name] print glyph_name, expand(src_glyph, dst_glyph, delta, join, cap) print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def apply_callback(self, sender): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) # transform glyphs if len(glyph_names) > 0: # get parameters delta = int(self.w.delta_spinner.value.get()) join = self.w.join.get() cap = self.w.cap.get() # print info print('applying stroke to skeletons...\n') print('\tdelta: %s' % delta) print('\tjoin style: %s' % self.stroke_parameters[join]) print('\tcap style: %s' % self.stroke_parameters[cap]) print() print('\t', end=' ') # apply outline for glyph_name in glyph_names: src_glyph = dst_glyph = font[glyph_name] print(glyph_name, end=' ') expand(src_glyph, dst_glyph, delta, join, cap) print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def _flip_callback(self, sender): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) # get foreground anchors anchors_dict = get_anchors(font, glyph_names) for glyph_name in glyph_names: # flip layers (including anchors) font[glyph_name].prepareUndo('flip mask') font[glyph_name].flipLayers('foreground', self.mask_layer) # keep anchors from source layer in foreground if not self.w.flip_anchors.get(): if glyph_name in anchors_dict: for anchor in anchors_dict[glyph_name]: anchor_name, anchor_pos = anchor font[glyph_name].appendAnchor(anchor_name, anchor_pos) font[glyph_name].update() # remove anchors from dest layer dest_glyph = font[glyph_name].getLayer(self.mask_layer) dest_glyph.clearAnchors() # done with glyph font[glyph_name].performUndo() # done with font font.update() else: print(no_font_open)
def apply_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: # get parameters old = self.w._old_name_value.get() new = self.w._new_name_value.get() boolstring = (False, True) # print info print 'renaming anchors in glyphs...\n' print '\told name: %s' % old print '\tnew name: %s' % new print print '\t', # change anchors names for glyph_name in glyph_names: print glyph_name, # rename anchor f[glyph_name].prepareUndo('rename anchor') has_name = rename_anchor(f[glyph_name], old, new) f[glyph_name].performUndo() 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
def _flip_callback(self, sender): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) # get foreground anchors anchors_dict = get_anchors(font, glyph_names) for glyph_name in glyph_names: # flip layers (including anchors) font[glyph_name].prepareUndo('flip mask') font[glyph_name].flipLayers('foreground', self.mask_layer) # keep anchors from source layer in foreground if not self.w.flip_anchors.get(): if anchors_dict.has_key(glyph_name): for anchor in anchors_dict[glyph_name]: anchor_name, anchor_pos = anchor font[glyph_name].appendAnchor(anchor_name, anchor_pos) font[glyph_name].update() # remove anchors from dest layer dest_glyph = font[glyph_name].getLayer(self.mask_layer) dest_glyph.clearAnchors() # done with glyph font[glyph_name].performUndo() # done with font font.update() else: print no_font_open
def paint_callback(self, sender): f = CurrentFont() if f is not None: _mark_color = self.w.mark_color.get() _mark_color = ( _mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent(), ) glyph_names = get_glyphs(f) if len(glyph_names) > 0: print 'painting selected glyphs...\n' print '\tcolor: %s %s %s %s' % _mark_color print print '\t', for glyph_name in glyph_names: print glyph_name, f[glyph_name].prepareUndo('paint glyph') f[glyph_name].mark = _mark_color f[glyph_name].performUndo() print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def _mirror_glyphs(self, xxx_todo_changeme2): (scale_x, scale_y) = xxx_todo_changeme2 f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names): print('reflecting selected glyphs...\n') print('\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') # mirror all layers if self.layers: for layer_name in f.layerOrder: _g = f[glyph_name].getLayer(layer_name) self._mirror_glyph(_g, (scale_x, scale_y)) # mirror active layer only else: self._mirror_glyph(f[glyph_name], (scale_x, scale_y)) # done with glyph f[glyph_name].update() # done with font f.update() print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def apply_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: print('applying actions to selected glyphs...\n') for action in list(self.actions.keys()): if self.actions[action]: print('\t%s' % action) print() print('\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') # current layer only if not self.actions['all layers']: self.apply_actions(f[glyph_name]) # all layers else: for layer_name in f.layerOrder: layer_glyph = f[glyph_name].getLayer(layer_name) self.apply_actions(layer_glyph) # done glyph f[glyph_name].update() # done font print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def _rasterize_callback(self, sender): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) if len(glyph_names) > 0: gridsize = int(self.w.spinner.value.get()) res = (gridsize, gridsize) self.w.bar.start() print "rasterizing glyphs...\n" for glyph_name in glyph_names: glyph = font[glyph_name] print '\tscanning %s...' % glyph_name glyph.prepareUndo('rasterize glyph') R = RasterGlyph(glyph) R.rasterize(res=res) glyph.update() glyph.performUndo() # done font.update() self.w.bar.stop() print "\n...done.\n" # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def apply_callback(self, sender): f = CurrentFont() if f is not None: boolstring = [ 'False', 'True' ] # get parameters _left = self.w.left_checkbox.get() _left_mode = self.w.left_mode.get() _right = self.w.right_checkbox.get() _right_mode = self.w.right_mode.get() # iterate over glyphs glyph_names = get_glyphs(f) if len(glyph_names) > 0: # print info print 'setting margins for selected glyphs...\n' print '\tleft: %s %s [%s]' % (self._modes[_left_mode], self._left_value, boolstring[_left]) print '\tright: %s %s [%s]' % (self._modes[_right_mode], self._right_value, boolstring[_right]) print print '\t\t', # set margins for glyph_name in glyph_names: print glyph_name, self.set_margins(f[glyph_name], (_left, self._left_value, _left_mode), (_right, self._right_value, _right_mode)) f.update() print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def update(self): self.glyph_window = CurrentGlyphWindow() if self.glyph_window is not None: self.glyph = CurrentGlyph() self.font = self.glyph.getParent() self.glyph_index = self.font.glyphOrder.index(self.glyph.name) self.font_index = self.all_fonts.index(self.font) self._update_text_box() return True else: f = CurrentFont() if f is not None: self.font = f self.font_index = self.all_fonts.index(self.font) glyph_names = get_glyphs(f) if len(glyph_names) > 0: self.glyph = self.font[glyph_names[0]] self.glyph_index = self.font.glyphOrder.index(self.glyph.name) self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False) self._update_text_box() return True else: print no_glyph_selected return False else: print no_font_open return False
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 "copying glyphs to mask...\n" print "\tsource font: %s (foreground)" % get_full_name(source_font) print "\ttarget font: %s (%s)" % (get_full_name(target_font), self.target_layer_name) print print "\t", # batch copy glyphs to mask for glyph_name in get_glyphs(source_font): print glyph_name, # prepare undo target_font[glyph_name].prepareUndo("copy glyphs to mask") # copy oulines to mask target_glyph_layer = target_font[glyph_name].getLayer(self.target_layer_name) pen = target_glyph_layer.getPointPen() source_font[glyph_name].drawPoints(pen) # update target_font[glyph_name].update() # activate undo target_font[glyph_name].performUndo() # done print target_font.update() print "\n...done.\n" # no font open else: print no_font_open
def copy_callback(self, sender): f = CurrentFont() glyph_name = get_glyphs(f)[0] print('copied glyph %s' % glyph_name) self.source_font = f self.source_glyph = self.source_font[glyph_name] print()
def apply_callback(self, sender): # no font open if self.font is None: print no_font_open # copy to layers else: # get layers and options source = self.w.layers_source.get() targets = self.w.layers_target.getSelection() overwrite = self.w.checkbox_overwrite.get() # get layer names source_layer = self.layers[source] target_layers = [] for t in targets: target_layers.append(self.layers[t+1]) target_layer_names = ' '.join(target_layers) # copy to selected layers print 'copying glyphs between layers...\n' print '\tsource layer: %s' % self.layers[source] print '\ttarget layers: %s' % target_layer_names print for glyph_name in get_glyphs(self.font): print '\t%s' % glyph_name, source_glyph = self.font[glyph_name].getLayer(source_layer, clear=False) for target_layer in target_layers: target_glyph = self.font[glyph_name].getLayer(target_layer, clear=False) target_glyph.prepareUndo('copy to layer') target_glyph = self.font[glyph_name].getLayer(target_layer, clear=overwrite) source_glyph.copyToLayer(target_layer, clear=False) target_glyph.performUndo() target_glyph.update() # done print print '\n...done.\n'
def apply_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: print 'applying actions to selected glyphs...\n' for action in self.actions.keys(): if self.actions[action]: print '\t%s' % action print print '\t', for glyph_name in glyph_names: print glyph_name, # current layer only if not self.actions['all layers']: self.apply_actions(f[glyph_name]) # all layers else: for layer_name in f.layerOrder: layer_glyph = f[glyph_name].getLayer(layer_name) self.apply_actions(layer_glyph) # done glyph f[glyph_name].update() # done font print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def paint_callback(self, sender): f = CurrentFont() if f is not None: _mark_color = self.w.mark_color.get() _mark_color = ( _mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent(), ) glyph_names = get_glyphs(f) if len(glyph_names) > 0: print('painting selected glyphs...\n') print('\tcolor: %s %s %s %s' % _mark_color) print() print('\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') f[glyph_name].prepareUndo('paint glyph') f[glyph_name].mark = _mark_color f[glyph_name].performUndo() print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def _get_glyphs(self): f = CurrentFont() if f is not None: self.font = f self.glyph_names = get_glyphs(self.font) else: print 'please open a font first.\n' return
def apply_callback(self, sender): f = CurrentFont() if f is not None: # iterate over glyphs glyph_names = get_glyphs(f) if len(glyph_names) > 0: # get parameters width = int(self.w.spinner.value.get()) center = self.w.center_checkbox.get() split = self.w.split_checkbox.get() split_relative = self.w.split_relative_checkbox.get() boolstring = (False, True) # set sidebearings mode if center: w_mode = 'center' elif split: w_mode = 'split difference' elif split_relative: w_mode = 'split relative' else: w_mode = 'default' # print info print 'setting character widths...\n' print '\t%s %s' % (self._modes[self._mode], width) print '\tmode: %s' % w_mode print print '\t', for glyph_name in glyph_names: print glyph_name, self.set_width(f[glyph_name], width, w_mode) # RF 2.0 if version[0] == '2': f.changed() # RF 1.8.X else: f.update() print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def _print_callback(self, sender): f = CurrentFont() glyph_names = get_glyphs(f) if len(glyph_names) > 0: print "printing glyphs...\n" for glyph_name in glyph_names: g = RasterGlyph(f[glyph_name]) g._print(res=self._gridsize) f.update() print "...done.\n"
def _copy_callback(self, sender): font = CurrentFont() if font is not None: for glyph_name in get_glyphs(font): font[glyph_name].prepareUndo('copy to mask') font[glyph_name].copyToLayer(self.mask_layer, clear=False) font[glyph_name].performUndo() font.update() else: print no_font_open
def skew_glyphs(self, angle): font = CurrentFont() if self.offset_x: self.offset_x = math.tan(math.radians(angle)) * (font.info.xHeight / 2) else: self.offset_x = 0 for gName in get_glyphs(font): font[gName].prepareUndo('skew') font[gName].skew(angle, offset=(self.offset_x, 0)) font[gName].performUndo()
def _flip_callback(self, sender): font = CurrentFont() if font is not None: for glyph_name in get_glyphs(font): font[glyph_name].prepareUndo('flip mask') font[glyph_name].flipLayers('foreground', self.mask_layer) font[glyph_name].performUndo() font.update() else: print no_font_open
def apply_callback(self, sender): # no font open if len(self.all_fonts) == 0: print no_font_open # only one font open elif len(self.all_fonts) == 1: print no_other_fonts # two or more fonts open else: boolstring = [False, True] # source font _source_font_index = self.w._source_value.get() _source_font = self.all_fonts[_source_font_index] _source_font_name = self.all_fonts_names[_source_font_index] # dest font _dest_font_index = self.w._dest_value.get() _dest_font = self.all_fonts[_dest_font_index] _dest_font_name = self.all_fonts_names[_dest_font_index] # left / right _left = self.w.left_checkbox.get() _right = self.w.right_checkbox.get() # batch process glyphs if _left or _right: # print info print 'copying side-bearings...\n' print '\tsource font: %s' % _source_font_name print '\ttarget font: %s' % _dest_font_name print print '\tcopy left: %s' % boolstring[_left] print '\tcopy right: %s' % boolstring[_right] print # batch copy side-bearings for glyph_name in get_glyphs(_source_font): try: # set undo _dest_font[glyph_name].prepareUndo('copy margins') print '\t%s' % glyph_name, # copy if _left: _dest_font[glyph_name].leftMargin = _source_font[ glyph_name].leftMargin if _right: _dest_font[glyph_name].rightMargin = _source_font[ glyph_name].rightMargin # call undo _dest_font.performUndo() _dest_font.update() except: print '\tcannot process %s' % glyph_name print print '\n...done.\n' # nothing selected else: print 'Nothing to copy. Please select "left" or "right" side-bearings, and try again.\n'
def _get_glyphs(self): f = CurrentFont() # no font open if f is None: print no_font_open else: self.font = f self.glyph_names = get_glyphs(self.font) # no glyphs selected if len(self.glyph_names) == 0: print no_glyph_selected
def _clear_callback(self, sender): font = CurrentFont() if font is not None: for glyph_name in get_glyphs(font): font[glyph_name].prepareUndo('clear mask') clear_mask = font[glyph_name].getLayer(self.mask_layer, clear=True) font[glyph_name].update() font[glyph_name].performUndo() font.update() else: print no_font_open
def _copy_callback(self, sender): font = CurrentFont() if font is not None: for glyph_name in get_glyphs(font): font[glyph_name].prepareUndo('copy to mask') font[glyph_name].copyToLayer(self.mask_layer, clear=False) font[glyph_name].performUndo() font[glyph_name].update() # font.update() else: print(no_font_open)
def _clear_callback(self, sender): font = CurrentFont() if font is not None: for glyph_name in get_glyphs(font): font[glyph_name].prepareUndo('clear mask') clear_mask = font[glyph_name].getLayer(self.mask_layer, clear=True) font[glyph_name].update() font[glyph_name].performUndo() font.update() else: print(no_font_open)
def apply_callback(self, sender): # get fonts f1_index = self.w.f1_font.get() f2_index = self.w.f2_font.get() f1 = self.all_fonts[f1_index] f2 = self.all_fonts[f2_index] # get glyphs glyph_names = get_glyphs(f1) if len(glyph_names) == 0: glyph_names = f1.keys() # run! check_compatibility(f2, f1, names=glyph_names, report=False)
def apply_callback(self, sender): # no font open if len(self.all_fonts) == 0: print no_font_open # only one font open elif len(self.all_fonts) == 1: print no_other_fonts # two or more fonts open else: boolstring = [False, True] # source font _source_font_index = self.w._source_value.get() _source_font = self.all_fonts[_source_font_index] _source_font_name = self.all_fonts_names[_source_font_index] # dest font _dest_font_index = self.w._dest_value.get() _dest_font = self.all_fonts[_dest_font_index] _dest_font_name = self.all_fonts_names[_dest_font_index] # left / right _left = self.w.left_checkbox.get() _right = self.w.right_checkbox.get() # batch process glyphs if _left or _right: # print info print 'copying side-bearings...\n' print '\tsource font: %s' % _source_font_name print '\ttarget font: %s' % _dest_font_name print print '\tcopy left: %s' % boolstring[_left] print '\tcopy right: %s' % boolstring[_right] print # batch copy side-bearings for glyph_name in get_glyphs(_source_font): try: # set undo _dest_font[glyph_name].prepareUndo('copy margins') print '\t%s' % glyph_name, # copy if _left: _dest_font[glyph_name].leftMargin = _source_font[glyph_name].leftMargin if _right: _dest_font[glyph_name].rightMargin = _source_font[glyph_name].rightMargin # call undo _dest_font.performUndo() _dest_font.update() except: print '\tcannot process %s' % glyph_name print print '\n...done.\n' # nothing selected else: print 'Nothing to copy. Please select "left" or "right" side-bearings, and try again.\n'
def apply_callback(self, sender): boolstring = [ False, True ] f = CurrentFont() if f is not None: if len(f.selection) > 0: # print info print 'changing glyph name suffixes...\n' print '\told suffix: %s' % self._old_suffix print '\tnew suffix: %s' % self._new_suffix print '\toverwrite: %s' % boolstring[self._overwrite] print # batch change glyph names for glyph_name in get_glyphs(f): g = f[glyph_name] # get glyphs with matching suffix if has_suffix(g, self._old_suffix): # make new name if len(self._new_suffix) > 0: _new_name = change_suffix(g, self._old_suffix, self._new_suffix) else: _new_name = change_suffix(g, self._old_suffix, None) # if new name not in font, rename if not f.has_key(_new_name): print '\trenaming %s to %s...' % (glyph_name, _new_name) g.name = _new_name # new name in font else: # overwrite existing if self._overwrite: print "\toverwriting '%s' with '%s'" % (_new_name, glyph_name) f.removeGlyph(_new_name) f.update() g.name = _new_name g.update() # do not overwrite else: print "\t'%s' already exists in font, skipping '%s'" % (_new_name, glyph_name) # glyph name does not have suffix else: pass # done glyph # done font f.update() print print '...done.\n' # no glyph selected else: print 'please select one or more glyphs before running the script.\n' # no glyph selected else: print 'please open a font first.\n' pass
def scale_glyphs(self, xxx_todo_changeme): (factor_x, factor_y) = xxx_todo_changeme boolstring = [False, True] font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) # scale glyphs if len(glyph_names) > 0: print('scaling selected glyphs...\n') print('\tx factor: %s' % factor_x) print('\ty factor: %s' % factor_y) print() print('\tside-bearings: %s' % boolstring[self.x_metrics]) print('\tvertical metrics: %s' % boolstring[self.y_metrics]) print() print('\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') glyph = font[glyph_name] glyph.prepareUndo('scale') left = glyph.leftMargin right = glyph.rightMargin # scale outlines if self.layers: # scale all layers for layer_name in font.layerOrder: layer_glyph = glyph.getLayer(layer_name) layer_glyph.scale((factor_x, factor_y)) # scale active layer only else: glyph.scale((factor_x, factor_y)) # scale horizontal metrics if self.x_metrics: glyph.leftMargin = left * factor_x glyph.rightMargin = right * factor_x # done glyph glyph.performUndo() # scale vertical metrics if self.y_metrics: font.info.xHeight = font.info.xHeight * factor_y font.info.capHeight = font.info.capHeight * factor_y font.info.ascender = font.info.ascender * factor_y font.info.descender = font.info.descender * factor_y # done all glyphs print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def select_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: glyph_name = get_glyphs(f)[0] # RF 2.0 if version[0] == '2': color = f[glyph_name].markColor # RF 1.8.X else: color = f[glyph_name].mark print 'selecting glyphs:\n' print '\t', glyph_names = [] for glyph in f: # RF 2.0 if version[0] == '2': if glyph.markColor == color: print glyph.name, glyph_names.append(glyph.name) # RF 1.8.X else: if glyph.mark == color: print glyph.name, glyph_names.append(glyph.name) f.selection = glyph_names print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
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 apply_callback(self, sender): mode = self.w.print_mode.get() sort_names = self.w.sort_names.get() font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) if len(glyph_names): print_selected_glyphs(font, mode, sort=sort_names) # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def select_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: glyph_name = get_glyphs(f)[0] color = f[glyph_name].mark print('selecting glyphs:\n') print('\t', end=' ') glyph_names = [] for glyph in f: if glyph.mark == color: print(glyph.name, end=' ') glyph_names.append(glyph.name) f.selection = glyph_names print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def move_glyphs(self, xxx_todo_changeme): (x, y) = xxx_todo_changeme f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) # transform glyphs if len(glyph_names) > 0: # get options foreground = self.w.foreground.get() layers = self.w.layers.get() if (layers and foreground) is not False: boolstring = [False, True] # print info if self.verbose: print('moving selected glyphs...\n') print('\tx: %s' % x) print('\ty: %s' % y) print('\tlayers: %s' % boolstring[layers]) print() print('\t', end=' ') # move glyphs for glyph_name in glyph_names: if self.verbose: print(glyph_name, end=' ') f[glyph_name].prepareUndo('move') # all layers if layers: for layer_name in f.layerOrder: glyph = f[glyph_name].getLayer(layer_name) glyph.move((x, y)) # active layer if foreground: f[glyph_name].move((x, y)) # done glyph f[glyph_name].performUndo() f[glyph_name].update() # done font f.update() if self.verbose: print() print('\n...done.\n') # no layer selected else: print(no_layer_selected) # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def apply_callback(self, sender): f = CurrentFont() if f is not None: # iterate over glyphs glyph_names = get_glyphs(f) if len(glyph_names) > 0: # get parameters width = int(self.w.spinner.value.get()) center = self.w.center_checkbox.get() split = self.w.split_checkbox.get() split_relative = self.w.split_relative_checkbox.get() boolstring = (False, True) # set sidebearings mode if center: w_mode = 'center' elif split: w_mode = 'split difference' elif split_relative: w_mode = 'split relative' else: w_mode = None # print info print 'setting character widths...\n' print '\t%s %s' % (self._modes[self._mode], width) print '\tmode: %s' % w_mode print print '\t', for glyph_name in glyph_names: print glyph_name, self.set_width(f[glyph_name], width, w_mode) f.update() print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def slide_callback(self, sender): xValue = self.w.x_slider.get() yValue = self.w.y_slider.get() x = self._moveX - xValue y = self._moveY - yValue self._moveX = xValue self._moveY = yValue glyph_names = get_glyphs(self.font) if len(glyph_names) > 0: for glyph_name in glyph_names: try: self.font[glyph_name].move((-x, -y)) except: print 'cannot transform %s' % glyph_name else: print no_glyph_selected
def apply_callback(self, sender): # no font open if len(self.all_fonts) == 0: print(no_font_open) # only one font open elif len(self.all_fonts) == 1: print(no_other_fonts) # two or more fonts open else: boolstring = [False, True] # source font _source_font_index = self.w._source_value.get() _source_font = self.all_fonts[_source_font_index] _source_font_name = self.all_fonts_names[_source_font_index] # dest font _dest_font_index = self.w._dest_value.get() _dest_font = self.all_fonts[_dest_font_index] _dest_font_name = self.all_fonts_names[_dest_font_index] # center _center = self.w.center_checkbox.get() # print info print('copying widths...\n') print('\tsource font: %s' % _source_font_name) print('\ttarget font: %s' % _dest_font_name) print('\tcenter: %s' % boolstring[_center]) print() print('\t', end=' ') # batch copy side-bearings for glyph_name in get_glyphs(_source_font): if glyph_name in _dest_font: # set undo _dest_font[glyph_name].prepareUndo('copy width') # copy print(glyph_name, end=' ') _dest_font[glyph_name].width = _source_font[ glyph_name].width # center if _center: center_glyph(_dest_font[glyph_name]) # call undo _dest_font[glyph_name].performUndo() _dest_font[glyph_name].update() _dest_font.update() print() print('\n...done.\n')
def apply_callback(self, sender): f = CurrentFont() if f is not None: _top = self.w.top.get() _bottom = self.w.bottom.get() _top_pos = int(self.w.spinner_top.value.get()) _bottom_pos = int(self.w.spinner_bottom.value.get()) _accent = self.w.accent.get() _clear = self.w.clear.get() print _top_delta, type(_top_delta) print _bottom_delta, type(_bottom_delta) glyph_names = get_glyphs(f) if len(glyph_names) > 0: if _clear: print 'removing anchors...\n' clear_anchors(f, glyph_names) print '...done.\n' print 'creating anchors in glyphs...\n' print '\t', for glyph_name in glyph_names: print glyph_name, f[glyph_name].prepareUndo('create anchors') create_anchors(f[glyph_name], top=_top, bottom=_bottom, accent=_accent, top_pos=_top_pos, bottom_pos=_bottom_pos) f[glyph_name].performUndo() f.update() print print "\n...done.\n" else: print no_glyph_selected else: print no_font_open
def clear_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: print('clearing colors from selected glyphs...\n') print('\t\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') clear_color(f[glyph_name]) print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def apply_callback(self, sender): if self.font is not None: glyph_names = get_glyphs(self.font) if len(glyph_names) > 0: guides = self.w.guides.get() print('centering glyphs...\n') print('\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') center_glyph_layers(self.font[glyph_name], self.layer_names, guides) print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def get_color_callback(self, sender): f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: g = f[glyph_names[0]] # get glyph color color = g.mark print('%s: %s\n' % (g.name, color)) # convert rgba to NSColor nscolor = convert_to_nscolor(*color) # set swatch color self.w.mark_color.set(nscolor) # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def skew_glyphs(self, angle): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) if len(glyph_names) > 0: if self.offset_x: self.offset_x = math.tan( math.radians(angle)) * (font.info.xHeight / 2) else: self.offset_x = 0 for glyph_name in glyph_names: font[glyph_name].prepareUndo('skew') font[glyph_name].skew(angle, offset=(self.offset_x, 0)) font[glyph_name].performUndo() # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def apply_callback(self, sender): # copy to layers if self.font is not None: glyph_names = get_glyphs(self.font) if len(glyph_names) > 0: # get layers and options source = self.w.layers_source.get() targets = self.w.layers_target.getSelection() overwrite = self.w.checkbox_overwrite.get() # get layer names source_layer = self.layers[source] target_layers = [] for t in targets: target_layers.append(self.layers[t]) # copy to selected layers print('copying glyphs between layers...\n') print('\tsource layer: %s' % self.layers[source]) print('\ttarget layers: %s' % ' '.join(target_layers)) print() for glyph_name in glyph_names: print('\t%s' % glyph_name, end=' ') source_glyph = self.font[glyph_name].getLayer(source_layer, clear=False) for target_layer in target_layers: target_glyph = self.font[glyph_name].getLayer( target_layer, clear=False) target_glyph.prepareUndo('copy to layer') target_glyph = self.font[glyph_name].getLayer( target_layer, clear=overwrite) source_glyph.copyToLayer(target_layer, clear=False) target_glyph.performUndo() target_glyph.update() # done print() print('\n...done.\n') # no glyph selected else: print(no_glyph_selected) # no font open else: print(no_font_open)
def apply_callback(self, sender): self.font = CurrentFont() if self.font is not None: glyph_names = get_glyphs(self.font) if len(glyph_names) > 0: print 'gridfitting glyphs...\n' # get options options = { 'bpoints': self.w._b_points_checkBox.get(), 'points': self.w._points_checkBox.get(), 'margins': self.w._margins_checkBox.get(), 'width': self.w._width_checkBox.get(), 'anchors': self.w._anchors_checkBox.get(), 'layers': self.w._layers_checkBox.get(), 'gridsize': int(self.w.spinner.value.get()) } # print info boolstring = [False, True] print '\tgrid size: %s' % options['gridsize'] print '\tbPoints: %s' % boolstring[options['bpoints']] print '\tpoints: %s' % boolstring[options['points']] print '\tmargins: %s' % boolstring[options['margins']] print '\twidth: %s' % boolstring[options['width']] print '\tanchors: %s' % boolstring[options['anchors']] print '\tlayers: %s' % boolstring[options['layers']] print print '\t', for glyph_name in glyph_names: print glyph_name, self.gridfit(self.font[glyph_name], options) # done self.font.update() print print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open 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()] glyph_names = get_glyphs(source_font) if len(glyph_names) > 0: # print info print 'copying glyphs to mask...\n' print '\tsource font: %s (foreground)' % get_full_name( source_font) print '\ttarget font: %s (%s)' % (get_full_name(target_font), self.target_layer_name) print print '\t', # batch copy glyphs to mask for glyph_name in glyph_names: print glyph_name, # prepare undo target_font[glyph_name].prepareUndo('copy glyphs to mask') # copy oulines to mask target_glyph_layer = target_font[glyph_name].getLayer( self.target_layer_name) pen = target_glyph_layer.getPointPen() source_font[glyph_name].drawPoints(pen) # update target_font[glyph_name].update() # activate undo target_font[glyph_name].performUndo() # done print target_font.update() print '\n...done.\n' # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def _scan_callback(self, sender): font = CurrentFont() if font is not None: glyph_names = get_glyphs(font) if len(glyph_names) > 0: # get resolution gridsize = int(self.w.spinner.value.get()) res = (gridsize, gridsize) print "scanning glyphs...\n" for glyph_name in glyph_names: glyph = font[glyph_name] R = RasterGlyph(glyph) R.scan(res=res) # done font.update() print "...done.\n" # no glyph selected else: print no_glyph_selected # no font open 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 no_font_open # 'please open at least one font.\n'