コード例 #1
0
    def currentGlyphChanged(self, notification):
        glyph = notification['glyph']
        if glyph is None: return
        changed = False
        if glyph.name != self.currentGlyph.name:
            changed = True
            self.closeimportDCFromCG()
        self.currentGlyph = self.currentFont[glyph.name]
        if changed:
            # self.currentGlyph.sourcesList = []
            # for axis, variation in zip(self.currentGlyph._axes, self.currentGlyph._glyphVariations):
            #     self.currentGlyph.sourcesList.append({"Axis":axis["name"], "Layer":variation["layerName"], "PreviewValue":{axis["name"]:0}, "MinValue":axis["minValue"], "MaxValue":axis["maxValue"]})
            # self.currentGlyph.sourcesList = self.sortDeepComponentAxesList(self.currentGlyph.sourcesList)
            # self.currentViewSourceList.glyphVariationAxesList.set(self.currentGlyph.sourcesList)
            self.glyphInspectorWindow.sourcesItem.setList()
            self.glyphInspectorWindow.axesItem.setList()
            self.currentViewSourceValue.set("")
        if self.currentGlyph.type == 'atomicElement':
            uninstallTool(self.transformationTool)
        else:
            installTool(self.transformationTool)

        if self.currentGlyph.type != "atomicElement":
            self.addSubView()
        self.openGlyphInspector()
        self.updateDeepComponent()

        self.glyphInspectorWindow.updatePreview()
コード例 #2
0
 def installCustomTool(self, install=True, sender=None):
     if install:
         if self.currentGlyph.type == 'atomicElement':
             uninstallTool(self.transformationTool)
         else:
             installTool(self.transformationTool)
     else:
         uninstallTool(self.transformationTool)
コード例 #3
0
    def _updateTools(self):
        for toolName in self.toolDescription:
            active = self.toolDescription[toolName]

            for toolObj in self.tools:
                if toolObj.__class__.__name__ == toolName:
                    if active:
                        installTool(toolObj)
                    else:
                        if len(getToolOrder()) > 1:
                            uninstallTool(toolObj)
コード例 #4
0
    def listChangedCallback(self, sender):
        items = sender.get()
        selection = sender.getSelection()
        for index,item in enumerate(items):
            toolname = item['tool']
            oldValue = self.toolDescription[toolname]

            newValue = False
            if item['active'] == 1: newValue = True

            if newValue != oldValue:
                self.toolDescription[toolname] = newValue

                currTool = None
                for toolObj in self.tools:
                    if toolObj.__class__.__name__ == toolname:

                        if newValue:
                            installTool(toolObj)
                        else:
                            if len(getToolOrder()) > 1:
                                uninstallTool(toolObj)
                        break
                if not newValue:
                    if index in selection:
                        # if the selected tool is going to be disabled,
                        # the following code will switch to
                        # the first enabled tool
                        listOfValues = [self.toolDescription[name] for name in self.toolNames]
                        newSelection = []
                        for i, value in enumerate(listOfValues):
                            if value:
                                newSelection += [i]
                        print(newSelection)
                        if len(newSelection) > 1:
                            sender.setSelection([newSelection[0]])
                        else:
                            sender.setSelection(newSelection)
コード例 #5
0
ファイル: __init__.py プロジェクト: cjdunn/robo-cjk
    def __init__(self):
        self.windowWidth, self.windowHeight = 1000,600
        self.w = Window((self.windowWidth, self.windowHeight), "Robo CJK", minSize = (300,300), maxSize = (2500,2000))

        self.font = CurrentFont()
        self.glyph = CurrentGlyph()
        self.glyphset = list()

        self.font2Storage = dict()
        self.layerList = list()
        self.glyphsSetDict = dict()

        self.newDeepComponent_active = False
        self.temp_DeepCompo_slidersValuesList = []
        self.temp_DeepComponents = {}

        self.activeMaster = True
        self.deepCompoWillDrag = False

        self.currentGlyph_DeepComponents = {
                                            'CurrentDeepComponents':{}, 
                                            'Existing':{}, 
                                            'NewDeepComponents':{},
                                            }
        self.deepCompo_DeltaX, self.deepCompo_DeltaY = 0, 0


        self.current_DeepComponent_selection = None 

        self.selectedCompositionGlyphName = ""
        self.selectedVariantName = ""

        toolbarItems = [
            {   
                'itemIdentifier': "saveUFO(s)",
                'label': 'Save UFO(s)',
                'callback': self._saveUFOs_callback,
                'imagePath': SavePDF
            },
            {
                'itemIdentifier': "testInstall",
                'label': 'Test Install',
                'callback': self._testInstall_callback,
                'imagePath': TestInstallPDF
            },
            {
                'itemIdentifier': NSToolbarFlexibleSpaceItemIdentifier,
            },
            {
                'itemIdentifier': "textCenter",
                'label': 'Text Center',
                'callback': self._textCenter_callback,
                'imagePath': TextCenterPDF
            },
            {
                'itemIdentifier': "mastersOverview",
                'label': 'Masters Overview',
                'callback': self._textCenter_callback,
                'imagePath': MastersOverviewPDF
            },
            {
                'itemIdentifier': NSToolbarFlexibleSpaceItemIdentifier,
            },
            {
                'itemIdentifier': "projectEditor",
                'label': 'Projects Editor',
                'callback': self._projectsSettings_callback,
                'imagePath': ProjectEditorPDF
            },
            {
                'itemIdentifier': "preference",
                'label': 'Preference',
                'callback': self._preference_callback,
                'imagePath': PreferencesPDF,
            },
        ]
        self.w.addToolbar("DesignSpaceToolbar", toolbarItems)

        self.project_popUpButton_list = ["Load a project..."]
        self.w.projects_popUpButton = PopUpButton((10,10,-10,20),
                self.project_popUpButton_list, 
                callback = self._projects_popUpButton_callback)

        segmentedElements = ["Active Master", "Deep Components Editor"]
        self.w.main_segmentedButton = SegmentedButton((10,40,-180,20), 
                [dict(title=e, width = (self.windowWidth-224)/len(segmentedElements)) for e in segmentedElements],
                callback = self._main_segmentedButton_callback,
                sizeStyle='regular')
        self.w.main_segmentedButton.set(0)

        self.getCompositionGlyph()

        self.w.activeMasterGroup = Group((10,70,-205,-20))
        self.w.deepComponentsEditorGroup = Group((10,70,-205,-20))
        self.w.deepComponentsEditorGroup.show(0)

        ####### GLYPHSET #######
        self.w.activeMasterGroup.glyphSet = GlyphSet((225,0,-0,-200), self)

        ####### GLYPHSET #######
        self.w.activeMasterGroup.glyphData = GlyphData((0,180,215,-0), self)

        self.w.activeMasterGroup.DeepComponentsInstantiator = DeepComponentsInstantiator((225,-190,-0,-0), self)

        # self.w.deepComponentsEditorGroup.fontsGroup = Fonts((0,0,215,170), self)

        self.w.deepComponentsEditorGroup.Layers = Layers((0,150,215,-0), self)

        self.w.deepComponentsEditorGroup.GlyphLayers = GlyphLayers((225,0,-0,-0), self)

        ####### MINIFONT GROUP #######
        # self.minifonts = MiniFonts((0,0,-0,-0), self)

        ####### REFERENCE VIEWER #######
        self.referenceViewer = ReferenceViewer((0,0,-0,-0), self)

        ###### DESIGN FRAMES ######
        self.designFrame = DesignFrame((0,0,-0,-0), self)

        ####### FONT GROUP #######
        self.w.fontsGroup = Fonts((10,70,215,170), self)

        ###### ACCORDION VIEW ######
        self.accordionViewDescriptions = [
                       dict(label="Reference Viewer", view=self.referenceViewer, size=55, collapsed=True, canResize=0),
                       dict(label="Design Frame", view=self.designFrame, size=173, collapsed=False, canResize=0),
                       ]

        self.w.accordionView = AccordionView((-200, 40, -0, -20), self.accordionViewDescriptions,
            backgroundColor=NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 1, 1, 1))
        
        ###### DARK MODE ######
        self.darkMode = 1
        Helpers.setDarkMode(self.w, self.darkMode)

        self.w.darkMode_checkBox = CheckBox((10,-20,-10,-0),
            "Dark Mode", 
            sizeStyle = "small",
            value = self.darkMode,
            callback = self._darkMode_checkBox_checkBox)

        ###### OFF TOOLS ######
        PowerRuler.Ruler(self)
        BalanceHandles.BalanceHandles(self)
        OpenSelectedComponent.OpenSelectedComponent(self)

        self.smartSelector = SmartSelector(self)
        installTool(self.smartSelector)

        ###### OBSERVER ######
        self.observer()
        self.w.bind('close', self.windowWillClose)
        self.w.bind('resize', self.windowDidResize)

        ###### LAUNCH WINDOW ######        
        self.w.open()
コード例 #6
0
        self.clearAll()
        g = CurrentGlyph()
        self.getRatio(g)
        
    def mouseDragged(self, point=None, delta=None):
        self.update()

    def mouseDown(self, point, event):
        self.update()

    def mouseUp(self, xx):
        self._rin = None
        self._rout = None
        self.update()
    
    def keyDown(self, event):
        self.update()

    def becomeInactive(self):
        self.clearAll()

    def clearAll(self):
        self.outgoingLayer.clearSublayers()
        self.incomingLayer.clearSublayers()
        self.captionTextLayer.clearSublayers()
            
p = RatioTool()
installTool(p)

print('installed', p)
コード例 #7
0
ファイル: boundingTool.py プロジェクト: typoman/fbOpenTools
        Draw guidelines for the current box.
        """
        g = self.getGlyph()
        selectedBox = self.getBox(selected=True)
        if selectedBox:
            divisionsX = int(self.w.divisionsRadioY.get())
            divisionsY = int(self.w.divisionsRadioX.get())
            pt1, pt2, pt3, pt4, dimensions = selectedBox
            pt1X, pt1Y = pt1  # bottom left
            pt2X, pt2Y = pt2  # top left
            pt3X, pt3Y = pt3  # top right
            pt4X, pt4Y = pt4  # bottom right
            width, height = dimensions
            italicAngle = 0
            if self.w.useItalic.get():
                italicAngle = g.getParent().info.italicAngle or 0
            g.prepareUndo()
            #if self.w.viewX.get():
            g.addGuide((pt1X, pt1Y), 90 + italicAngle)
            g.addGuide((pt3X, pt3Y), 90 + italicAngle)
            #if self.w.viewY.get():
            g.addGuide((pt1X, pt1Y), 0)
            g.addGuide((pt3X, pt3Y), 0)
            g.performUndo()

    def updateView(self, sender=None):
        UpdateCurrentGlyphView()


installTool(BoundingTool())
コード例 #8
0
            cachedW = self.cachedSelectionBounds[
                2] - self.cachedSelectionBounds[0]
            cachedH = self.cachedSelectionBounds[
                3] - self.cachedSelectionBounds[1]
            w = self.selectionBounds[2] - self.selectionBounds[0]
            h = self.selectionBounds[3] - self.selectionBounds[1]
            offsetX = self.selectionBounds[0] - self.cachedSelectionBounds[0]
            offsetY = self.selectionBounds[1] - self.cachedSelectionBounds[1]
            if cachedW == 0:
                scaleW = 0
            else:
                scaleW = w / cachedW
            if cachedH == 0:
                scaleH = 0
            else:
                scaleH = h / cachedH
            return (offsetX, offsetY), (scaleW, scaleH)
        else:
            return None

    def pointInBounds(self, point, bounds):
        if bounds:
            return bounds[0] < point[0] < bounds[2] and bounds[1] < point[
                1] < bounds[3]
        else:
            return False


if RF3:
    installTool(SlightlyBetterTransformTool())
コード例 #9
0
    def _applyTolerance(self, info):
        """
        Pass to delegate object's method:
        Redefine tolerance whenever com.ToleranceSettingChanged is triggered
        """
        self.delegate.readToleranceSetting()

    def _selectSegmentWhenBCPConnectionIsClicked(self):
        """
        Keep segment selected when click point is w/in
        line connecting bcps

        If multiple segments are selected, only one
        segment will remain selected
        """
        for selected in self.delegate._selectedSegments:
            p1, segment = selected
            h1, h2, p2 = segment
            if hf.isPointInLine(self.mouseDownPoint, (h1, h2), self.delegate.scale):
                self.canMarquee = False
                self.lineWeightMultiplier = 4
                segment.selected = True


if __name__ == "__main__":
    dwgDelegate = DrawingDelegate()
    parallelGuides = ParallelGuides(dwgDelegate)
    parallelTool = EditConnectionLineTool(dwgDelegate)

    installTool(parallelTool)
コード例 #10
0
        if 'Radial Guide' not in ancs:
            g.appendAnchor("Radial Guide", (500, 500))

        for a in g.guides:
            if a.name in gd:
                g.removeGuide(a)

        for a in g.anchors:
            if a.name == 'Radial Guide':
                x = a.x
                y = a.y
                for angle in range(0, 180, 15):
                    g.addGuide((x, y), angle, name=("Radial {0}deg".format(angle)))
                    guide = g.addGuide((x, y), angle, name=("Radial {0}deg".format(angle)))
                    guide.naked().showMeasurements = True

        CurrentFont().update() 


    def getToolbarIcon(self):
        ## return the toolbar icon
        return toolbarIcon

    def getToolbarTip(self):
        ## return the toolbar tool tip
        return "Radial Guides Tool"

## install the tool!!
installTool(RadialGuideTool())

コード例 #11
0
            str(int(self.position.x)) + ", " + str(int(self.position.y)),
            (x + 20, y + 20))
        stroke(1, 0, 0)
        rect(self.here.x - size * 1, self.here.y - size * 1, size * 2,
             size * 2)

        if self.hereOld != None:
            xx = self.positionOld.x - size
            yy = self.positionOld.y - size
            fill(0, 255, 255, 1.0)
            fontSize(30)
            text(
                str(int(self.positionOld.x)) + ", " +
                str(int(self.positionOld.y)), (xx + 20, yy + 20))
            stroke(1, 0, 0)

            rect(self.hereOld.x - size * 1, self.hereOld.y - size * 1,
                 size * 2, size * 2)

    def getToolbarTip(self):
        pass

    def viewDidChangeGlyph(self):
        pass

    def preferencesChanged(self):
        pass


installTool(AttributeTool())
コード例 #12
0
                # scale curve
                newDistX = diff(p1.x, p2.x, self.settings['simplified'])
                newDistY = diff(p1.y, p2.y, self.settings['simplified'])
                p1UtX, p1UtY = newDistX * p1xr + p1.x, newDistY * p1yr + p1.y
                p2InX, p2InY = newDistX * p2xr + p2.x, newDistY * p2yr + p2.y
                p1Ut.x, p1Ut.y, p2In.x, p2In.y = p1UtX, p1UtY, p2InX, p2InY

                # correct offCurve angles
                if not self.settings['simplified']:
                    if prevType == 'line' and p1.smooth: # smooth line before
                        p1Ut.x, p1Ut.y = smoothLines(p1, p0, p1Ut)
                    elif p1yx: # diagonal p1Ut
                        p1Ut.x, p1Ut.y = keepAngles(p1, p1Ut, p1yx, p1xy, p1dx, p1dy)
                        if not arrowKeyDown and self.commandDown: # keep angle override
                            if self.settings['smoothsToo'] or not self.settings['smoothsToo'] and not p1.smooth:
                                if self.settings['selectOnly'] and p1.selected or not self.settings['selectOnly']:
                                    p1Ut.x, p1Ut.y = p1UtX, p1UtY

                    if nextType == 'line' and p2.smooth:  # smooth line after
                        p2In.x, p2In.y = smoothLines(p2, p3, p2In)
                    elif p2yx: # diagonal p2In
                        p2In.x, p2In.y = keepAngles(p2, p2In, p2yx, p2xy, p2dx, p2dy)
                        if not arrowKeyDown and self.commandDown: # keep angle override
                            if self.settings['smoothsToo'] or not self.settings['smoothsToo'] and not p2.smooth:
                                if self.settings['selectOnly'] and p2.selected or not self.settings['selectOnly']:
                                    p2In.x, p2In.y = p2InX, p2InY


installTool(ScalingEditTool())
コード例 #13
0
            pen.addPoint(_roundPoint(x + w, y + hh), segmentType)
            pen.addPoint(_roundPoint(x + w, y + hh + hh*r))
            pen.addPoint(_roundPoint(x + hw + hw*r, y + h))

            pen.addPoint(_roundPoint(x + hw, y + h), segmentType)
            pen.addPoint(_roundPoint(x + hw - hw*r, y + h))
            pen.addPoint(_roundPoint(x, y + hh + hh*r))

            pen.addPoint(_roundPoint(x, y + hh), segmentType)
            pen.addPoint(_roundPoint(x, y + hh - hh*r))
            pen.addPoint(_roundPoint(x + hw - hw*r, y))

            pen.endPath()
        
        elif self.drawingMode == COMPONENT_MODE and self.componentName and self.componentName != glyph.name:
            pen.addComponent(self.componentName, [1, 0, 0, 1, x, y])
            
        
    def getDefaultCursor(self):
        return pixelCursor
    
    def getToolbarIcon(self):
        return pixelToolbarIcon
    
    def getToolbarTip(self):
        return "Pixel Tool"
    
        
installTool(PixelTool())
コード例 #14
0
        nsPathObject = self.getGlyph().getRepresentation("defconAppKit.NSBezierPath")
        for pos, val in self.kernel.items():
            thisPos = (
                samplePoint[0] + pos[0] * self.prefs["chunkSize"],
                samplePoint[1] + pos[1] * self.prefs["chunkSize"],
            )
            # a = math.atan2(pos[0], pos[1])
            if thisPos not in self._insides:
                self._insides[thisPos] = nsPathObject.containsPoint_(thisPos)
            if not self._insides[thisPos]:
                level += self.kernel.get(pos)
                self._hits[thisPos] = self.kernel.get(pos)
            else:
                self._misses[thisPos] = self.kernel.get(pos)
        self.pts.append((samplePoint, level, self.prefs["toolDiameter"]))
        self.samples[(samplePoint, self.prefs["toolDiameter"])] = dict(level=level)
        self.dupes.add((self.prefs["toolDiameter"], samplePoint))
        return level

    def getToolbarTip(self):
        return "LightMeter"

    def getToolbarIcon(self):
        ## return the toolbar icon
        return toolbarIcon


p = LightMeterTool()
installTool(p)
コード例 #15
0
        print "draw", self.isDragging()
        if self.isDragging():
            ## draw a red dot when dragging
            r = 50
            NSColor.redColor().set()
            x, y = self.currentPoint
            NSBezierPath.bezierPathWithOvalInRect_(((x-r, y-r), (r*2, r*2))).fill()

    def drawBackground(self, scale):
        print "drawBackground here"

    #def getDefaultCursor(self):
    #   this will be the cursor default is an arrow
    #   return aNSCursor
    #def getToolbarIcon(self):
    #   this is setting the icon in the toolbar default is an arrow
    #   return aNSImage

    def getToolbarTip(self):
        return "My Event Tool Bar Tip"

    #notifications

    def viewDidChangeGlyph(self):
        print "view changed glyph"

    def preferencesChanged(self):
        print "prefs changed"

installTool(MyEvent())
コード例 #16
0
                                path.curveToPoint_controlPoint1_controlPoint2_(((nextPoint.x + nextPairPoint.x) / 2, (nextPoint.y + nextPairPoint.y) / 2), 
                                    (((currentPoint.x + nextPoint.x) / 2 + ccp[currentPairIndex - 1].x) / 2, ((currentPoint.y + nextPoint.y) / 2 + ccp[currentPairIndex - 1].y) / 2), 
                                    (((currentPoint.x + nextPoint.x) / 2 + ccp[currentPairIndex - 2].x) / 2, ((currentPoint.y + nextPoint.y) / 2 + ccp[currentPairIndex - 2].y) / 2))
                                path.stroke()
                        else:
                            if pairCurve == False:
                                ccp = currentContour.points
                                path = NSBezierPath.bezierPath()
                                currentColor = NSColor.redColor()
                                currentColor.set()
                                path.moveToPoint_(((currentPoint.x + currentPairPoint.x) / 2, (currentPoint.y + currentPairPoint.y) / 2))
                                path.curveToPoint_controlPoint1_controlPoint2_(((nextPoint.x + nextPairPoint.x) / 2, (nextPoint.y + nextPairPoint.y) / 2), 
                                    (((currentPairPoint.x + nextPairPoint.x) / 2 + ccp[currentIndex + 1].x) / 2, ((currentPairPoint.y + nextPairPoint.y) / 2 + ccp[currentIndex + 1].y) / 2), 
                                    (((currentPairPoint.x + nextPairPoint.x) / 2 + ccp[currentIndex + 2].x) / 2, ((currentPairPoint.y + nextPairPoint.y) / 2 + ccp[currentIndex + 2].y) / 2))
                                path.stroke()
                            else:
                                ccp = currentContour.points
                                path = NSBezierPath.bezierPath()
                                currentColor = NSColor.redColor()
                                currentColor.set()
                                path.moveToPoint_(((currentPoint.x + currentPairPoint.x) / 2, (currentPoint.y + currentPairPoint.y) / 2))
                                path.curveToPoint_controlPoint1_controlPoint2_(((nextPoint.x + nextPairPoint.x) / 2, (nextPoint.y + nextPairPoint.y) / 2), 
                                    ((ccp[currentIndex + 1].x + ccp[currentPairIndex - 1].x) / 2, (ccp[currentIndex + 1].y + ccp[currentPairIndex - 1].y) / 2), 
                                    ((ccp[currentIndex + 2].x + ccp[currentPairIndex - 2].x) / 2, (ccp[currentIndex + 2].y + ccp[currentPairIndex - 2].y) / 2))
                                path.stroke()
                        drawed = drawed + 1
            except AttributeError:
                continue
        
installTool(CenterLine())
コード例 #17
0
    def mouseUp(self, point):
        self.pEnd = point
        self._getSelectedPoints()
        #print(self.errorSelection)
        self.pStart = None
        self.pEnd = None
        self._selectedMouseDownPoint = None

    def mouseDragged(self, point, delta):
        self.pEnd = point
        #self._getSelectedPoints()

    def draw(self, scale):
        if self.isDragging() and self.pStart and self.pEnd:
            r = self.getMarqueRect()
            if r:
                color = getDefaultColor('glyphViewSelectionMarqueColor')
                color.set()
                path = NSBezierPath.bezierPathWithRect_(r)
                path.fill()
            return
        self.drawSelection(scale)

    def drawSelection(self, scale):
        self.errorSelection.draw(scale)


installTool(RedArrowFixerTool())
print("Red Arrow Fixer installed in tool bar.")
コード例 #18
0
        
        glyph = self.getGlyph()
        path = self.pen.path
        for contour in glyph:
            for point in contour.points:
                result = path.containsPoint_((point.x, point.y))
                if self.controlDown:
                    point.selected = not result
                else:
                    point.selected = result
        
        self._oldPen = self.pen
        self.pen = None
        
    def draw(self, scale):
        if self.pen is None:
            return
        fill(0, .1)
        stroke(0, .6)
        strokeWidth(scale)
        drawPath(self.pen.path)
    
    def canSelectWithMarque(self):
        return False
    
    def getToolbarTip(self):
        return "Polygon Selection Tool"
        
    
installTool(PolygonSelectionTool())
コード例 #19
0
        def becomeInactive(self):
            self.speedpunklib.Close()

        def drawBackground(self, scale):
            try:

                if self.getGlyph() != None:
                    self.speedpunklib.UpdateGlyph(self.getGlyph())

            except:
                NSLog('Speed Punk:\n%s' % traceback.format_exc())

        def glyphWindowWillClose(self, a):
            self.speedpunklib.Close()

        def glyphWindowDidOpen(self, a):
            self.speedpunklib.Open()

        def getToolbarTip(self):
            return "Speed Punk"

        def getToolbarIcon(self):
            NSImage = bundle.getResourceImage("toolbar")
            if NSImage:
                return NSImage

    installTool(SpeedPunkTool())

except:
    NSLog('Speed Punk:\n%s' % traceback.format_exc())
コード例 #20
0
        """
        g = self.getGlyph()
        selectedBox = self.getBox(selected=True)
        if selectedBox:
            divisionsX = int(self.w.divisionsRadioY.get())
            divisionsY = int(self.w.divisionsRadioX.get())
            pt1, pt2, pt3, pt4, dimensions = selectedBox
            pt1X, pt1Y = pt1 # bottom left
            pt2X, pt2Y = pt2 # top left
            pt3X, pt3Y = pt3 # top right
            pt4X, pt4Y = pt4 # bottom right
            width, height = dimensions
            italicAngle = 0
            if self.w.useItalic.get():
                italicAngle = g.getParent().info.italicAngle or 0
            g.prepareUndo()
            #if self.w.viewX.get():
            g.addGuide((pt1X, pt1Y), 90+italicAngle)
            g.addGuide((pt3X, pt3Y), 90+italicAngle)
            #if self.w.viewY.get():
            g.addGuide((pt1X, pt1Y), 0)
            g.addGuide((pt3X, pt3Y), 0)
            g.performUndo()

    def updateView(self, sender=None):
        UpdateCurrentGlyphView()
        

    
installTool(BoundingTool())
コード例 #21
0
            penMethod(_roundPoint(x + w, y + hh + hh*r), 
                        _roundPoint(x + hw + hw*r, y + h), 
                        _roundPoint(x + hw, y + h))

            penMethod(_roundPoint(x + hw - hw*r, y + h), 
                        _roundPoint(x, y + hh + hh*r), 
                        _roundPoint(x, y + hh))

            penMethod(_roundPoint(x, y + hh - hh*r), 
                        _roundPoint(x + hw - hw*r, y), 
                        _roundPoint(x + hw, y))
            

            pen.closePath()
        
        elif self.drawingMode == COMPONENT_MODE and self.componentName and self.componentName != glyph.name:
            pen.addComponent(self.componentName, [1, 0, 0, 1, x, y])
            
        
    def getDefaultCursor(self):
        return pixelCursor
    
    def getToolbarIcon(self):
        return pixelCursor.image()
    
    def getToolbarTip(self):
        return "Pixel Tool"
    
        
installTool(PixelTool())
コード例 #22
0
                if bezierTools.distanceFromPointToPoint(anchor, point) < s:
                    self.selection.addAnchor(anchor, self.shiftDown)
                    self._selectedMouseDownPoint = (anchor.x, anchor.y)
                    return

    def mouseUp(self, point):
        self.pEnd = point
        self._getSelectedPoints()
        self.pStart = None
        self.pEnd = None
        self._selectedMouseDownPoint = None

    def mouseDragged(self, point, delta):
        self.pEnd = point
        #self._getSelectedPoints()

    def draw(self, scale):
        if self.isDragging() and self.pStart and self.pEnd:
            r = self.getMarqueRect()
            if r:
                color = getDefaultColor('glyphViewSelectionMarqueColor')
                color.set()
                path = NSBezierPath.bezierPathWithRect_(r)
                path.fill()
            return
        self.drawSelection(scale)


installTool(AnchorTool())
#print("Anchor Tool installed in tool bar.")
コード例 #23
0
        self.convertToLine(g)

    def convertToLine(self, glyph):
        if glyph and glyph.selection != []:
            glyph.prepareUndo()
            for c_index in range(len(glyph.contours)):
                c = glyph.contours[c_index]
                for s_index in range(len(c.segments)):
                    s = c.segments[s_index]
                    if s.selected and s.type == "curve":
                        s.type = "line"
                        s.points[0].smooth = False
                        s.smooth = False
                        c.segments[s_index - 1].points[-1].smooth = False

            glyph.deselect()
            UpdateCurrentGlyphView()
            glyph.changed()

    def getToolbarTip(self):
        return "Eraser Tool"

    def getToolbarIcon(self):
        return toolbarIcon

    def getDefaultCursor(self):
        return eraserCursor


installTool(EraserTool())
コード例 #24
0
        self.updateRoundablePoints()

    # def keyUp(self, event):
    #     print "keyUp"

    # def modifiersChanged(self):
    #     pass

    # def drawBackground(self, scale):
    #     print "drawBackground here"

    #def getDefaultCursor(self):
    #   this will be the cursor default is an arrow
    #   return aNSCursor

    def getToolbarIcon(self):
        return toolbarIcon

    def getToolbarTip(self):
        return "Rounding Tool"

    #notifications

    def viewDidChangeGlyph(self):
        self.init()

    # def preferencesChanged(self):
    #     print "prefs changed"

installTool(RoundingTool())
コード例 #25
0
        #tangent 1, horizontal
        self._t1_h = self._xMin + .5 * self._width - self.flatFactor_x * .5 * self._width
        #tangent 2, horizontal
        self._t2_h = self._xMin + .5 * self._width + self.flatFactor_x * .5 * self._width
        #tangent 1, vertical
        self._t1_v = self._yMin + .5 * self._height - self.flatFactor_y * .5 * self._height
        #tangent 2, vertical
        self._t2_v = self._yMin + .5 * self._height + self.flatFactor_y * .5 * self._height
        #tangent 1, horizontal
        self._t1_h = self._xMin + .5 * self._width - self.flatFactor_x * .5 * self._width
        #tangent 2, horizontal
        self._t2_h = self._xMin + .5 * self._width + self.flatFactor_x * .5 * self._width

        # bcps
        self._b1_v = self._yMin + self.bcpFactor_y * (self._t1_v - self._yMin)
        self._b2_v = self._t2_v + (1 - self.bcpFactor_y) * (self._yMax -
                                                            self._t2_v)
        self._b1_h = self._xMin + self.bcpFactor_x * (self._t1_h - self._xMin)
        self._b2_h = self._t2_h + (1 - self.bcpFactor_x) * (self._xMax -
                                                            self._t2_h)

    def canSelectWithMarque(self):
        return False

    def getToolbarTip(self):
        return "Symmetrical Round Shape Drawing Tool"


installTool(SymmetricalRoundShapeDrawingTool())
コード例 #26
0
        for contour in glyph:
            for point in contour.points:
                result = path.containsPoint_((point.x, point.y))
                if self.controlDown:
                    point.selected = not result
                else:
                    point.selected = result

        self._oldPen = self.pen
        self.pen = None

    def draw(self, scale):
        if self.pen is None:
            return
        fill(0, .1)
        stroke(0, .6)
        strokeWidth(scale)
        drawPath(self.pen.path)

    def canSelectWithMarque(self):
        return False

    def getToolbarTip(self):
        return "Lasso"

    def getToolbarIcon(self):
        return toolbarIcon


installTool(PolygonSelectionTool())
コード例 #27
0
        # apply default _mouseDragged behavior first
        shiftdown = self.shiftDown
        self.shiftDown = False
        super()._mouseDragged(point, delta)
        self.shiftDown = shiftdown

        # handle single off-curve point selection
        if self.shiftDown and self.selection.containsSingleOffCurve():

            # get selected off-curve point
            offcurve = self.selection.selectedPoints[0]

            # get related on-curve point
            info = self.selection.selectionDataForPoint(offcurve)
            anchor = info["anchor"]

            # calculate delta for off-curve point
            offcurveDelta = Point(
                (offcurve.x - anchor.x, offcurve.y - anchor.y))

            # constrain delta to angle
            self.modifyDeltaForAngle(offcurveDelta, self.angle)

            # update position of off-curve point
            offcurve.x = anchor.x + offcurveDelta.x
            offcurve.y = anchor.y + offcurveDelta.y


installTool(ConstrainAngleEditingTool())
コード例 #28
0
                                                            new_x_baseGlyph_anchor = selectedComponent_anchor.x + selected_component.offset[
                                                                0] - x_offset
                                                            new_y_baseGlyph_anchor = selectedComponent_anchor.y + selected_component.offset[
                                                                1] - y_offset

                                                            self.drawInfos(
                                                                new_x_baseGlyph_anchor,
                                                                new_y_baseGlyph_anchor,
                                                                viewScale,
                                                                glyphView,
                                                                baseGlyph_anchor
                                                            )

                                                            ### Update baseGlyph anchor
                                                            baseGlyph_anchor.x = new_x_baseGlyph_anchor
                                                            baseGlyph_anchor.y = new_y_baseGlyph_anchor

                                                            if self.SettingsWindow.w.updateComposites.get(
                                                            ) == 1:
                                                                self.updateRelatedComposites(
                                                                    glyph_constructor,
                                                                    cg, cf,
                                                                    new_base_glyph,
                                                                    baseGlyph_anchor,
                                                                    composed_glyph
                                                                )


installTool(ComponentTool())
コード例 #29
0
        for segment in self.selectedSegments:
            selectedOnCurves = []
            selectedOffCurves = []
            for point in segment.points:
                if point.type == "offcurve":
                    selectedOffCurves.append(point)
                else:
                    selectedOnCurves.append(point)

            pt0 = self._findPrevOnCurvePt(selectedOnCurves[0],
                                          contourPoints).position
            pt1 = selectedOnCurves[0].position
            pt2 = selectedOffCurves[0].position
            pt3 = selectedOffCurves[1].position

            # if lines are parallel, lines are green; otherwise, red
            if self._checkParallel((pt0, pt1), (pt2, pt3)):
                dt.stroke(0, 1, 0, 1)
            else:
                dt.stroke(1, 0, 0, 1)

            dt.strokeWidth(lineThickness)
            dt.line(pt0, pt1)
            dt.line(pt2, pt3)

    def getToolbarTip(self):
        return "Check Parallel Tool"


installTool(CheckParallel())
コード例 #30
0
                path = NSBezierPath.bezierPathWithRect_(rect)
                
            elif self.shape == "oval":
                ## create a oval path
                path = NSBezierPath.bezierPathWithOvalInRect_(rect)
            ## set the line width
            path.setLineWidth_(scale)
            ## draw without anit-alias
            strokePixelPath(path)


    def getDefaultCursor(self):
        ## returns the cursor
        if self.shape == "rect":
            return _cursorRect
        else:
            return _cursorOval
            
    def getToolbarIcon(self):
        ## return the toolbar icon
        return toolbarIcon

    def getToolbarTip(self):
        ## return the toolbar tool tip
        return "Shape Tool"

## install the tool!!
installTool(DrawGeometricShapesTool())


コード例 #31
0
class MyTool(BaseEventTool):
    
    def setup(self):
        self.position = None
    
    def mouseDown(self, point, clickCount):
        self.position = point
    
    def mouseDragged(self, point, delta):
        self.position = point
    
    def mouseUp(self, point):
        self.position = None
    
    def draw(self, scale):
        if self.position is not None:
            size = 10
            x = self.position.x - size
            y = self.position.y - size
            fill(None)
            stroke(1, 0, 0)
            oval(x, y, size*2, size*2)
    
    def getToolbarTip(self):
        return "My Tool Tip"
    
    

installTool(MyTool())
コード例 #32
0
                centerY = y + h * .5

                path.moveToPoint_((centerX, centerY - crossHairLength))
                path.lineToPoint_((centerX, centerY + crossHairLength))
                path.moveToPoint_((centerX - crossHairLength, centerY))
                path.lineToPoint_((centerX + crossHairLength, centerY))

            # set the line width
            path.setLineWidth_(scale)
            # draw without anti-alias
            strokePixelPath(path)

    def getDefaultCursor(self):
        # returns the cursor
        if self.shape == "rect":
            return _cursorRect
        else:
            return _cursorOval

    def getToolbarIcon(self):
        # return the toolbar icon
        return toolbarIcon

    def getToolbarTip(self):
        # return the toolbar tool tip
        return "Shape Tool"


# install the tool!!
installTool(DrawGeometricShapesTool())
コード例 #33
0
            UpdateCurrentGlyphView()

    def drawInactive(self,info):
        self.drawPoints(info)
        
class SurgeonTool(EditingTool):
    
    def becomeActive(self):
        self.SurgeonToolUI = BezierSurgeon()
    
    def becomeInactive(self):
        self.SurgeonToolUI.closeWindow(None)
        self.SurgeonToolUI.w.close()

    def glyphWindowDidOpen(self, info):
        self.SurgeonToolUI.w.show()

    def glyphWindowWillClose(self,info):
        # print("becomeInactive_noWindow")
        self.SurgeonToolUI.closeWindow(None)
        self.SurgeonToolUI.w.hide()

    def getToolbarTip(self):
        return "Bezier Surgeon"

    def getToolbarIcon(self):
        return toolbarIcon
        
installTool(SurgeonTool())
コード例 #34
0
            # scale bcps:
            newDistX = diff(p1.anchor[0], p2.anchor[0])
            newDistY = diff(p1.anchor[1], p2.anchor[1])
            p1.bcpOut = newDistX * p1xr, newDistY * p1yr
            p2.bcpIn = newDistX * p2xr, newDistY * p2yr

            # correct bcp angles:
            if prevType == 'line' and p1smooth:  # smooth line before
                bcpLen = sqrt(p1.bcpOut[0]**2 + p1.bcpOut[1]**2)
                p1.bcpOut = smoothLines(p1, p0, bcpLen)
            elif p1yx:  # angled p1.bcpOuts
                if not self.commandDown or self.isArrowKeyDown:
                    bcpLen = sqrt(p1.bcpOut[0]**2 + p1.bcpOut[1]**2)
                    newX = bcpLen / sqrt(p1yx**2 + 1)
                    newY = bcpLen / sqrt(p1xy**2 + 1)
                    p1.bcpOut = newX * p1dx, newY * p1dy

            if nextType == 'line' and p2smooth:  # smooth line after
                bcpLen = sqrt(p2.bcpIn[0]**2 + p2.bcpIn[1]**2)
                p2.bcpIn = smoothLines(p2, p3, bcpLen)
            elif p2yx:  # angled p2.bcpIns
                if not self.commandDown or self.isArrowKeyDown:
                    bcpLen = sqrt(p2.bcpIn[0]**2 + p2.bcpIn[1]**2)
                    newX = bcpLen / sqrt(p2yx**2 + 1)
                    newY = bcpLen / sqrt(p2xy**2 + 1)
                    p2.bcpIn = newX * p2dx, newY * p2dy


installTool(ScalingEditTool())
コード例 #35
0
                    self._selectedMouseDownPoint = p
                    break
    
    def mouseUp(self, point):
        self.pEnd = point
        self._getSelectedPoints()
        #print self.errorSelection
        self.pStart = None
        self.pEnd = None
        self._selectedMouseDownPoint = None
    
    def mouseDragged(self, point, delta):
        self.pEnd = point
        #self._getSelectedPoints()
    
    def draw(self, scale):
        if self.isDragging() and self.pStart and self.pEnd:
            r = self.getMarqueRect()
            if r:
                color = getDefaultColor('glyphViewSelectionMarqueColor')
                color.set()
                path = NSBezierPath.bezierPathWithRect_(r)
                path.fill()
            return
        self.drawSelection(scale)
    
    def drawSelection(self, scale):
        self.errorSelection.draw(scale)
        
installTool(RedArrowFixerTool())
print "Red Arrow Fixer installed in tool bar."