def layerActions(self): glyph = self.view.glyph() newLayer, action, ok = LayerActionsDialog.getLayerAndAction( self, glyph) if ok and newLayer is not None: # TODO: whole glyph for now, but consider selection too if not glyph.name in newLayer: newLayer.newGlyph(glyph.name) otherGlyph = newLayer[glyph.name] otherGlyph.disableNotifications() if action == "Swap": tempGlyph = TGlyph() otherGlyph.drawPoints(tempGlyph.getPointPen()) tempGlyph.width = otherGlyph.width otherGlyph.clearContours() glyph.drawPoints(otherGlyph.getPointPen()) otherGlyph.width = glyph.width if action != "Copy": glyph.disableNotifications() glyph.clearContours() if action == "Swap": tempGlyph.drawPoints(glyph.getPointPen()) glyph.width = tempGlyph.width glyph.enableNotifications() otherGlyph.enableNotifications()
def FilterSelectionFactory(glyph): copyGlyph = TGlyph() pen = copyGlyph.getPointPen() for anchor in glyph.anchors: if anchor.selected: anchorDict = dict( x=anchor.x, y=anchor.y, name=anchor.name, color=anchor.color, identifier=anchor.identifier ) copyGlyph.appendAnchor(anchorDict) for contour in glyph: onCurvesSelected = True for point in contour: if point.segmentType and not point.selected: onCurvesSelected = False break if onCurvesSelected: contour.drawPoints(pen) else: # TODO: somehow make this into a pen? # I'm wary of doing it because it warrants reordering and so on segments = contour.segments # put start point at the beginning of a subcontour lastSubcontour = None for index, segment in reversed(list(enumerate(segments))): if segment[-1].selected: lastSubcontour = index else: if lastSubcontour is not None: break if lastSubcontour is None: continue segments = segments[lastSubcontour:] + segments[:lastSubcontour] # now draw filtered shouldMoveTo = True for index, segment in enumerate(segments): on = segment[-1] if not on.selected: if not shouldMoveTo: pen.endPath() shouldMoveTo = True continue if on.segmentType == "move" and not shouldMoveTo: pen.endPath() shouldMoveTo = True if shouldMoveTo: pen.beginPath() pen.addPoint((on.x, on.y), segmentType="move", smooth=on.smooth, name=on.name) shouldMoveTo = False continue for point in segment: pen.addPoint( (point.x, point.y), segmentType=point.segmentType, smooth=point.smooth, name=point.name ) if not shouldMoveTo: pen.endPath() for component in glyph.components: if component.selected: component.drawPoints(pen) return copyGlyph
def FilterSelectionFactory(glyph): # TODO: somehow make this all a pen? # I'm wary of doing it because it warrants reordering and so on copyGlyph = TGlyph() pen = copyGlyph.getPointPen() for anchor in glyph.anchors: if anchor.selected: anchorDict = dict( x=anchor.x, y=anchor.y, name=anchor.name, color=anchor.color, identifier=anchor.identifier, ) copyGlyph.appendAnchor(anchorDict) for contour in glyph: onCurvesSelected = True for point in contour: if point.segmentType and not point.selected: onCurvesSelected = False break if onCurvesSelected: contour.drawPoints(pen) else: lastSubcontour = None segments = contour.segments # put start point at the beginning of a subcontour for index, segment in reversed(list(enumerate(segments))): if segment[-1].selected: lastSubcontour = index else: if lastSubcontour is not None: break if lastSubcontour is None: continue segments = segments[lastSubcontour:] + segments[:lastSubcontour] # now draw filtered pen.beginPath() shouldMoveTo = False for index, segment in enumerate(segments): on = segment[-1] if not on.selected: if not shouldMoveTo: pen.endPath() shouldMoveTo = True continue if shouldMoveTo or not index: if shouldMoveTo: pen.beginPath() shouldMoveTo = False pen.addPoint((on.x, on.y), segmentType="move", smooth=on.smooth, name=on.name) continue for point in segment: pen.addPoint((point.x, point.y), segmentType=point.segmentType, smooth=point.smooth, name=point.name) if not shouldMoveTo: pen.endPath() for component in glyph.components: if component.selected: component.drawPoints(pen) return copyGlyph