def __init__(self, *argv): from typerig.brain import Coord, Curve, Line from typerig.node import eNode from fontlab import CurveEx, flNode, flContour multiCheck = lambda t, type: all([isinstance(i, type) for i in t]) if isinstance(argv[0], CurveEx) and multiCheck(argv[1], flNode): self.fl = self.CurveEx = argv[0] self.nodes = argv[1] elif (isinstance(argv[0], list) or isinstance(argv[0], tuple)) and multiCheck(argv[0], flNode): self.nodes = argv[0] self.fl = None if len(self.nodes) == 4: self.n0, self.n1, self.n2, self.n3 = [ eNode(node) for node in self.nodes ] if self.fl is None: self.fl = self.CurveEx = self.n0.getSegment() self.curve = Curve(self.CurveEx) self.line = Line(self.n0.asCoord(), self.n3.asCoord()) self.isCurve = True elif len(self.nodes) == 2: self.n0, self.n1 = [eNode(node) for node in self.nodes] if self.fl is None: self.fl = self.CurveEx = self.n0.getSegment() self.curve = None self.line = Line(self.CurveEx) self.isCurve = False self.contour = self.n0.contour
def valueChanged(self, item): if self.doCheck(): #print item.text(), item.row() try: # Dirty Quick Fix - Solve later # - Init x_col, y_col = self.table_columns.index( 'X'), self.table_columns.index('Y') active_nid = int(self.tab_nodes.item(item.row(), 0).text()) # - Process if item.column() == x_col or item.column() == y_col: new_x = float( self.tab_nodes.item(item.row(), x_col).text()) new_y = float( self.tab_nodes.item(item.row(), y_col).text()) active_node = eNode( self.glyph.nodes( self.cmb_layer.currentText)[active_nid]) active_node.reloc(new_x, new_y) # -- Finish self.glyph.update() self.glyph.updateObject(self.glyph.fl, verbose=False) except AttributeError: pass
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 eqContour(self, method): glyph = eGlyph() selection = glyph.selected(True) wLayers = glyph._prepareLayers(pLayers) for layer in wLayers: # !!! Fixed the problem, but with too many loops - rethink nodes_fl = [glyph.nodes(layer)[nid] for nid in selection] nodes = [eNode(node) for node in nodes_fl] conNodes = [node for node in nodes if node.getNextOn() in nodes_fl] segmentNodes = [node.getSegmentNodes() for node in conNodes] for segment in reversed(segmentNodes): if len(segment) == 4: wSegment = eCurveEx(segment) if method is 'tunni': wSegment.eqTunni() elif method is 'hobby': curvature = (float(self.spn_hobby0.value), float(self.spn_hobby1.value)) wSegment.eqHobbySpline(curvature) elif method is 'prop': proportion = float(self.spn_prop.value) wSegment.eqProportionalHandles(proportion) glyph.updateObject(glyph.fl, 'Optimize %s @ %s.' % (method, '; '.join(wLayers))) glyph.update()
def hobby_get(self): glyph = eGlyph() selSegment = eCurveEx( eNode(glyph.selectedNodes()[0]).getSegmentNodes()) c0, c1 = selSegment.curve.getHobbyCurvature() self.spn_hobby0.setValue(c0.real) self.spn_hobby1.setValue(c1.real)
def pasteSlope(self, mode): from typerig.brain import Line if self.btn_copy.isChecked() or self.btn_italic.isChecked(): glyph = eGlyph() wLayers = glyph._prepareLayers(pLayers) italicAngle = glyph.package.italicAngle_value control = (True, False) for layer in wLayers: selection = [eNode(node) for node in glyph.selectedNodes(layer)] srcLine = self.copyLine[layer] if not self.btn_italic.isChecked() else None if mode == 'MinY': dstLine = Line(min(selection, key=lambda item: item.y).fl, max(selection, key=lambda item: item.y).fl) if not self.btn_italic.isChecked(): dstLine.slope = srcLine.getSlope() else: dstLine.setAngle(-1*italicAngle) elif mode == 'MaxY': dstLine = Line(max(selection, key=lambda item: item.y).fl, min(selection, key=lambda item: item.y).fl) if not self.btn_italic.isChecked(): dstLine.slope = srcLine.getSlope() else: dstLine.setAngle(-1*italicAngle) elif mode == 'FLMinY': dstLine = Line(min(selection, key=lambda item: item.y).fl, max(selection, key=lambda item: item.y).fl) if not self.btn_italic.isChecked(): dstLine.slope = -1.*srcLine.getSlope() else: dstLine.setAngle(italicAngle) elif mode == 'FLMaxY': dstLine = Line(max(selection, key=lambda item: item.y).fl, min(selection, key=lambda item: item.y).fl) if not self.btn_italic.isChecked(): dstLine.slope = -1.*srcLine.getSlope() else: dstLine.setAngle(italicAngle) for node in selection: node.alignTo(dstLine, control) glyph.updateObject(glyph.fl, 'Paste Slope @ %s.' %'; '.join(wLayers)) glyph.update()
def refresh(self, layer=None): # - Init self.glyph = eGlyph() self.edt_glyphName.setText(eGlyph().name) self.table_dict = {} node_count = 0 # - Populate layers if layer is None: self.layer_names = [ item.name for item in self.glyph.layers() if '#' not in item.name ] self.cmb_layer.clear() self.cmb_layer.addItems(self.layer_names) self.cmb_layer.setCurrentIndex( self.layer_names.index(self.glyph.activeLayer().name)) # - Populate table try: # Dirty Quick Fix - Solve later for sID, shape in enumerate(self.glyph.shapes(layer)): for cID, contour in enumerate(shape.contours): for nID, node in enumerate(contour.nodes()): table_values = [ node_count, sID, cID, round(node.x, 2), round(node.y, 2), node.type, round(eNode(node).distanceToPrev(), 2) ] self.table_dict[node_count] = OrderedDict( zip(self.table_columns, table_values)) node_count += 1 self.tab_nodes.setTable(self.table_dict, (False, False)) self.tab_nodes.resizeColumnsToContents() except AttributeError: pass
# - Process -------------------------------------------- for work_glyph in process_glyphs: if work_glyph is not None: # - Init smart_corners = [] # - Get all smart nodes/corners for layer in wLayers: wBuilders = work_glyph.getBuilders(layer) #print work_glyph.name, work_glyph.getBuilders(layer) if wBuilders is not None and filter_name in wBuilders.keys(): if len(wBuilders[filter_name]): for builder in wBuilders[filter_name]: if builder.getSmartNodes() is not None: smart_corners += builder.getSmartNodes() if len(smart_corners): for node in smart_corners: wNode = eNode(node) if wNode.getSmartAngleRadius() <= float( active_preset[layer]): serach_result.add(work_glyph.name) #print 'FOUND:\t Glyph: %s; Layer: %s; Radius: %s' %(work_glyph.name, layer, active_preset[layer]) print '/' + ' /'.join(list(serach_result)) # - Finish -------------------------------------------- print 'DONE.'