def _roundCurrentGlyph(self): if self.sourceLayerName == self.targetLayerName: self.showMessage( 'ERROR', u'source layer name and target layer name should be different') return None currentGlyph = CurrentGlyph() if currentGlyph is not None: self.rounderLogger.info( 'start: _roundCurrentGlyph(), glyph {} from {} {}'.format( currentGlyph.name, self.selectedFont.info.familyName, self.selectedFont.info.styleName)) selectedFont = currentGlyph.getParent() roundingsData = pullRoundingsDataFromFont(selectedFont) if roundingsData is not None: makeGlyphRound(currentGlyph, roundingsData, sourceLayerName=self.sourceLayerName, targetLayerName=self.targetLayerName) UpdateCurrentGlyphView() self.rounderLogger.info( 'end: _roundCurrentGlyph(), glyph {} from {} {}'.format( currentGlyph.name, selectedFont.info.familyName, selectedFont.info.styleName)) elif currentGlyph is not None: self.showMessage('ERROR', NO_DATA_INTO_FONT) self.rounderLogger.error(NO_DATA_INTO_FONT) else: self.showMessage('ERROR', NO_GLYPH_TO_ROUND) self.rounderLogger.error(NO_GLYPH_TO_ROUND)
def drawDuplicateContours(self, contours, scale): glyph = CurrentGlyph() font = glyph.getParent() duplicateContourColor.set() for contourIndex in contours: contour = glyph[contourIndex] pen = CocoaPen(font) contour.draw(pen) path = pen.path path.fill() path.setLineWidth_(5 * scale) path.stroke() xMin, yMin, xMax, yMax = contour.box mid = calcMid((xMin, yMin), (xMax, yMin)) x, y = mid drawString((x, y - (10 * scale)), "Duplicate Contour", 10, scale, duplicateContourColor)
def updateStatus(self, info): glyph = CurrentGlyph() if glyph is None: font = CurrentFont() if font is None: message = "Im just looking around" else: m = self.parseFontInfo(font) message = "Im working on my %s in RoboFont" % m else: font = glyph.getParent() m = self.parseFontInfo(font) message = "Im drawing glyph %s for %s in RoboFont" % (glyph.name, m) cmd = NSAppleScript.alloc().initWithSource_(appleScript % message) cmd.executeAndReturnError_(None)
class switchGlyphDialog(hDialog): """A dialog to navigate through glyphs, fonts and layers of all open fonts. .. image:: imgs/glyph/switch.png """ # methods def __init__(self): # get fonts self.get_fonts() if len(self.all_fonts) > 0: self.title = "switch" self.text_height += 3 self.square_button -= 4 self.height = (self.square_button * 3) + (self.padding_y * 2) self.width = 320 self.w = HUDFloatingWindow((self.width, self.height), self.title) # move buttons x = self.padding_x y = self.padding_y x1 = x + (self.square_button * 1) - 1 x2 = x + (self.square_button * 2) - 2 self.w._up = SquareButton( (x1, y, self.square_button, self.square_button), unichr(8673), callback=self._up_callback) self.w._up_right = SquareButton( (x2 + 8, y, self.square_button - 8, self.square_button - 8), unichr(8599), callback=self._up_right_callback, sizeStyle=self.size_style) y += self.square_button - 1 self.w._left = SquareButton( (x, y, self.square_button, self.square_button), unichr(8672), callback=self._left_callback) self.w._right = SquareButton( (x2, y, self.square_button, self.square_button), unichr(8674), callback=self._right_callback) y += self.square_button - 1 self.w._down_left = SquareButton( (x, y + 8, self.square_button - 8, self.square_button - 8), unichr(8601), callback=self._down_left_callback, sizeStyle=self.size_style) self.w._down = SquareButton( (x1, y, self.square_button, self.square_button), unichr(8675), callback=self._down_callback) # location y = self.padding_y x3 = x2 + self.square_button + 16 self.w.box_font = Box( (x3, y, -self.padding_x, self.text_height)) self.w.box_font.text = TextBox( (5, 0, -self.padding_x, -0), '', sizeStyle=self.size_style) y += self.text_height + self.padding_y self.w.box_glyph = Box( (x3, y, -self.padding_x, self.text_height)) self.w.box_glyph.text = TextBox( (5, 0, -self.padding_x, -0), '', sizeStyle=self.size_style) y += self.text_height + self.padding_y self.w.box_layer = Box( (x3, y, -self.padding_x, self.text_height)) self.w.box_layer.text = TextBox( (5, 0, -self.padding_x, -0), '', sizeStyle=self.size_style) # open if self.update(): # bind # self.w.bind("became key", self.update_callback) self.w.bind("close", self.on_close_window) # observers addObserver(self, "update_callback", "newFontDidOpen") addObserver(self, "update_callback", "fontDidOpen") addObserver(self, "update_callback", "fontDidClose") # open window self.w.open() else: print no_font_open # methods def get_fonts(self): self.all_fonts = AllFonts() def next_glyph(self): next = next_glyph(self.font, self.glyph_index) try: self.glyph_window.setGlyphByName(next) except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.setGlyphByName(next) self.update() def previous_glyph(self): prev = previous_glyph(self.font, self.glyph_index) try: self.glyph_window.setGlyphByName(prev) except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.setGlyphByName(prev) self.update() def layer_down(self): try: self.glyph_window.layerDown() except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.layerDown() self.update() def layer_up(self): try: self.glyph_window.layerUp() except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.layerUp() self.update() def _update_text_box(self): self.w.box_font.text.set(get_full_name(self.font)) self.w.box_glyph.text.set(self.glyph.name) self.w.box_layer.text.set(self.glyph.layerName) 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 # callbacks def _left_callback(self, sender): self.previous_glyph() def _right_callback(self, sender): self.next_glyph() def _up_callback(self, sender): self.layer_up() def _down_callback(self, sender): self.layer_down() 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 next_font.has_key(g_current.name): 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 prev_font.has_key(g_current.name): 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 update_callback(self, sender): self.get_fonts() self.update() def on_close_window(self, sender): removeObserver(self, "newFontDidOpen") removeObserver(self, "fontDidOpen") removeObserver(self, "fontDidClose")
class switchGlyphDialog(hDialog): """A dialog to navigate through glyphs, fonts and layers of all open fonts. .. image:: imgs/glyph/switch.png """ # methods def __init__(self): # get fonts self.get_fonts() if len(self.all_fonts) > 0: self.title = "switch" self.text_height += 3 self.square_button -= 4 self.height = (self.square_button * 3) + (self.padding_y * 2) self.width = 320 self.w = FloatingWindow((self.width, self.height), self.title) # move buttons x = self.padding_x y = self.padding_y x1 = x + (self.square_button * 1) - 1 x2 = x + (self.square_button * 2) - 2 self.w._up = SquareButton( (x1, y, self.square_button, self.square_button), chr(8673), callback=self._up_callback) self.w._up_right = SquareButton( (x2 + 8, y, self.square_button - 8, self.square_button - 8), chr(8599), callback=self._up_right_callback, sizeStyle=self.size_style) y += self.square_button - 1 self.w._left = SquareButton( (x, y, self.square_button, self.square_button), chr(8672), callback=self._left_callback) self.w._right = SquareButton( (x2, y, self.square_button, self.square_button), chr(8674), callback=self._right_callback) y += self.square_button - 1 self.w._down_left = SquareButton( (x, y + 8, self.square_button - 8, self.square_button - 8), chr(8601), callback=self._down_left_callback, sizeStyle=self.size_style) self.w._down = SquareButton( (x1, y, self.square_button, self.square_button), chr(8675), callback=self._down_callback) # location y = self.padding_y x3 = x2 + self.square_button + 16 self.w.box_font = Box((x3, y, -self.padding_x, self.text_height)) self.w.box_font.text = TextBox((5, 0, -self.padding_x, -0), '', sizeStyle=self.size_style) y += self.text_height + self.padding_y self.w.box_glyph = Box((x3, y, -self.padding_x, self.text_height)) self.w.box_glyph.text = TextBox((5, 0, -self.padding_x, -0), '', sizeStyle=self.size_style) y += self.text_height + self.padding_y self.w.box_layer = Box((x3, y, -self.padding_x, self.text_height)) self.w.box_layer.text = TextBox((5, 0, -self.padding_x, -0), '', sizeStyle=self.size_style) # open if self.update(): # bind # self.w.bind("became key", self.update_callback) self.w.bind("close", self.on_close_window) # observers addObserver(self, "update_callback", "newFontDidOpen") addObserver(self, "update_callback", "fontDidOpen") addObserver(self, "update_callback", "fontDidClose") # open window self.w.open() else: print(no_font_open) # methods def get_fonts(self): self.all_fonts = AllFonts() def next_glyph(self): next = next_glyph(self.font, self.glyph_index) try: self.glyph_window.setGlyphByName(next) except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.setGlyphByName(next) self.update() def previous_glyph(self): prev = previous_glyph(self.font, self.glyph_index) try: self.glyph_window.setGlyphByName(prev) except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.setGlyphByName(prev) self.update() def layer_down(self): try: self.glyph_window.layerDown() except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.layerDown() self.update() def layer_up(self): try: self.glyph_window.layerUp() except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.layerUp() self.update() def _update_text_box(self): self.w.box_font.text.set(get_full_name(self.font)) self.w.box_glyph.text.set(self.glyph.name) self.w.box_layer.text.set(self.glyph.layerName) 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 # callbacks def _left_callback(self, sender): self.previous_glyph() def _right_callback(self, sender): self.next_glyph() def _up_callback(self, sender): self.layer_up() def _down_callback(self, sender): self.layer_down() 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 update_callback(self, sender): self.get_fonts() self.update() def on_close_window(self, sender): removeObserver(self, "newFontDidOpen") removeObserver(self, "fontDidOpen") removeObserver(self, "fontDidClose")
class switchGlyphDialog(object): _title = "switch" _padding_top = 8 _padding = 10 _button_1 = 30 _button_2 = 18 _line_height = 18 _box_height = 23 _width = 320 _height = (_button_1 * 3) + (_padding_top * 2) _move_default = 70 def __init__(self): # get fonts self.all_fonts = AllFonts() if len(self.all_fonts) > 0: self.w = FloatingWindow( (self._width, self._height), self._title) # move buttons p = self._padding b1 = self._button_1 b2 = self._button_2 box = self._box_height x = self._padding y = self._padding_top x1 = x + b1 - 1 x2 = x + (b1 * 2) - 2 # buttons self.w._up = SquareButton( (x1, y, b1, b1), unichr(8673), callback=self._up_callback) self.w._up_right = SquareButton( (x2 + 8, y, b1 - 8, b1 - 8), unichr(8599), callback=self._up_right_callback, sizeStyle='small') y += b1 - 1 self.w._left = SquareButton( (x, y, b1, b1), unichr(8672), callback=self._left_callback) self.w._right = SquareButton( (x2, y, b1, b1), unichr(8674), callback=self._right_callback) y += b1 - 1 self.w._down = SquareButton( (x1, y, b1, b1), unichr(8675), callback=self._down_callback) self.w._down_left = SquareButton( (x, y + 8, b1 - 8, b1 - 8), unichr(8601), callback=self._down_left_callback, sizeStyle='small') # location y = p x3 = x2 + b1 + 16 self.w.box_font = Box( (x3, y, -self._padding, self._box_height)) self.w.box_font.text = TextBox( (5, 0, -self._padding, -0), '', sizeStyle='small') y += self._box_height + self._padding_top self.w.box_glyph = Box( (x3, y, -self._padding, self._box_height)) self.w.box_glyph.text = TextBox( (5, 0, -self._padding, -0), '', sizeStyle='small') y += self._box_height + self._padding_top self.w.box_layer = Box( (x3, y, -self._padding, self._box_height)) self.w.box_layer.text = TextBox( (5, 0, -self._padding, -0), '', sizeStyle='small') # open if self.update(): self.w.open() else: print 'please open at least one font first.\n' # methods def next_glyph(self): next = next_glyph(self.font, self.glyph_index) try: self.glyph_window.setGlyphByName(next) except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.setGlyphByName(next) self.update() def previous_glyph(self): prev = previous_glyph(self.font, self.glyph_index) try: self.glyph_window.setGlyphByName(prev) except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.setGlyphByName(prev) self.update() def layer_down(self): try: self.glyph_window.layerDown() except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.layerDown() self.update() def layer_up(self): try: self.glyph_window.layerUp() except AttributeError: self.glyph_window = CurrentGlyphWindow() self.glyph_window.layerUp() self.update() def _update_text_box(self): self.w.box_font.text.set('%s [%s]' % (get_full_name(self.font), self.font_index)) self.w.box_glyph.text.set('%s [%s]' % (self.glyph.name, self.glyph_index)) self.w.box_layer.text.set(self.glyph.layerName) 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 'please select a glyph first.\n' return False else: print 'please open a font first.\n' return False # callbacks def _left_callback(self, sender): self.previous_glyph() def _right_callback(self, sender): self.next_glyph() def _up_callback(self, sender): self.layer_up() def _down_callback(self, sender): self.layer_down() 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 next_font.has_key(g_current.name): 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 prev_font.has_key(g_current.name): 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()