def apply_callback(self, sender): # get font font = CurrentFont() if font is not None: # get glyphs glyph_names = font.selection if len(glyph_names) > 0: # get values esize = get_esize(font) self.rand_min = self.w.spinner_min.value.get() self.rand_max = self.w.spinner_max.value.get() # randomize elements for glyph_name in glyph_names: w = font[glyph_name].width g = RasterGlyph(font[glyph_name]) g.rasterize() randomize_elements(font[glyph_name], esize, (self.rand_min, self.rand_max)) font[glyph_name].width = w font.update() # 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 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 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: # get layer name layer_name_option = self.w.layer_name.get() # mask layer if not layer_name_option: layer_name = 'background' # font name else: layer_name = os.path.split(self.ufo_path)[1] # import layer print 'importing .ufo...\n' print '\ttarget layer: %s\n' % layer_name ufo = RFont(self.ufo_path, showUI=False) for glyph_name in f.keys(): if ufo.has_key(glyph_name): layer_glyph = f[glyph_name].getLayer(layer_name) pen = layer_glyph.getPointPen() ufo[glyph_name].drawPoints(pen) f[glyph_name].update() f.update() print '...done.\n' # 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 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 _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 _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: # 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 _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 apply_callback(self, sender): font = CurrentFont() _layer_name = self.w._layer_name.get() if _layer_name in font.layerOrder: print 'deleting layer %s...' % _layer_name font.removeLayer(_layer_name) print '...done.\n' font.update() else: print 'font does not have layer %s.' % _layer_name
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 _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 _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 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 _saveImage(self, path, multipage): # extract glyph name and layername for the path # full syntax: 'a(background).glyph' # draw in glyph with name 'a' in the 'background' layer glyphName, ext = os.path.splitext(os.path.basename(path)) # extract the layername layerName = layerNameRE.findall(glyphName) # replace the layername by nothing glyphName = layerNameRE.sub("", glyphName) # layer name found if layerName: layerName = layerName[0] else: layerName = None # if there is an extension --> there is a glyph name # get the glyph from the CurrentFont # otherwise draw in the CurrentGlyph if ext: font = CurrentFont() if glyphName not in font: dest = font.newGlyph(glyphName) if dest is None: raise GlyphDrawBotError("No font available to draw in") dest.width = 500 else: dest = font[glyphName] else: dest = CurrentGlyph() # can not found a proper glyph to draw in if dest is None: raise GlyphDrawBotError("No glyph available to draw in") dest.clear() multiplePages = len(self._glyphs) > 1 for count, glyph in enumerate(self._glyphs): if layerName: if multiplePages: n = "%s_%s" % (layerName, count + 1) else: n = layerName destLayer = dest.getLayer(n) else: destLayer = dest layerName = "drawBot" destLayer.appendGlyph(glyph) if glyph.image: image = glyph.image destImage = destLayer.addImage(image.data) destImage.transformation = image.transformation destImage.brightness = image.brightness
def apply_callback(self, sender): f = CurrentFont() if f is not None: # get parameters _width = int(self.w.width_value.get()) _center = self.w.center_checkbox.get() _split = self.w.split_checkbox.get() _split_relative = self.w.split_relative_checkbox.get() _gNames = f.selection 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', # current glyph glyph = CurrentGlyph() if glyph is not None: print glyph.name, self.set_width(glyph, _width, _w_mode) f.update() print print '\n...done.\n' # selected glyphs else: glyph_names = f.selection if len(glyph_names) > 0: 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 'please select one or more glyphs first.\n' # no font open else: print 'please open a font first.\n'
def _rasterize_callback(self, sender): f = CurrentFont() glyph_names = get_glyphs(f) if len(glyph_names) > 0: self.w.bar.start() print "rasterizing glyphs..." for glyph_name in glyph_names: print '\tscanning %s...' % glyph_name f[glyph_name].prepareUndo('rasterize glyph') g = RasterGlyph(f[glyph_name]) g.rasterize(res=self._gridsize) f[glyph_name].update() f[glyph_name].performUndo() f.update() self.w.bar.stop() print "...done.\n"
def apply_callback(self, sender): f = CurrentFont() if f is not None: print 'importing .ufo into layer...' ufo = RFont(self.ufo_path, showUI=False) layer_name = os.path.split(self.ufo_path)[1] for glyph_name in f.keys(): if ufo.has_key(glyph_name): layer_glyph = f[glyph_name].getLayer(layer_name) pen = layer_glyph.getPointPen() ufo[glyph_name].drawPoints(pen) f[glyph_name].update() f.update() print '...done.\n' else: print 'please open a font first.\n'
def _currentFontChanged(self, info): self.font.naked().removeObserver(self, "Font.Changed") self.font = CurrentFont() self.font.naked().addObserver(self, "fontWasModified", "Font.Changed") self.fillAnchorsAndMarksDicts() del self.glyphNamesList[:] del self.selectedGlyphNamesList[:] self.updateExtensionWindow()
def set_element_callback(self, sender): font = CurrentFont() if font is not None: # get parameters shape = self.shapes[self.w.shape.get()] scale = float(self.w.spinner_size.value.get()) magic = float(self.w.spinner_magic.value.get()) # create element glyph if not font.has_key(self.element_glyph): font.newGlyph(self.element_glyph) # draw element shape font[self.element_glyph].prepareUndo('set element') set_element(font, scale, type=shape, magic=magic, element_=self.element_glyph) font[self.element_glyph].performUndo() # no font open else: print no_font_open
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 __init__(self): self.font = CurrentFont() if self.font is None: return doc = self.font.document() if doc is None: return self.window = doc.getMainWindow() vanilla.dialogs.getFolder(parentWindow=self.window, resultCallback=self.generate)
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 set_element_callback(self, sender): font = CurrentFont() if font is not None: # get parameters shape = self.shapes[self.w.shape.get()] scale = float(self.w.spinner_size.value.get()) magic = float(self.w.spinner_magic.value.get()) # create element glyph if not font.has_key(self.element_glyph): font.newGlyph(self.element_glyph) # draw element shape font[self.element_glyph].prepareUndo('set element') set_element(font, scale, type=shape, magic=magic, element_src=self.element_glyph) font[self.element_glyph].performUndo() # 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
class GenerateImageFont(object): def __init__(self): self.font = CurrentFont() if self.font is None: return doc = self.font.document() if doc is None: return self.window = doc.getMainWindow() vanilla.dialogs.getFolder(parentWindow=self.window, resultCallback=self.generate) def generate(self, saveDir): if not saveDir: return saveDir = saveDir[0] f = self.font.naked() glyphs = [g for g in f if not g.template] progress = ProgressWindow("Generating .png's", tickCount=len(glyphs), parentWindow=self.window) gridSize = int(getExtensionDefault(GRID_DEFAULTS_KEY, 50)) for g in glyphs: if g.unicode is not None: fileName = "%04X" %g.unicode else: fileName = glyphNameToFileName(g.name, f) path = os.path.join(saveDir, "%s.png" %fileName) image = g.getRepresentation("com.typemytype.pixelImageFactory", gridSize=gridSize) data = image.TIFFRepresentation() imageRep = NSBitmapImageRep.imageRepWithData_(data) pngData = imageRep.representationUsingType_properties_(NSPNGFileType, None) pngData.writeToFile_atomically_(path, False) progress.update() progress.close()
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 _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 checkFont(self, useSelection=False, excludeZeroWidth=True): f = CurrentFont() if f is not None: # initialize things self.w.options.progress.start() time0 = time.time() self.excludeZeroWidth = excludeZeroWidth self.f = f glyphNames = f.selection if useSelection else f.keys() glyphList = [f[x] for x in glyphNames] glyphList = self._trimGlyphList(glyphList) self.touchingPairs = Touche(f).findTouchingPairs(glyphList) # display output self.w.results.stats.set("%d glyphs checked" % len(glyphList)) self.w.results.result.set("%d touching pairs found" % len(self.touchingPairs)) self.w.results.show(True) outputList = [{"left glyph": g1, "right glyph": g2} for (g1, g2) in self.touchingPairs] self.w.outputList.set(outputList) if len(self.touchingPairs) > 0: self.w.outputList.setSelection([0]) else: self.w.preview.set("") outputButtons = [self.w.results.spaceView, self.w.results.exportTxt] for b in outputButtons: b.enable(False) if len(self.touchingPairs) == 0 else b.enable(True) self.w.preview.setFont(f) self.w.options.progress.stop() self._resizeWindow(enlarge=True) time1 = time.time() print u"Touché: finished checking %d glyphs in %.2f seconds" % (len(glyphList), time1 - time0) else: Message(u"Touché: Can’t find a font to check")
def calcItalicCallback(self, sender): italicAngle = self.getItalicAngle() italicSlantOffset = self.getItalicSlantOffset() if sender == self.w.crossHeightSetUC and CurrentFont() is not None: crossHeight = (CurrentFont().info.capHeight or 0) / 2.0 sender = self.w.crossHeight elif sender == self.w.crossHeightSetLC and CurrentFont() is not None: crossHeight = (CurrentFont().info.xHeight or 0) / 2.0 sender = self.w.crossHeight else: crossHeight = self.getCrossHeight() if sender == self.w.italicAngle or sender == self.w.italicSlantOffset: self.setCrossHeight( calcCrossHeight(italicAngle=italicAngle, italicSlantOffset=italicSlantOffset)) elif sender == self.w.crossHeight: self.setItalicSlantOffset( calcItalicSlantOffset(italicAngle=italicAngle, crossHeight=crossHeight)) self.setCrossHeight(crossHeight) self.updateBowtie()
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 move_anchors(self, xxx_todo_changeme): (x, y) = xxx_todo_changeme f = CurrentFont() if f is not None: glyph_names = get_glyphs(f) if len(glyph_names) > 0: self.get_parameters() print('moving anchors in glyphs...\n') print('\tanchors: %s' % self.anchor_names) print('\tmove: %s, %s' % (x, y)) print() print('\t', end=' ') for glyph_name in glyph_names: print(glyph_name, end=' ') if self.anchors_layers: for layer_name in f.layerOrder: layer_glyph = f[glyph_name].getLayer(layer_name) layer_glyph.prepareUndo('move anchors') move_anchors(layer_glyph, self.anchor_names, (x, y)) layer_glyph.performUndo() layer_glyph.update() # f[glyph_name].update() else: f[glyph_name].prepareUndo('move anchors') move_anchors(f[glyph_name], self.anchor_names, (x, y)) f[glyph_name].performUndo() # done glyph f[glyph_name].update() 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): 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 __init__(self): self.extensionID = self.getExtensionID() self.font = CurrentFont() self.glyph = CurrentGlyph() self._initSettings() self._loadSettings() self.w = self._buildUI() self._addObservers() self.setUpBaseWindowBehavior() self.w.open() #self.glyph.prepareUndo("Glyph Processor") UpdateCurrentGlyphView()
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 glyphPopCallback(self, sender): if self.activeFontPath == CURRENT_FONT_REPR: activeFont = CurrentFont() else: activeFont = getOpenedFontFromPath(AllFonts(), self.activeFontPath) if sender.get() == 0: self.activeGlyphName = CurrentGlyph().name elif sender.get() == 1: self.activeGlyphName = None else: self.activeGlyphName = self.glyphPop.getItems()[sender.get()] self.callback(self)
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() left_value = int(self.w.spinner_left.value.get()) right = self.w.right_checkbox.get() right_mode = self.w.right_mode.get() right_value = int(self.w.spinner_right.value.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], left_value, boolstring[left]) print '\tright: %s %s [%s]' % (self.modes[right_mode], right_value, boolstring[right]) print print '\t', # set margins for glyph_name in glyph_names: print glyph_name, self.set_margins(f[glyph_name], (left, left_value, left_mode), (right, right_value, right_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 convertCurrentGlyphCallback(self, sender): g = CurrentGlyph() if None == g: return layerToConvert = self.layers[self.w.layerPopup.get()] if layerToConvert == 'foreground': Message( "I can only convert contours from a layer different from 'foreground'." ) return g.flipLayers('foreground', layerToConvert) g.copyToLayer(layerToConvert) convert(g, self.maxDistanceValue, self.minLengthValue, self.useArcLength) CurrentFont().changed() UpdateCurrentGlyphView()
def get_font(self): self.font = CurrentFont() if self.font is not None: self.w.box.font_name.set(get_full_name(self.font)) self.w.hairspace_value.set(int(self.font.info.unitsPerEm * self.hairspace_factor)) self.w.thickspace_value.set(int(self.font.info.unitsPerEm * self.thickspace_factor)) self.w.thinspace_value.set(int(self.font.info.unitsPerEm * self.thinspace_factor)) self.w.figurespace_value.set(int(self.font.info.unitsPerEm * self.figurespace_factor)) else: self.w.box.font_name.set('(None)') self.w.hairspace_value.set('') self.w.thickspace_value.set('') self.w.thinspace_value.set('') self.w.figurespace_value.set('') print no_font_open
def refresh(self, sender=None): f = CurrentFont() if f: italicSlantOffset = f.lib.get(self.italicSlantOffsetKey) or 0 italicAngle = f.info.italicAngle or 0 crossHeight = calcCrossHeight(italicAngle=italicAngle, italicSlantOffset=italicSlantOffset) self.setItalicSlantOffset(italicSlantOffset) self.setItalicAngle(italicAngle) self.setCrossHeight(crossHeight) else: self.setItalicSlantOffset(0) self.setItalicAngle(0) self.setCrossHeight(0) self.updateBowtie()
def chooseRightGlyph(aFontPath, aGlyphName): if aGlyphName == CURRENT_GLYPH_REPR: absGlyphName = CurrentGlyph().name else: absGlyphName = aGlyphName if aFontPath == CURRENT_FONT_REPR: absFontPath = CurrentFont().path else: absFontPath = aFontPath for eachFont in AllFonts(): if eachFont.path == absFontPath: if eachFont.has_key(absGlyphName): return eachFont[absGlyphName] else: return None
def apply_callback(self, sender): _overwrite = self.w._overwrite.get() _mark = self.w._mark.get() # the apply button was pressed before getting the list file if not self.list_path: print 'please get a names list first.\n' return f = CurrentFont() if f is not None: names_list = read_names_list_from_file(self.list_path) if len(names_list) > 0: rename_glyphs_from_list(f, names_list, overwrite=_overwrite, mark=_mark) # no glyph selected else: print no_glyph_selected # no font open 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 calculateBoundingBox(self, sender=None): xmin = [9999, ""] ymin = [9999, ""] xmax = [-9999, ""] ymax = [-9999, ""] for g in CurrentFont(): if g.bounds: if xmin[0] > g.bounds[0]: xmin[0] = g.bounds[0] xmin[1] = g.name if ymin[0] > g.bounds[1]: ymin[0] = g.bounds[1] ymin[1] = g.name if xmax[0] < g.bounds[2]: xmax[0] = g.bounds[2] xmax[1] = g.name if ymax[0] < g.bounds[3]: ymax[0] = g.bounds[3] ymax[1] = g.name self.xmin = xmin self.ymin = ymin self.xmax = xmax self.ymax = ymax PostNotification('doodle.updateGlyphView') if hasattr(self, 'w'): l = [] # if hasattr(self, 'w'): l.append(dict(B='←', glyphname=xmin[1], value=xmin[0])) l.append(dict(B='↓', glyphname=ymin[1], value=ymin[0])) l.append(dict(B='→', glyphname=xmax[1], value=xmax[0])) l.append(dict(B='↑', glyphname=ymax[1], value=ymax[0])) l.append( dict(B='↔︎', glyphname="full width", value=self.xmax[0] - self.xmin[0])) l.append( dict(B='↕︎', glyphname="full height", value=self.ymax[0] - self.ymin[0])) # {"B": 'a', "glyphname": self.xmin[1], "value": str( # self.xmin[0])} self.w.results.set(l)
def getOtherMaster(nextFont=True): cf = CurrentFont() orderedFonts = [] fonts = {} for f in AllFonts(): if f.path is None: continue fonts[f.path]=f sortedPaths = list(fonts.keys()) sortedPaths.sort() for i in range(len(sortedPaths)): if cf.path == fonts[sortedPaths[i]].path: prev = fonts[sortedPaths[i-1]] nxt = fonts[sortedPaths[(i+1)%len(sortedPaths)]] if nextFont: return nxt else: return prev
def click(self, sender): t = sender.tag f = CurrentFont() if f is None: return names = self.getSelection() copyable = "" if t == "names": copyable = self._asSpacedNames(names) elif t == "comma": copyable = self._asQuotesAndCommasNames(names) elif t == "slash": copyable = self._asSlashedNames(names) elif t == "feature": copyable = self._asFeatureGroup(names) elif t == "unicode": copyable = self._asUnicodeText(names) self._toPasteBoard(copyable) self.w.caption.set("%d names to clipboard!" % (len(names)))
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 generateFontCallback(self, sender): progress = self.startProgress("Generating Shifters...") font = CurrentFont() outFont = RFont(showInterface=False) outFont.info.update(font.info.asDict()) outFont.features.text = font.features.text attrValues = self.getAttributes() for glyph in font: outFont.newGlyph(glyph.name) outGlyph = outFont[glyph.name] outGlyph.width = glyph.width outGlyph.unicodes = glyph.unicodes resultGlyph = self.getGlyph(glyph, *attrValues, addComponents=True, skipComponents=True) outGlyph.appendGlyph(resultGlyph) progress.close() outFont.openInterface()
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 _up_right_callback(self, sender): if len(self.all_fonts) > 1: # get next font f = CurrentFont() i = self.all_fonts.index(f) try: next_i = i + 1 next_font = self.all_fonts[next_i] except IndexError: next_i = 0 next_font = self.all_fonts[next_i] # get glyph g_current = CurrentGlyph() if g_current is not None: if g_current.name in next_font: next_glyph = next_font[g_current.name] else: next_glyph = next_font[next_font.glyphOrder[0]] # switch to glyph window G = OpenGlyphWindow(next_glyph, newWindow=False) # update UI self.update()
def _down_left_callback(self, sender): if len(self.all_fonts) > 1: # get next font f = CurrentFont() i = self.all_fonts.index(f) try: prev_i = i - 1 prev_font = self.all_fonts[prev_i] except IndexError: prev_i = -1 prev_font = self.all_fonts[prev_i] # get glyph g_current = CurrentGlyph() if g_current is not None: if g_current.name in prev_font: prev_glyph = prev_font[g_current.name] else: prev_glyph = prev_font[prev_font.glyphOrder[0]] # switch to glyph window G = OpenGlyphWindow(prev_glyph, newWindow=False) # update UI self.update()
def roundFontButtonCallback(self, sender): if self.sourceLayerName == self.targetLayerName: self.showMessage('ERROR', LAYERS_MATCH) self.rounderLogger.error(LAYERS_MATCH) return None if self.selectedFont == CurrentFont(): self.rounderLogger.info( 'start: roundFontButtonCallback(), {} {}'.format( selectedFont.info.familyName, selectedFont.info.styleName)) for eachGlyph in self.selectedFont: makeGlyphRound(eachGlyph, self.roundingsData, sourceLayerName=self.sourceLayerName, targetLayerName=self.targetLayerName) self.rounderLogger.info( 'end: roundFontButtonCallback(), {} {}'.format( selectedFont.info.familyName, selectedFont.info.styleName)) else: self.showMessage('ERROR', FONT_MISMATCH) self.rounderLogger.error(FONT_MISMATCH)
def runButtonCallback(self, sender): if self.target == 'All Fonts': fontsToProcess = AllFonts() else: fontsToProcess = [CurrentFont()] for eachFont in fontsToProcess: for eachRow in self.transferList: if len(eachRow) == 2: eachTarget, eachSource = eachRow else: eachTarget, eachSource = eachRow[0], eachRow[1:] if eachTarget not in eachFont: targetGlyph = eachFont.newGlyph(eachTarget) else: targetGlyph = eachFont[eachTarget] targetGlyph.clear() if isinstance(eachSource, types.ListType) is False: targetGlyph.width = eachFont[eachSource].width if eachFont.info.italicAngle: anchorAngle = radians(-eachFont.info.italicAngle) else: anchorAngle = radians(0) tangentOffset = tan(anchorAngle) * self.verticalOffset targetGlyph.appendComponent( eachSource, (tangentOffset, self.verticalOffset)) else: offsetX = 0 for eachSourceGlyphName in eachSource: targetGlyph.appendComponent(eachSourceGlyphName, (offsetX, 0)) offsetX += eachFont[eachSourceGlyphName].width targetGlyph.width = offsetX
def _print_callback(self, sender): font = CurrentFont() if font is not None: # get selected glyphs glyph_names = get_glyphs(font) if len(glyph_names) > 0: # get resolution gridsize = int(self.w.spinner.value.get()) res = (gridsize, gridsize) # print bit libs print "printing glyphs...\n" for glyph_name in glyph_names: glyph = font[glyph_name] R = RasterGlyph(glyph) R.print_bits(res=res) # done print "...done.\n" # no glyph selected else: print no_glyph_selected # no font open else: print no_font_open
def applyCallback(self, sender): self._holdGlyphUpdates = True font = CurrentFont() attrValues = self.getAttributes() selection = [] if CurrentGlyphWindow(): selection = [CurrentGlyph().name] else: selection = font.selectedGlyphNames for name in selection: glyph = font[name] glyph.prepareUndo("Shifter") outGlyph = self.getGlyph(glyph, *attrValues) glyph.clear() glyph.appendGlyph(outGlyph) glyph.performUndo() self._holdGlyphUpdates = False
def __init__(self, posSize, title, isActive, openedFontPaths, activeFontPath, activeGlyphName, callback): Group.__init__(self, posSize) self.isActive = isActive self.openedFontPaths = openedFontPaths self.activeFontPath = activeFontPath self.activeGlyphName = activeGlyphName self.callback = callback ctrlWidth = posSize[2] # ui jumpingY = 4 self.isActiveCheck = CheckBox( (0, jumpingY, ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']), title, value=self.isActive, callback=self.isActiveCallback) jumpingY += vanillaControlsSize['CheckBoxRegularHeight'] + 2 self.fontPop = PopUpButton( (1, jumpingY, ctrlWidth - 1, vanillaControlsSize['PopUpButtonRegularHeight']), makeFontList(openedFontPaths), callback=self.fontPopCallback) jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + MARGIN_VER if self.activeFontPath == CURRENT_FONT_REPR: activeFont = CurrentFont() else: activeFont = getOpenedFontFromPath(AllFonts(), self.activeFontPath) self.glyphPop = PopUpButton( (1, jumpingY, ctrlWidth - 1, vanillaControlsSize['ComboBoxRegularHeight']), makeGlyphList(activeFont), callback=self.glyphPopCallback)