def glyph_setBasics(self, mode): font = pFont() process_glyphs = getProcessGlyphs(pMode) processed_glyphs = [] for n, glyph in enumerate(process_glyphs): if mode == 'flag': wLayers = glyph._prepareLayers(pLayers) for layer in wLayers: glyph.setMark( self.color_codes[self.cmb_select_color.currentText], None) if mode == 'name': new_name = str(self.edt_glyphName.text) if number_token in new_name: token_count = new_name.count(number_token) new_name = new_name.replace('#' * token_count, '%s') % fromat_number( n, token_count) if font.hasGlyph(new_name): new_name = '%s.%s' % (new_name, str(n)) glyph.setName(new_name) if mode == 'tags': glyph.setTags(str(self.edt_glyphTags.text).split(' ')) processed_glyphs.append(glyph.name) font.updateObject( font.fl, 'Set Glyph(s) %s | %s' % (mode, ', '.join(processed_glyphs)))
def shape_replace(self): process_glyphs = getProcessGlyphs(pMode) replace_shape_name = self.cmb_fontShapes.currentText for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) process_shapes_dict = {} for layer in process_layers: replace_shape = self.active_font.findShape( replace_shape_name, layer) selected_shape = glyph.selectedAtShapes(index=False, layer=layer, deep=False)[0][0] if selected_shape is not None: if replace_shape is not None: process_shapes_dict[layer] = (selected_shape, replace_shape, selected_shape.transform) else: print 'ERROR:\t Glyph: %s\tElement: %s not found @Layer: %s' % ( glyph.name, replace_shape_name, layer) for layer, shape_triple in process_shapes_dict.items(): replace_shape.transform = shape_triple[2] # Apply transform glyph.replaceShape(shape_triple[0], shape_triple[1], layer) glyph.update() glyph.updateObject( glyph.fl, 'Glyph: %s;\tInsert Element:%s @ %s.' % (glyph.name, replace_shape_name, '; '.join(process_layers)))
def remove_SmartCorner(self): # Finds active preset in glyphs smart corners and removes them # - Init process_glyphs = getProcessGlyphs(pMode) active_preset = self.getPreset() # - Process if len(process_glyphs): for work_glyph in process_glyphs: if work_glyph is not None: # - Init wLayers = work_glyph._prepareLayers(pLayers) smart_corners, target_corners = [], [] # - Get all smart nodes/corners for layer in wLayers: for builder in work_glyph.getBuilders(layer)[filter_name]: smart_corners += builder.getSmartNodes() if len(smart_corners): for node in smart_corners: wNode = eNode(node) if wNode.getSmartAngleRadius() == float(active_preset[layer]): wNode.delSmartAngle() self.update_glyphs(process_glyphs, True) print 'DONE:\t Filter: Remove Smart Corner; Glyphs: %s' %'; '.join([g.name for g in process_glyphs])
def copyMetrics(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: copyOrder = [ '--' in name for name in (self.edt_lsb.text, self.edt_rsb.text, self.edt_adv.text) ] srcGlyphs = [ str(name).replace('--', '') if len(name) else None for name in (self.edt_lsb.text, self.edt_rsb.text, self.edt_adv.text) ] adjPercents = (self.spb_lsb_percent.value, self.spb_rsb_percent.value, self.spb_adv_percent.value) adjUnits = (self.spb_lsb_units.value, self.spb_rsb_units.value, self.spb_adv_units.value) glyph.copyMetricsbyName(srcGlyphs, pLayers, copyOrder, adjPercents, adjUnits) glyph.updateObject( glyph.fl, 'Copy Metrics | LSB: %s; RSB: %s; ADV:%s.' % (srcGlyphs[0], srcGlyphs[1], srcGlyphs[2])) glyph.update() self.reset_fileds()
def rebuild(self): # - Init process_glyphs = getProcessGlyphs(pMode) # - Process if len(process_glyphs): for glyph in process_glyphs: if glyph is not None: wLayers = glyph._prepareLayers(pLayers) for layer in wLayers: selection = glyph.selectedNodes(layer, filterOn=True, extend=eNode, deep=True) if len(selection) > 1: node_first = selection[0] node_last = selection[-1] line_in = node_first.getPrevLine() if node_first.getPrevOn(False) not in selection else node_first.getNextLine() line_out = node_last.getNextLine() if node_last.getNextOn(False) not in selection else node_last.getPrevLine() crossing = line_in & line_out node_first.smartReloc(*crossing) node_first.parent.removeNodesBetween(node_first.fl, node_last.getNextOn()) glyph.update() glyph.updateObject(glyph.fl, 'Rebuild corner: %s nodes reduced; At layers: %s' %(len(selection), '; '.join(wLayers)))
def adjMetrics(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: wLayers = glyph._prepareLayers(pLayers) copyOrder = [False] * 3 srcGlyphs = [glyph.name] * 3 adjPercents = (self.spb_lsb_percent.value, self.spb_rsb_percent.value, self.spb_adv_percent.value) adjUnits = (self.spb_lsb_units.value, self.spb_rsb_units.value, self.spb_adv_units.value) for layer in wLayers: glyph.setLSB( glyph.getLSB(layer) * adjPercents[0] / 100 + adjUnits[0], layer) glyph.setRSB( glyph.getRSB(layer) * adjPercents[1] / 100 + adjUnits[1], layer) glyph.setAdvance( glyph.getAdvance(layer) * adjPercents[2] / 100 + adjUnits[2], layer) glyph.updateObject( glyph.fl, 'Adjust Metrics @ %s | %s' % ('; '.join(wLayers), zip(('LSB', 'RSB', 'ADV'), adjPercents, adjUnits))) glyph.update()
def shape_autoReorder(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) for layer in process_layers: glyph.reorder_shapes(layer) glyph.update() glyph.updateObject( glyph.fl, 'Auto Shape Order @ %s.' % '; '.join(process_layers))
def shape_ungroupAll(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) for layer in process_layers: glyph.ungroup_all_shapes(layer) glyph.update() glyph.updateObject( glyph.fl, 'Ungroup all Shapes @ %s.' % '; '.join(process_layers))
def setMetricEquations(self, clear=False): process_glyphs = getProcessGlyphs(pMode) modifiers = QtGui.QApplication.keyboardModifiers() for glyph in process_glyphs: wLayers = glyph._prepareLayers(pLayers) for layer in wLayers: if not clear: if len(self.edt_lsb.text): eq_set = self.edt_lsb.text if modifiers == QtCore.Qt.ShiftModifier: selection = glyph.selectedNodes(layer, extend=eNode) diffX = selection[0].diffTo(selection[-1])[0] eq_set += '%s%s' % ([ '-', '+' ][modifiers == QtCore.Qt.ControlModifier], abs(diffX)) glyph.setLSBeq(eq_set, layer) if len(self.edt_rsb.text): eq_set = self.edt_rsb.text if modifiers == QtCore.Qt.AltModifier: selection = glyph.selectedNodes(layer, extend=eNode) diffX = selection[0].diffTo(selection[-1])[0] eq_set += '%s%s' % ([ '-', '+' ][modifiers == QtCore.Qt.ControlModifier], abs(diffX)) glyph.setRSBeq(eq_set, layer) if len(self.edt_adv.text): eq_set = self.edt_adv.text glyph.setADVeq(eq_set, layer) else: glyph.setLSBeq('', layer) glyph.setRSBeq('', layer) glyph.setADVeq('', layer) glyph.update() glyph.updateObject( glyph.fl, 'Set Metrics Equations @ %s.' % '; '.join(wLayers)) self.reset_fileds()
def execute_preset(self, preset_list): # - Init copy_options = self.getCopyOptions() process_glyphs = getProcessGlyphs(self.pMode) print_preset = [' -> '.join(item) for item in preset_list] # - Process for wGlyph in process_glyphs: for process_src, process_dst in preset_list: self.copyLayer(wGlyph, process_src, process_dst, copy_options, True, self.chk_crlayer.isChecked()) wGlyph.update() wGlyph.updateObject( wGlyph.fl, 'Glyph: /%s;\tCopy Layer Preset | %s.' % (wGlyph.name, ' | '.join(print_preset)))
def autoMetricEquations(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: wLayers = glyph._prepareLayers(pLayers) glyph_stat = [] for layer in wLayers: status = glyph.bindCompMetrics(layer) glyph_stat.append(status) glyph.update() glyph.updateObject( glyph.fl, 'Glyph: %s;\tAuto Metrics Equations @ %s.' % (glyph.name, '; '.join('%s: %s' % item for item in zip(wLayers, glyph_stat))))
def glyph_duplicate(self): copy_options = { 'out': self.chk_outline.isChecked(), 'gui': self.chk_guides.isChecked(), 'anc': self.chk_anchors.isChecked(), 'lsb': self.chk_lsb.isChecked(), 'adv': self.chk_adv.isChecked(), 'rsb': self.chk_rsb.isChecked(), 'lnk': self.chk_links.isChecked(), 'ref': self.chk_references.isChecked(), 'flg': self.chk_flag.isChecked(), 'tag': self.chk_tags.isChecked() } # - Init font = pFont() process_glyphs = getProcessGlyphs(pMode) processed_glyphs = [] for glyph in process_glyphs: glyp_name = glyph.name for n in range(self.spb_duplicate.value): new_name = glyp_name + str(self.edt_glyphsuffix.text) token_count = new_name.count(number_token) if number_token in new_name: new_name = new_name.replace('#' * token_count, '%s') % fromat_number( n, token_count) if font.hasGlyph(new_name): new_name = '%s.%s' % (new_name, str(n)) font.duplicateGlyph(glyp_name, new_name, dst_unicode=None, options=copy_options) processed_glyphs.append(new_name) ''' for glyph in process_glyphs: wLayers = glyph._prepareLayers(pLayers) ''' font.updateObject( font.fl, 'Duplicate Glyph(s) | %s' % ', '.join(processed_glyphs))
def shape_delete(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) process_shapes = { layer: glyph.selectedAtShapes(index=False, layer=layer, deep=False)[0][0] for layer in process_layers } for layer, shape in process_shapes.items(): glyph.layer(layer).removeShape(shape) glyph.update() glyph.updateObject( glyph.fl, 'Remove Element @ %s.' % '; '.join(process_layers))
def execute_table(self): # - Init copy_options = self.getCopyOptions() process_glyphs = getProcessGlyphs(self.pMode) # - Process process_dict = self.tab_masters.getTable() process_src = process_dict['SRC'][0] process_dst = process_dict['DST'] for wGlyph in process_glyphs: for dst_layer in process_dst: self.copyLayer(wGlyph, process_src, dst_layer, copy_options, True, self.chk_crlayer.isChecked()) wGlyph.update() wGlyph.updateObject( wGlyph.fl, 'Glyph: /%s;\tCopy Layer | %s -> %s.' % (wGlyph.name, process_src, '; '.join(process_dst)))
def shape_setname(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) for layer in process_layers: #print glyph.selectedAtShapes(index=False, layer=layer, deep=False) wShape = pShape( glyph.selectedAtShapes(index=False, layer=layer, deep=False)[0][0]) wShape.setName(self.edt_shapeName.text) glyph.update() glyph.updateObject( glyph.fl, 'Set Element Name @ %s.' % '; '.join(process_layers)) self.reset_fileds()
def shape_resetTransform(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) for layer in process_layers: wShape = pShape( glyph.selectedAtShapes(index=False, layer=layer, deep=False)[0][0]) wShape.reset_transform() glyph.update() glyph.updateObject( glyph.fl, 'Reset Element transformation data @ %s.' % '; '.join(process_layers)) self.reset_fileds()
def table_execute(self): process_glyphs = getProcessGlyphs(self.pMode) for wGlyph in process_glyphs: if self.pMode != 0: self.get_PointArrays(wGlyph) process_out = [] for layerIndex in range(self.tab_masters.rowCount): if self.tab_masters.item(layerIndex, 0).checkState() == QtCore.Qt.Checked: process_out.append( self.tab_masters.item(layerIndex, 0).text()) self.process_scale(wGlyph, layerIndex, anisotropic=self.chk_single.isChecked(), live_update=False) wGlyph.update() wGlyph.updateObject( wGlyph.fl, '| Delta Machine | Glyph: %s\tLayers procesed: %s' % (wGlyph.name, '; '.join(process_out)))
def apply_SmartCorner(self, remove=False): # NOTE: apply and remove here apply only to soelected nodes. if self.builder is not None: # - Init process_glyphs = getProcessGlyphs(pMode) active_preset = self.getPreset() if remove: # Build a special preset that deletes active_preset = {key:'DEL' for key in active_preset.keys()} # - Process if len(process_glyphs): for work_glyph in process_glyphs: if work_glyph is not None: self.process_smartCorner(work_glyph, active_preset) self.update_glyphs(process_glyphs, True) print 'DONE:\t Filter: Smart Corner; Glyphs: %s' %'; '.join([g.name for g in process_glyphs]) else: print 'ERROR:\t Please specify a Glyph with suitable Shape Builder (Smart corner) first!'
def shape_insert(self): process_glyphs = getProcessGlyphs(pMode) insert_shape_name = self.cmb_fontShapes.currentText for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) for layer in process_layers: insert_shape = self.active_font.findShape( insert_shape_name, layer) if insert_shape is not None: glyph.addShape(insert_shape, layer) else: print 'ERROR:\t Glyph: %s\tElement: %s not found @Layer: %s' % ( glyph.name, insert_shape_name, layer) glyph.update() glyph.updateObject( glyph.fl, 'Glyph: %s;\tInsert Element:%s @ %s.' % (glyph.name, insert_shape_name, '; '.join(process_layers)))
def apply_trap(self): # - Init process_glyphs = getProcessGlyphs(pMode) active_preset = self.getPreset() # - Process if len(process_glyphs): for glyph in process_glyphs: if glyph is not None: wLayers = glyph._prepareLayers(pLayers) for layer in reversed(wLayers): if layer in active_preset.keys(): selection = glyph.selectedNodes(layer, filterOn=True, extend=eNode, deep=True) for node in reversed(selection): preset_values = tuple([float(item.strip()) for item in active_preset[layer].split(',')]) node.cornerTrapInc(*preset_values) glyph.update() glyph.updateObject(glyph.fl, '%s @ %s.' %('Ink Trap', '; '.join(active_preset.keys())))
def moveElement(self, offset_x, offset_y, method): # - Init glyph = eGlyph() font = pFont() process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: wLayers = glyph._prepareLayers(pLayers) for layer in wLayers: selected_shapes = glyph.selectedAtShapes(index=False, layer=layer, deep=False) for shape, contour, node in selected_shapes: wShape = pShape(shape) if method == 'Shift': wShape.shift(offset_x, offset_y) elif method == 'Scale': wShape.scale(1. + offset_x / 100., 1. + offset_y / 100.) elif method == 'Shear': wShape.shear(radians(offset_x), radians(offset_y)) glyph.update() glyph.updateObject( glyph.fl, 'Element: %s @ %s.' % (method, '; '.join(wLayers))) # - Set Undo #glyph.updateObject(glyph.activeLayer(), '%s @ %s.' %(method, glyph.activeLayer().name), verbose=False) # - Finish it glyph.update()
def shape_roundTransform(self): process_glyphs = getProcessGlyphs(pMode) for glyph in process_glyphs: process_layers = glyph._prepareLayers(pLayers) for layer in process_layers: selected_shapes = glyph.selectedAtShapes(index=False, layer=layer, deep=False) if len(selected_shapes): wShape = eShape(selected_shapes[0][0]) wShape.round() else: for s in glyph.shapes(layer, extend=eShape): s.round() glyph.update() glyph.updateObject( glyph.fl, 'Round Element transformation data @ %s.' % '; '.join(process_layers)) self.reset_fileds()
def apply_mitre(self, doKnot=False): # - Init process_glyphs = getProcessGlyphs(pMode) active_preset = self.getPreset() # - Process if len(process_glyphs): for glyph in process_glyphs: if glyph is not None: wLayers = glyph._prepareLayers(pLayers) for layer in reversed(wLayers): if layer in active_preset.keys(): selection = glyph.selectedNodes(layer, filterOn=True, extend=eNode, deep=True) for node in reversed(selection): if not doKnot: node.cornerMitre(float(active_preset[layer])) else: node.cornerMitre(-float(active_preset[layer]), True) action = 'Mitre Corner' if not doKnot else 'Overlap Corner' glyph.update() glyph.updateObject(glyph.fl, '%s @ %s.' %(action, '; '.join(active_preset.keys())))
def alignShapes(self): # - Helpers def getShapeBounds(work_shapes): tmp_bounds = [shape.bounds() for shape in work_shapes] shape_min_X, shape_min_Y, shape_max_X, shape_max_Y = map( set, zip(*tmp_bounds)) return (min(shape_min_X), min(shape_min_Y), max(shape_max_X), max(shape_max_Y)) def getAlignDict(bounds_tuple): align_dict = { 'L': bounds_tuple[0], 'R': bounds_tuple[2], 'C': bounds_tuple[2] / 2, 'B': bounds_tuple[1], 'T': bounds_tuple[3], 'E': bounds_tuple[3] / 2 } return align_dict # - Init user_mode = self.align_mode[self.cmb_align_mode.currentText] user_x = self.align_x[self.cmb_align_x.currentText] user_y = self.align_y[self.cmb_align_y.currentText] keep_x, keep_y = True, True if user_x == 'K': keep_x = False user_x = 'L' if user_y == 'X': keep_y = False user_y = 'B' process_glyphs = getProcessGlyphs(pMode) # - Process for glyph in process_glyphs: selection = glyph.selectedAtShapes(deep=False) wLayers = glyph._prepareLayers(pLayers) for layerName in wLayers: glyph_shapes = glyph.shapes(layerName, extend=eShape) work_shapes = [ glyph_shapes[index] for index in list(set([item[0] for item in selection])) ] if user_mode == 'CL': # Align all shapes in given Layer layer_bounds = glyph.getBounds(layerName) shape_bounds = (layer_bounds.x(), layer_bounds.y(), layer_bounds.x() + layer_bounds.width(), layer_bounds.y() + layer_bounds.height()) align_type = getAlignDict(shape_bounds) target = Coord(align_type[user_x], align_type[user_y]) for shape in glyph_shapes: shape.alignTo(target, user_x + user_y, (keep_x, keep_y)) elif user_mode == 'CC': # Align shapes to shapes if 1 < len(work_shapes) < 3: sh1, sh2 = work_shapes sh1.alignTo(sh2, user_x + user_y, (keep_x, keep_y)) elif len(work_shapes) > 2: shape_bounds = getShapeBounds(work_shapes) align_type = getAlignDict(shape_bounds) target = Coord(align_type[user_x], align_type[user_y]) for shape in work_shapes: shape.alignTo(target, user_x + user_y, (keep_x, keep_y)) elif user_mode == 'RC': # Align shapes to shapes in reverse order if 1 < len(work_shapes) < 3: sh1, sh2 = work_shapes sh2.alignTo(sh1, user_x + user_y, (keep_x, keep_y)) elif len(work_shapes) > 2: shape_bounds = getShapeBounds(work_shapes) align_type = getAlignDict(shape_bounds) target = Coord(align_type[user_x], align_type[user_y]) for shape in reversed(work_shapes): shape.alignTo(target, user_x + user_y, (keep_x, keep_y)) # !!! To be implemented elif user_mode == 'CN': # Align shape to node pass elif user_mode == 'NN': # Align a node on shape to node on another pass glyph.update() glyph.updateObject( glyph.fl, 'Glyph: %s;\tAction: Align Shapes @ %s.' % (glyph.name, '; '.join(wLayers)))
def table_refresh(self): if self.rad_glyph.isChecked(): self.pMode = 0 if self.rad_window.isChecked(): self.pMode = 1 if self.rad_selection.isChecked(): self.pMode = 2 if self.rad_font.isChecked(): self.pMode = 3 self.data_glyphs = getProcessGlyphs(self.pMode)