class transferAnchorsDialog(object): _title = 'transfer anchors' _all_fonts_names = [] _source_mark_color = randomColor() _target_mark_color = randomColor() _width = 280 _height = 247 _padding = 15 _padding_top = 8 _row_height = 25 _column_1 = 130 def __init__(self): if len(AllFonts()) > 0: self._all_fonts = AllFonts() for f in self._all_fonts: self._all_fonts_names.append(get_full_name(f)) self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # source font self.w._source_label = TextBox( (self._padding, self._padding_top + (self._row_height * 0), -self._padding, 17), "source font") self.w._source_value = PopUpButton( (self._padding, self._padding_top + (self._row_height * 1), -self._padding, 20), self._all_fonts_names) # source color self.w.source_mark_checkbox = CheckBox( (self._padding, self._padding_top + (self._row_height * 2) + 6, -self._padding, 20), "mark glyphs", value=True) self.w.source_mark_color = ColorWell( (self._column_1, self._padding_top + (self._row_height * 2) + 8, -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._source_mark_color)) # division 1 self.w.line_1 = HorizontalLine( (self._padding, self._padding_top + (self._row_height * 4) - 8, -self._padding, 1)) # target font self.w._target_label = TextBox( (self._padding, self._padding_top + (self._row_height * 4), -self._padding, 17), "target font") self.w._target_value = PopUpButton( (self._padding, self._padding_top + (self._row_height * 5), -self._padding, 20), self._all_fonts_names) # target color self.w.target_mark_checkbox = CheckBox( (self._padding, self._padding_top + (self._row_height * 6) + 6, -self._padding, 20), "mark glyphs", value=True) self.w.target_mark_color = ColorWell( (self._column_1, self._padding_top + (self._row_height * 6) + 8, -self._padding - 3, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._target_mark_color)) # division 2 self.w.line_2 = HorizontalLine( (self._padding, self._padding_top + (self._row_height * 8) - 8, -self._padding, 1)) # buttons self.w.button_apply = Button( (self._padding, -45, (self._width / 2) - 15, 0), "apply", callback=self.apply_callback) self.w.button_close = Button( (self._width / 2 + 5, -45, -self._padding, 0), "close", callback=self.close_callback) # open window self.w.open() else: print 'please open one or more fonts to use this dialog.\n' def apply_callback(self, sender): # get source font parameters _source_font = self._all_fonts[self.w._source_value.get()] _source_mark = self.w.source_mark_checkbox.get() _source_mark_color = self.w.source_mark_color.get() _source_mark_color = (_source_mark_color.redComponent(), _source_mark_color.greenComponent(), _source_mark_color.blueComponent(), _source_mark_color.alphaComponent()) # get target font parameters _target_font = self._all_fonts[self.w._target_value.get()] _target_mark = self.w.target_mark_checkbox.get() _target_mark_color = self.w.target_mark_color.get() _target_mark_color = (_target_mark_color.redComponent(), _target_mark_color.greenComponent(), _target_mark_color.blueComponent(), _target_mark_color.alphaComponent()) # print info boolstring = [False, True] print 'transfering anchors...\n' print '\tsource font: %s' % get_full_name(_source_font) print '\tsource color: %s, %s' % (_source_mark_color, boolstring[_source_mark]) print print '\ttarget font: %s' % get_full_name(_target_font) print '\ttarget color: %s, %s' % (_target_mark_color, boolstring[_target_mark]) print print '\t', # batch copy glyphs to mask for gName in _source_font.selection: try: print gName, # prepare undo _target_font[gName].prepareUndo('transfer anchors') # transfer anchors has_anchor = transferAnchors(_source_font[gName], _target_font[gName]) if has_anchor: # mark if _source_mark: _source_font[gName].mark = _source_mark_color if _target_mark: _target_font[gName].mark = _target_mark_color # update _source_font[gName].update() _target_font[gName].update() # activate undo _source_font[gName].performUndo() _target_font[gName].performUndo() except: print '\tcannot transform %s' % gName # done print _target_font.update() _source_font.update() print '\n...done.\n' def close_callback(self, sender): self.w.close()
class copyToLayerDialog(object): _title = 'copy to layer' _mark_color = randomColor() _padding = 10 def __init__(self, ): self.w = FloatingWindow( (190, 140), self._title, closable=False) # layer self.w._layers_label = TextBox( (self._padding, self._padding, -self._padding, 17), "target layer:") self.w._layers_value = EditText( (self._padding, 35, -self._padding, 21), placeholder='layer name') # mark color self.w.mark_checkbox = CheckBox( (self._padding, 70, -self._padding, 20), "mark glyphs", value=True) self.w.mark_color = ColorWell( (120, 70, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color)) # buttons self.w.button_apply = Button( (self._padding, -45, 80, 0), "apply", callback=self.apply_callback) self.w.button_close = Button( (-90, -45, 80, 0), "close", callback=self.close_callback) # open window self.w.open() def apply_callback(self, sender): f = CurrentFont() print f if f is not None: # get layer _layer_index = self.w._layers_value.get() _layer_name = self.w._layers_value.get() # get mark color _mark = self.w.mark_checkbox.get() _mark_color = self.w.mark_color.get() _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) # batch copy to layer if len(_layer_name) > 0: print 'copying outlines to layer "%s"...' % _layer_name print _mark_color for gName in f.selection: try: f[gName].prepareUndo('copy to layer') print '\t%s' % gName, f[gName].copyToLayer(_layer_name, clear=True) if _mark: f[gName].mark = _mark_color f[gName].performUndo() f[gName].update() except: print '\tcannot transform %s' % gName # done print '\n...done.\n' # no valid layer name else: print 'please set a name for the target layer.\n' # no font open else: print 'please open a font before running this script.\n' def close_callback(self, sender): self.w.close()
class changeSuffixDialog(object): _title = 'change suffix' _height = 140 _width = 210 _padding = 10 _column_1 = 100 _row_height = 30 _mark_color = randomColor() _old_suffix = '' _new_suffix = '' def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # old suffix self.w._old_suffix_label = TextBox( (self._padding, self._padding + (self._row_height * 0), -self._padding, 20), "old suffix") self.w._old_suffix_value = EditText( ((self._width / 2), self._padding + (self._row_height * 0), -self._padding, 20), placeholder='old suffix', text=self._old_suffix, callback=self.old_suffix_callback) # new suffix self.w._new_suffix_label = TextBox( (self._padding, self._padding + (self._row_height * 1), -self._padding, 20), "new suffix") self.w._new_suffix_value = EditText( ((self._width / 2), self._padding + (self._row_height * 1), -self._padding, 20), placeholder='optional', text=self._new_suffix, callback=self.new_suffix_callback) # mark color self.w.mark_checkbox = CheckBox( (self._padding, self._padding + (self._row_height * 2), -self._padding, 20), "mark", value=True) self.w.mark_color = ColorWell( ((self._width / 2), self._padding + (self._row_height * 2), -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w.button_close = Button( (self._padding, -35, (self._width / 2) - 10, 20), "close", callback=self.close_callback) self.w.button_apply = Button( ((self._width / 2) + 10, -35, -self._padding, 20), "apply", callback=self.apply_callback) # open window self.w.setDefaultButton(self.w.button_apply) self.w.button_close.bind(".", ["command"]) self.w.button_close.bind(unichr(27), []) self.w.open() def old_suffix_callback(self, sender): self._old_suffix = sender.get() def new_suffix_callback(self, sender): self._new_suffix = sender.get() def apply_callback(self, sender): f = CurrentFont() if f is not None: if len(f.selection) > 0: # get parameters _old = self._old_suffix _new = self._new_suffix _mark = self.w.mark_checkbox.get() _mark_color = self.w.mark_color.get() boolstring = (False, True) # print info print 'changing glyph name suffixes...\n' print '\told suffix: %s' % _old print '\tnew suffix: %s' % _new print '\tmark: %s' % boolstring[_mark] print _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) # batch change names for gName in f.selection: if gName is not None: if has_suffix(gName, _old): g = f[gName] # make new name _new_name = change_suffix(gName, _old, _new) print '\trenaming %s to %s...' % (gName, _new_name) if f.has_key(_new_name): print '\toverwriting %s' % _new_name f.removeGlyph(_new_name) g.name = _new_name g.mark = _mark_color g.update() print else: g.name = _new_name if _mark: g.mark = _mark_color g.update() # done 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 close_callback(self, sender): self.w.close()
class transformSelectedGlyphsDialog(object): _title = 'transform selected glyphs' _clear = False _round = False _decompose = False _order = False _direction = False _overlaps = False _extremes = False _mark = True _gNames = [] _mark_color = randomColor() _width = 220 _height = 285 _row_height = 25 _padding = 15 _padding_top = 10 def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # clear outlines self.w.clear_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 0), -self._padding, 20), "clear outlines", callback=self.clear_Callback, value=self._clear) # round point positions self.w.round_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 1), -self._padding, 20), "round point positions", callback=self.round_Callback, value=self._round) # decompose self.w.decompose_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 2), -self._padding, 20), "decompose", callback=self.decompose_Callback, value=self._decompose) # auto contour order self.w.order_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 3), -self._padding, 20), "auto contour order", callback=self.order_Callback, value=self._order) # auto contour direction self.w.direction_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 4), -self._padding, 20), "auto contour direction", callback=self.direction_Callback, value=self._direction) # remove overlaps self.w.overlaps_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 5), -self._padding, 20), "remove overlaps", callback=self.overlaps_Callback, value=self._overlaps) # add extreme points self.w.extremes_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 6), -self._padding, 20), "add extreme points", callback=self.extremes_Callback, value=self._extremes) # mark self.w.line = HorizontalLine( (self._padding, self._padding_top + (self._row_height * 7) + 10, -self._padding, 1)) self.w.mark_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 8), -self._padding, 20), "mark", callback=self.mark_Callback, value=self._mark) self.w.mark_color = ColorWell( (80, self._padding_top + (self._row_height * 8), -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w.button_apply = Button( (self._padding, -55, (self._width / 2) - 20, 0), "apply", callback=self.apply_Callback) self.w.button_close = Button( ((self._width / 2) + 5, -55, -self._padding, 0), "close", callback=self.close_Callback) # open window self.w.open() def clear_Callback(self, sender): self._clear = sender.get() def round_Callback(self, sender): self._round = sender.get() def decompose_Callback(self, sender): self._decompose = sender.get() def order_Callback(self, sender): self._order = sender.get() def direction_Callback(self, sender): self._direction = sender.get() def overlaps_Callback(self, sender): self._overlaps = sender.get() def extremes_Callback(self, sender): self._extremes = sender.get() def mark_Callback(self, sender): self._mark = sender.get() def apply_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()) print 'transforming selected glyphs...\n' for gName in f.selection: try: print '\ttransforming %s...' % gName if self._clear: print '\tdeleting outlines %s' % gName f[gName].prepareUndo('clear glyph contents') f.newGlyph(gName, clear=True) f[gName].performUndo() if self._round: print '\trounding %s' % gName f[gName].prepareUndo('round point positions') f[gName].round() f[gName].performUndo() if self._decompose: print '\t\tdecomposing...' f[gName].prepareUndo('decompose') f[gName].decompose() f[gName].performUndo() if self._overlaps: print '\t\tremoving overlaps...' f[gName].prepareUndo('remove overlaps') f[gName].removeOverlap() f[gName].performUndo() if self._extremes: print '\t\tadding extreme points...' f[gName].prepareUndo('add extreme points') f[gName].extremePoints() f[gName].performUndo() if self._order: print '\t\tauto contour order...' f[gName].prepareUndo('auto contour order') f[gName].autoContourOrder() f[gName].performUndo() if self._direction: print '\t\tauto contour direction...' f[gName].prepareUndo('auto contour directions') f[gName].correctDirection() f[gName].performUndo() if self._mark: print '\t\tmark glyphs...' f[gName].prepareUndo('mark') f[gName].mark = _mark_color f[gName].performUndo() print except: print '\tcannot transform %s\n' % gName # done print '...done.\n' # no font open else: print 'please open a font.\n' def close_Callback(self, sender): self.w.close()
class createSpaceGlyphsDialog(object): _title = 'create space glyphs' _height = 320 _padding = 15 _padding_top = 10 _column_1 = 160 _field_width = 60 _row_height = 30 _mark_color = randomColor() _hairspace_factor = .08 _thinspace_factor = .16 _thickspace_factor = .333 _figurespace_factor = .6 def __init__(self): self._width = self._column_1 + self._field_width + (self._padding * 3) if CurrentFont() is not None: self.font = CurrentFont() self.w = FloatingWindow((self._width, self._height), self._title, closable=True) # current font self.w.box = Box( (self._padding, self._padding_top + (self._row_height * 0), -self._padding, 26)) self.w.box.text = TextBox((5, 1, -10, 20), text=get_full_name(self.font), sizeStyle='small') # hair space self.w._hairspace_label = TextBox( (self._padding, self._padding_top + (self._row_height * 1) + 10, self._column_1, 20), "hair space") self.w._hairspace_value = EditText( (self._column_1 + (self._padding * 2), self._padding_top + (self._row_height * 1) + 10, self._field_width, 20), text=int(self.font.info.unitsPerEm * self._hairspace_factor)) # thin space self.w._thinspace_label = TextBox( (self._padding, self._padding_top + (self._row_height * 2) + 10, self._column_1, 20), "thin space") self.w._thinspace_value = EditText( (self._column_1 + (self._padding * 2), self._padding_top + (self._row_height * 2) + 10, self._field_width, 20), text=int(self.font.info.unitsPerEm * self._thinspace_factor)) # thick space self.w._thickspace_label = TextBox( (self._padding, self._padding_top + (self._row_height * 3) + 10, self._column_1, 20), "thick space") self.w._thickspace_value = EditText( (self._column_1 + (self._padding * 2), self._padding_top + (self._row_height * 3) + 10, self._field_width, 20), text=int(self.font.info.unitsPerEm * self._thickspace_factor)) # figure space self.w._figurespace_label = TextBox( (self._padding, self._padding_top + (self._row_height * 4) + 10, self._column_1, 20), "figure space") self.w._figurespace_value = EditText( (self._column_1 + (self._padding * 2), self._padding_top + (self._row_height * 4) + 10, self._field_width, 20), text=int(self.font.info.unitsPerEm * self._figurespace_factor)) # zero width space self.w._zerowidth_label = TextBox( (self._padding, self._padding_top + (self._row_height * 5) + 10, self._column_1, 20), "zero-width space") self.w._zerowidth_value = EditText( (self._column_1 + (self._padding * 2), self._padding_top + (self._row_height * 5) + 10, self._field_width, 20), text='0', readOnly=True) # division self.w.line_1 = HorizontalLine( (self._padding, self._padding_top + (self._row_height * 6) + 15, -self._padding, 1)) # mark color self.w._mark_checkbox = CheckBox( (self._padding, self._padding_top + (self._row_height * 7), self._column_1, 20), "mark", value=True) self.w._mark_color = ColorWell( (self._column_1 + (self._padding * 2), self._padding_top + (self._row_height * 7), self._field_width, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w._button_apply = Button( (self._padding, -65, -self._padding, 20), "create glyphs", sizeStyle='small', callback=self.apply_callback) self.w._button_switch = Button( (self._padding, -35, -self._padding, 20), "switch to current font", sizeStyle='small', callback=self.update_font_callback) # open window self.w.open() # no font open else: print 'please open a font first.\n' def apply_callback(self, sender): _hairspace = int(self.w._hairspace_value.get()) _thinspace = int(self.w._thinspace_value.get()) _thickspace = int(self.w._thickspace_value.get()) _figurespace = int(self.w._figurespace_value.get()) _mark = self.w._mark_checkbox.get() _mark_color = self.w._mark_color.get() _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) boolstring = (False, True) if self.font is not None: # print info print 'creating space glyphs...\n' print '\thair space: %s units' % _hairspace print '\tthin space: %s units' % _thinspace print '\tthick space: %s units' % _thickspace print '\tfigure space: %s units' % _figurespace print '\tzero-width space: 0' print '\tmark: %s' % boolstring[_mark] # hair space self.font.newGlyph('hairspace') self.font['hairspace'].width = _hairspace self.font['hairspace'].mark = _mark_color self.font['hairspace'].unicode = unicodeHexstrToInt('uni200A') self.font['hairspace'].update() # thin space self.font.newGlyph('thinspace') self.font['thinspace'].width = _thinspace self.font['thinspace'].mark = _mark_color self.font['thinspace'].unicode = unicodeHexstrToInt('uni2009') self.font['thinspace'].update() # thick space self.font.newGlyph('thickspace') self.font['thickspace'].width = _thickspace self.font['thickspace'].mark = _mark_color self.font['thickspace'].unicode = unicodeHexstrToInt('uni2004') self.font['thickspace'].update() # figure space self.font.newGlyph('figurespace') self.font['figurespace'].width = _figurespace self.font['figurespace'].mark = _mark_color self.font['figurespace'].unicode = unicodeHexstrToInt('uni2007') self.font['figurespace'].update() # zero-width space self.font.newGlyph('zerowidthspace') self.font['zerowidthspace'].width = 0 self.font['zerowidthspace'].mark = _mark_color self.font['zerowidthspace'].unicode = unicodeHexstrToInt('uni200B') self.font['zerowidthspace'].update() # done self.font.update() print print '...done.\n' else: print 'No font selected, please close the dialog and try again.\n' def update_font_callback(self, sender): self.font = CurrentFont() self.w.box.text.set(get_full_name(self.font)) def close_callback(self, sender): self.w.close()
class roundToGridDialog(object): _title = 'round to grid' _gNames = [] _width = 200 _height = 210 _gridsize = 30 _mark_color = randomColor() _mark = True _points = True _sidebearings = True _anchors = True _padding = 15 _padding_top = 10 _row_height = 25 def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # grid size self.w._gridsize_label = TextBox( (self._padding, self._padding_top + (self._row_height * 0), -self._padding, 17), "grid size") self.w._gridsize_value = EditText( (100, self._padding_top + (self._row_height * 0), -self._padding, 21), text=self._gridsize) # division self.w._line = HorizontalLine( (self._padding, self._padding_top + (self._row_height * 1) + 10, -self._padding, 1)) # points self.w._points_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 2), -self._padding, 20), "point positions", value=self._points) # sidebearings self.w._sidebearings_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 3), -self._padding, 20), "side-bearings", value=self._sidebearings) # anchors self.w._anchors_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 4), -self._padding, 20), "anchor positions", value=self._anchors) # mark self.w._mark_checkBox = CheckBox( (self._padding, self._padding_top + (self._row_height * 5), -self._padding, 20), "mark", value=self._mark) self.w._mark_color = ColorWell( (80, self._padding_top + (self._row_height * 5), -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w.button_apply = Button( (self._padding, -55, (self._width / 2) - 20, 0), "apply", callback=self.apply_Callback) self.w.button_close = Button( ((self._width / 2) + 5, -55, -self._padding, 0), "close", callback=self.close_Callback) self.w.open() def apply_Callback(self, sender): f = CurrentFont() if f is not None: print 'processing selected glyphs...\n' # get options boolstring = [False, True] _points = self.w._points_checkBox.get() _sidebearings = self.w._sidebearings_checkBox.get() _anchors = self.w._anchors_checkBox.get() # get color _gridsize = int(self.w._gridsize_value.get()) _mark = self.w._mark_checkBox.get() _mark_color = self.w._mark_color.get() _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) print '\tgrid size: %s' % _gridsize print '\talign points to grid: %s' % boolstring[_points] print '\talign side-bearings: %s' % boolstring[_sidebearings] print '\talign anchors: %s' % boolstring[_anchors] print '\tmark glyphs: %s (%s)' % (boolstring[_mark], _mark_color) print print '\t', # batch do stuff for gName in f.selection: print gName, f[gName].prepareUndo('align to grid') if _points: roundPointsToGrid(f[gName], (_gridsize, _gridsize)) if _anchors: roundAnchorsToGrid(f[gName], (_gridsize, _gridsize)) if _sidebearings: roundMargins(f[gName], _gridsize, left=True, right=True) if _mark: f[gName].mark = _mark_color f[gName].update() f[gName].performUndo() # done print f.update() print '\n...done.\n' def close_Callback(self, sender): self.w.close()
class setWidthDialog(object): _title = 'set character width' _mark_color = randomColor() _default_width = 400 _height = 102 _width = 210 _padding = 10 def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # left self.w.width_label = TextBox( (self._padding, self._padding, -self._padding, 20), "width") self.w.width_value = EditText((80, self._padding, -15, 20), placeholder='set value', text=self._default_width) # center self.w.center_checkbox = CheckBox( (self._padding, 40, -self._padding, 20), "center", value=False) self.w.mark_checkbox = CheckBox((80, 40, -self._padding, 20), "mark", value=True) self.w.mark_color = ColorWell( (140, 40, -15, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w.button_close = Button( (self._padding, -30, (self._width / 2) - 15, 20), "close", callback=self.close_callback) self.w.button_apply = Button( ((self._width / 2) + 5, -30, -self._padding, 20), "apply", callback=self.apply_callback) # open window self.w.setDefaultButton(self.w.button_apply) self.w.button_close.bind(".", ["command"]) self.w.button_close.bind(unichr(27), []) self.w.open() def apply_callback(self, sender): f = CurrentFont() if f is not None: if len(f.selection) > 0: # get parameters _width = self.w.width_value.get() _mark = self.w.mark_checkbox.get() _mark_color = self.w.mark_color.get() _center = self.w.center_checkbox.get() _gNames = f.selection boolstring = (False, True) # print info print 'setting character widths...\n' print '\twidth: %s' % _width print '\tmark: %s' % boolstring[_mark] print '\tmark color: %s' % _mark_color print '\tcenter: %s' % boolstring[_center] print '\tglyphs: %s' % _gNames print # batch set width for glyphs _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) for gName in _gNames: try: f[gName].prepareUndo('set glyph width') f[gName].width = int(_width) if _center: centerGlyph(f[gName]) if _mark: f[gName].mark = _mark_color f[gName].performUndo() f[gName].update() except: print '\tcannot transform %s' % gName # done print f.update() 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' def close_callback(self, sender): self.w.close()
# [h] mark composed glyphs from hTools2.modules.color import clearColors, randomColor f = CurrentFont() clearColors(f) mark_color = randomColor() for g in f: if len(g.components) > 0: g.mark = mark_color g.update() f.update()
class renameAnchorsDialog(object): _title = 'rename anchors' _mark_color = randomColor() _height = 140 _width = 210 _padding = 10 _column_1 = 100 _row_height = 30 def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # old name self.w._old_name_label = TextBox( (self._padding, self._padding + (self._row_height * 0), -self._padding, 20), "old name") self.w._old_name_value = EditText( ((self._width / 2), self._padding + (self._row_height * 0), -self._padding, 20), placeholder='old name', text='') # new name self.w._new_name_label = TextBox( (self._padding, self._padding + (self._row_height * 1), -self._padding, 20), "new name") self.w._new_name_value = EditText( ((self._width / 2), self._padding + (self._row_height * 1), -self._padding, 20), placeholder='new name', text='') # mark color self.w.mark_checkbox = CheckBox( (self._padding, 70, -self._padding, 20), "mark", value=True) self.w.mark_color = ColorWell( ((self._width / 2), 70, -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w.button_close = Button( (self._padding, -35, (self._width / 2) - 10, 20), "close", callback=self.close_callback) self.w.button_apply = Button( ((self._width / 2) + 10, -35, -self._padding, 20), "apply", callback=self.apply_callback) # open window self.w.setDefaultButton(self.w.button_apply) self.w.button_close.bind(".", ["command"]) self.w.button_close.bind(unichr(27), []) self.w.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() _mark = self.w.mark_checkbox.get() _mark_color = self.w.mark_color.get() boolstring = (False, True) # print info print 'changing anchor names...\n' print '\told name: %s' % _old print '\tnew name: %s' % _new print '\tmark: %s' % boolstring[_mark] print # batch change anchors names _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) for gName in f.selection: if gName is not None: # rename anchor has_name = renameAnchor(f[gName], _old, _new) # mark if has_name: if _mark: f[gName].mark = _mark_color f[gName].update() # done f.update() 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 close_callback(self, sender): self.w.close()
class copySidebearingsDialog(object): _title = 'copy side-bearings' _mark_color_source = randomColor() _mark_color_dest = randomColor() _all_fonts_names = [] _width = 280 _height = 300 _padding = 15 _padding_top = 10 def __init__(self, ): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) self._all_fonts = AllFonts() for f in self._all_fonts: self._all_fonts_names.append(get_full_name(f)) # source font self.w._source_label = TextBox( (self._padding, self._padding_top, -self._padding, 17), "source font:") self.w._source_value = PopUpButton( (self._padding, 35, -self._padding, 20), self._all_fonts_names) # mark source self.w.mark_source_checkbox = CheckBox( (self._padding, 65, -self._padding, 20), "mark glyphs", value=True) self.w.mark_source_color = ColorWell( (120, 65, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color_source)) # dest font self.w._dest_label = TextBox((self._padding, 100, -self._padding, 17), "target font:") self.w._dest_value = PopUpButton( (self._padding, 125, -self._padding, 20), self._all_fonts_names) # mark dest self.w.mark_dest_checkbox = CheckBox( (self._padding, 155, -self._padding, 20), "mark glyphs", value=True) self.w.mark_dest_color = ColorWell( (120, 155, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color_dest)) self.w.line = HorizontalLine((self._padding, 200, -self._padding, 1)) # left / right self.w.left_checkbox = CheckBox( (self._padding, 215, -self._padding, 20), "copy left", value=True) self.w.right_checkbox = CheckBox( (self._width / 2, 215, -self._padding, 20), "copy right", value=True) self.w.line2 = HorizontalLine((self._padding, 250, -self._padding, 1)) # buttons self.w.button_apply = Button( (self._padding, -50, self._width / 2 - 15, 0), "apply", callback=self.apply_callback) self.w.button_close = Button( (self._width / 2 + 5, -50, -self._padding, 0), "close", callback=self.close_callback) # open window self.w.open() def apply_callback(self, sender): 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] _source_mark = self.w.mark_source_checkbox.get() _source_mark_color = self.w.mark_source_color.get() _source_mark_color = (_source_mark_color.redComponent(), _source_mark_color.greenComponent(), _source_mark_color.blueComponent(), _source_mark_color.alphaComponent()) # 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] _dest_mark = self.w.mark_dest_checkbox.get() _dest_mark_color = self.w.mark_dest_color.get() _dest_mark_color = (_dest_mark_color.redComponent(), _dest_mark_color.greenComponent(), _dest_mark_color.blueComponent(), _dest_mark_color.alphaComponent()) # 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 gName in _source_font.selection: try: # set undo _source_font[gName].prepareUndo('copy side-bearings') _dest_font[gName].prepareUndo('copy side-bearings') print '\t%s' % gName, # copy if _left: _dest_font[gName].leftMargin = _source_font[ gName].leftMargin if _right: _dest_font[gName].rightMargin = _source_font[ gName].rightMargin # mark if _source_mark: _source_font[gName].mark = _source_mark_color if _dest_mark: _dest_font[gName].mark = _dest_mark_color # call undo _dest_font.performUndo() _dest_font.update() _dest_font.performUndo() _dest_font.update() except: print '\tcannot process %s' % gName print print '\n...done.\n' # nothing selected else: print 'Aborted, nothing to copy. Please select "left" or "right" side-bearings, and try again.\n' def close_callback(self, sender): self.w.close()
class setSidebearingsDialog(object): _title = 'set sidebearings' _modes = [ 'do nothing' , 'set equal to', 'increase by', 'decrease by', ] _mark_color = randomColor() _width = 280 _height = 150 _padding = 10 _column_1 = 120 def __init__(self): self.w = FloatingWindow( (self._width, self._height), self._title, closable=False) # left self.w.left_label = TextBox( (self._padding, self._padding, -self._padding, 17), "left") self.w.left_mode = PopUpButton( (60, self._padding, self._column_1, 20), self._modes, callback=self.left_mode_callback) self.w.left_value = EditText( (195, self._padding, -self._padding, 20), placeholder = 'set value') self.w.left_value.enable(False) # right self.w.right_label = TextBox( (self._padding, 40, -self._padding, 17), "right") self.w.right_mode = PopUpButton( (60, 40, self._column_1, 20), self._modes, callback=self.right_mode_callback) self.w.right_value = EditText( (195, 40, -self._padding, 20), placeholder='set value') self.w.right_value.enable(False) # colors self.w.mark_checkbox = CheckBox( (self._padding, 75, -170, 20), "mark glyphs", value = True) self.w.mark_color = ColorWell( (120, 75, -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color)) # buttons self.w.button_apply = Button( (self._padding, -35, (self._width / 2) - self._padding, 20), "apply", callback=self.apply_callback) self.w.button_close = Button( ((self._width / 2) + self._padding, -35, -self._padding, 20), "close", callback=self.close_callback) # open window self.w.setDefaultButton(self.w.button_apply) self.w.button_close.bind(".", ["command"]) self.w.button_close.bind(unichr(27), []) self.w.open() def left_mode_callback(self, sender): self.w.left_value.enable(sender.get() != 0) def right_mode_callback(self, sender): self.w.right_value.enable(sender.get() != 0) def apply_callback(self, sender): f = CurrentFont() if f is not None: if len(f.selection) > 0: # get sidebearings _left_mode = self.w.left_mode.get() _left_value = self.w.left_value.get() _right_mode = self.w.right_mode.get() _right_value = self.w.right_value.get() # get mark color _mark_color = self.w.mark_color.get() _mark_color = (_mark_color.redComponent(), _mark_color.greenComponent(), _mark_color.blueComponent(), _mark_color.alphaComponent()) # print info print 'setting sidebearings for selected glyphs...\n' print '\tleft: %s %s' % (self._modes[_left_mode], _left_value) print '\tright: %s %s' % (self._modes[_right_mode], _right_value) print '\tmark color: %s' % (False, True)[self.w.mark_checkbox.get()] # batch set left/right sidebearings in one pass for gName in f.selection: try: f[gName].prepareUndo('change sidebearings') # left sidebearing if _left_mode != 0: if _left_value != None: # calculate left sidebearing if _left_mode == 1: # set equal to _left_value_new = int(_left_value) elif _left_mode == 2: # increase by _left_value_new = f[gName].leftMargin + int(_left_value) elif _left_mode == 3: # decrease by _left_value_new = f[gName].leftMargin - int(_left_value) # set left sidebearing f[gName].leftMargin = _left_value_new f[gName].mark = _mark_color f[gName].update() f.update() # right sidebearing if _right_mode != 0: if _right_value != None: # calculate right sidebearing if _right_mode == 1: # set equal to _right_value_new = int(_right_value) elif _right_mode == 2: # increase by _right_value_new = f[gName].rightMargin + int(_right_value) elif _right_mode == 3: # decrease by _right_value_new = f[gName].rightMargin - int(_right_value) # set right sidebearing f[gName].rightMargin = _right_value_new f[gName].mark = _mark_color f[gName].update() f.update() # done glyph f[gName].performUndo() f[gName].update() # famous Cmd+A exception except: print '\tcannot transform %s' % gName # done f.update() print '\n...done.\n' # no glyph selected else: print 'please select one or more glyphsto transform.\n' # no font open else: print 'please open a font first.\n' def close_callback(self, sender): self.w.close()