コード例 #1
0
    def a_magnet(self):
        ctx.newPath()
        ctx.fill(0, 0, 0, .75)
        ctx.moveTo((25, 15))
        ctx.curveTo((20.0, 15.0), (17, 16), (17, 20))
        ctx.lineTo((17, 45))
        ctx.curveTo((17.0, 48.0), (15, 50), (9, 50))
        ctx.curveTo((2, 50), (0, 48.0), (0, 45))
        ctx.lineTo((0, 22))
        ctx.curveTo((0, 6), (9, 0), (25, 0))
        ctx.curveTo((41.0, 0.0), (50, 6), (50, 22))
        ctx.lineTo((50, 45))
        ctx.curveTo((50, 48), (48, 50), (41, 50))
        ctx.curveTo((35, 50), (33, 48), (33, 45))
        ctx.lineTo((33, 20))
        ctx.curveTo((33, 16), (30, 15), (25, 15))
        ctx.closePath()
        ctx.drawPath()

        ctx.newPath()
        ctx.fill(1)
        ctx.moveTo((25, 3))
        ctx.curveTo((11.0, 3), (3, 8), (3, 22))
        ctx.lineTo((3, 34))
        ctx.lineTo((14, 34))
        ctx.lineTo((14, 20))
        ctx.curveTo((14.0, 14.0), (18, 12), (25, 12))
        ctx.curveTo((32.0, 12.0), (36.0, 14.0), (36, 20))
        ctx.lineTo((36, 34))
        ctx.lineTo((47, 34))
        ctx.lineTo((47, 22))
        ctx.curveTo((47, 8), (39, 3), (25, 3))
        ctx.closePath()
        ctx.drawPath()
コード例 #2
0
 def drawPreview(self, scale):
     # only draws if there are already outlines in the glyph
     if self._xMin is None: return
     ctx.save()
     ctx.stroke(1, .4, 0)
     ctx.strokeWidth(2 * scale)
     ctx.lineDash(10 * scale, 20 * scale)
     ctx.fill(0)
     self.buildShapePath(scale)
     ctx.drawPath()
     ctx.restore()
 def drawPreview(self, info):
     # Draw a filled in version of the interpolated glyph
     scale = info["scale"]
     if self.interpolatedGlyph:
         pen = CocoaPen(None)
         self.interpolatedGlyph.draw(pen)
         dt.fill(r=0, g=0, b=0, a=0.6)
         dt.stroke(r=None, g=None, b=None, a=1)
         dt.save()
         dt.translate(self.currentGlyph.width)
         dt.drawPath(pen.path)
         dt.restore()
コード例 #4
0
    def drawRect_(self, rect):
        # draw here!

        if self.delegate.checked:
            AppKit.NSColor.selectedControlColor().set()
            selectionPath = AppKit.NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                AppKit.NSInsetRect(rect, 2, 2), 4, 4)
            AppKit.NSColor.selectedControlColor().colorWithAlphaComponent_(
                0.1).set()
            selectionPath.fill()
            AppKit.NSColor.selectedControlColor().set()
            selectionPath.stroke()

        frame_width, frame_height = self.frame().size
        w, h = [i - 2 * self._inset for i in self.frame().size]

        glyph_pair = self._glyphData
        glyph_l, glyph_r = glyph_pair
        font = glyph_l.getParent()
        upm = font.info.unitsPerEm
        scale_factor = h / (upm * 1.2)
        drawBot.translate(frame_width / 2, self._inset)
        drawBot.scale(scale_factor)

        drawBot.stroke(None)
        if self._kern_value <= 0:
            drawBot.fill(1, 0.3, 0.75)
        else:
            drawBot.fill(0, 0.8, 0)

        drawBot.rect(  # bottom rectangle
            0 - abs(self._kern_value) / 2, self._inset / scale_factor,
            abs(self._kern_value), 2 * self._inset / scale_factor)
        drawBot.rect(  # top rectangle
            0 - abs(self._kern_value) / 2, (h - self._inset) / scale_factor,
            abs(self._kern_value), 2 * self._inset / scale_factor)
        drawBot.translate(0, upm / 3)
        drawBot.translate(-glyph_l.width - self._kern_value / 2, 0)

        for glyph in glyph_pair:
            path = glyph.getRepresentation('defconAppKit.NSBezierPath')

            drawBot.stroke(None)
            drawBot.fill(0)
            drawBot.drawPath(path)
            drawBot.translate(glyph.width + self._kern_value, 0)
コード例 #5
0
ファイル: mainController.py プロジェクト: late2game/ttools2
    def _drawStems(self, currentGlyph, scalingFactor, offset_X=0):
        if STEM_KEY not in currentGlyph.lib:
            return None

        stemData = calcStemsData(currentGlyph, STEM_KEY)
        for PTs, DIFFs, middlePoint in stemData:
            pt1, pt2 = PTs
            horDiff, verDiff = DIFFs

            dt.save()
            dt.translate(offset_X, 0)
            dt.stroke(*self.stemColor)
            dt.fill(None)
            dt.strokeWidth(1 * scalingFactor)

            dt.newPath()
            if horDiff > verDiff:  # ver
                rightPt, leftPt = PTs
                if pt1.x > pt2.x:
                    rightPt, leftPt = leftPt, rightPt
                dt.moveTo((leftPt.x, leftPt.y))
                dt.curveTo((leftPt.x - horDiff / 2, leftPt.y),
                           (rightPt.x + horDiff / 2, rightPt.y),
                           (rightPt.x, rightPt.y))

            else:  # hor
                topPt, btmPt = PTs
                if pt2.y > pt1.y:
                    btmPt, topPt = topPt, btmPt
                dt.moveTo((btmPt.x, btmPt.y))
                dt.curveTo((btmPt.x, btmPt.y + verDiff / 2),
                           (topPt.x, topPt.y - verDiff / 2),
                           (topPt.x, topPt.y))
            dt.drawPath()
            dt.restore()

            dt.save()
            dt.translate(offset_X, 0)
            textQualities(BODYSIZE_CAPTION * scalingFactor)
            dataToPlot = u'↑{:d}\n→{:d}'.format(int(verDiff), int(horDiff))
            textWidth, textHeight = dt.textSize(dataToPlot)
            textRect = (middlePoint[0] - textWidth / 2.,
                        middlePoint[1] - textHeight / 2., textWidth,
                        textHeight)
            dt.textBox(dataToPlot, textRect, align='center')
            dt.restore()
コード例 #6
0
ファイル: transform.py プロジェクト: typesupply/popuptools
 def drawActionPreview(self, data):
     if not self.previewObjects:
         return
     pen = CocoaPen(glyphSet=self.glyph.layer)
     for obj in self.previewObjects:
         if isinstance(obj, BaseBPoint):
             pass
         elif isinstance(obj, BaseContour):
             obj.draw(pen)
         elif isinstance(obj, BaseComponent):
             obj.draw(pen)
     pixel = 1.0 / data["scale"]
     r, g, b, a = getDefault("glyphViewEchoStrokeColor")
     with bot.savedState():
         bot.fill(None)
         bot.stroke(r, g, b, a)
         bot.strokeWidth(pixel)
         bot.drawPath(pen.path)
    def drawBkgnd(self, info):
        # Draw the interpolated glyph outlines
        scale = info["scale"]
        ptSize = 7 * scale
        if self.interpolatedGlyph:
            # Draw the glyph outline
            pen = CocoaPen(None)
            self.interpolatedGlyph.draw(pen)
            dt.fill(r=None, g=None, b=None, a=1)
            dt.stroke(r=0, g=0, b=0, a=0.4)
            dt.strokeWidth(2 * scale)
            dt.save()
            dt.translate(self.currentGlyph.width)
            dt.drawPath(pen.path)
            dt.stroke(r=0, g=0, b=0, a=1)
            # Draw the points and handles
            for contour in self.interpolatedGlyph.contours:
                for bPoint in contour.bPoints:
                    inLoc = self.addPoints(bPoint.anchor, bPoint.bcpIn)
                    outLoc = self.addPoints(bPoint.anchor, bPoint.bcpOut)
                    dt.line(inLoc, bPoint.anchor)
                    dt.line(bPoint.anchor, outLoc)
                    dt.fill(r=1, g=1, b=1, a=1)
                    dt.oval(bPoint.anchor[0] - (ptSize * 0.5),
                            bPoint.anchor[1] - (ptSize * 0.5), ptSize, ptSize)
                    dt.fill(0)
                    # Draw an "X" over each BCP
                    if not bPoint.bcpIn == (0, 0):
                        dt.oval(inLoc[0] - (ptSize * 0.5),
                                inLoc[1] - (ptSize * 0.5), ptSize, ptSize)
                        #dt.line((inLoc[0]-(ptSize*0.5), inLoc[1]-(ptSize*0.5)), (inLoc[0]+(ptSize*0.5), inLoc[1]+(ptSize*0.5)))
                        #dt.line((inLoc[0]+(ptSize*0.5), inLoc[1]-(ptSize*0.5)), (inLoc[0]-(ptSize*0.5), inLoc[1]+(ptSize*0.5)))
                    if not bPoint.bcpOut == (0, 0):
                        dt.oval(outLoc[0] - (ptSize * 0.5),
                                outLoc[1] - (ptSize * 0.5), ptSize, ptSize)
                        #dt.line((outLoc[0]-(ptSize*0.5), outLoc[1]-(ptSize*0.5)), (outLoc[0]+(ptSize*0.5), outLoc[1]+(ptSize*0.5)))
                        #dt.line((outLoc[0]+(ptSize*0.5), outLoc[1]-(ptSize*0.5)), (outLoc[0]-(ptSize*0.5), outLoc[1]+(ptSize*0.5)))

            dt.restore()
コード例 #8
0
    def drawRect_(self, rect):
        # draw here!
        frame_width, frame_height = self.frame().size
        w, h = [i - 2 * self._inset for i in self.frame().size]
        drawBot.fill(None)
        drawBot.rect(self._inset, self._inset, w, h)
        drawBot.stroke(0)
        drawBot.strokeWidth(1)

        glyph_pair = self._glyphData
        glyph_l, glyph_r = glyph_pair
        font = glyph_l.getParent()
        upm = font.info.unitsPerEm
        scale_factor = h / (upm * 1.2)
        drawBot.translate(frame_width / 2, self._inset)
        drawBot.scale(scale_factor)

        drawBot.stroke(None)
        if self._kern_value <= 0:
            drawBot.fill(1, 0.3, 0.75)
        else:
            drawBot.fill(0, 0.8, 0)
            # drawBot.fill(0.4, 1, 0.8)
        drawBot.rect(
            0 - abs(self._kern_value) / 2, 0,
            abs(self._kern_value), h * 1 / scale_factor)

        drawBot.translate(0, upm / 3)
        drawBot.translate(-glyph_l.width - self._kern_value / 2, 0)

        for glyph in glyph_pair:
            path = glyph.getRepresentation('defconAppKit.NSBezierPath')

            drawBot.stroke(None)
            # drawBot.fill(0, 1, 0)
            drawBot.fill(0)
            drawBot.drawPath(path)
            drawBot.translate(glyph.width + self._kern_value, 0)
コード例 #9
0
    def _drawException(self, aPair, correction):
        lftGlyphName, rgtGlyphName = aPair
        lftGlyph, rgtGlyph = self.fontObj[lftGlyphName], self.fontObj[
            rgtGlyphName]

        dt.save()
        dt.fill(None)
        dt.stroke(*LIGHT_GRAY)
        dt.strokeWidth(20)

        # calc wiggle line
        pt1 = Point(-lftGlyph.width, 0)
        pt2 = Point(rgtGlyph.width + correction, 0)
        wigglePoints = calcWiggle(pt1, pt2, 100, 100, .65)

        # draw wiggle line
        dt.newPath()
        dt.moveTo(wigglePoints[0])
        for eachBcpOut, eachBcpIn, eachAnchor in wigglePoints[1:]:
            dt.curveTo(eachBcpOut, eachBcpIn, eachAnchor)
        dt.drawPath()

        dt.restore()
コード例 #10
0
 def draw(self):
     drawPath()
コード例 #11
0
    def draw(self, scale):
        if not self._didCalculate: return
        cornerDot = bcpDot = tanDot = 4
        if self.dragState == 'flats':
            tanDot = 10
        elif self.dragState == "curves":
            bcpDot = 10

        stackedbv = self._b1_v == self._b2_v
        stackedbh = self._b1_h == self._b2_h
        stackedtv = self._t1_v == self._t2_v
        stackedth = self._t1_h == self._t2_h
        self.dot((self._xMin, self._t1_v),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedtv)
        self.dot((self._xMax, self._t1_v),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedtv)
        self.dot((self._xMin, self._t2_v),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedtv)
        self.dot((self._xMax, self._t2_v),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedtv)
        self.dot((self._t1_h, self._yMin),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedth)
        self.dot((self._t1_h, self._yMax),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedth)
        self.dot((self._t2_h, self._yMin),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedth)
        self.dot((self._t2_h, self._yMax),
                 s=tanDot,
                 scale=scale,
                 stacked=stackedth)
        self.dot((self._xMin, self._b1_v),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbv)
        self.dot((self._xMax, self._b1_v),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbv)
        self.dot((self._xMin, self._b2_v),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbv)
        self.dot((self._xMax, self._b2_v),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbv)
        self.dot((self._b1_h, self._yMax),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbh)
        self.dot((self._b2_h, self._yMax),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbh)
        self.dot((self._b1_h, self._yMin),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbh)
        self.dot((self._b2_h, self._yMin),
                 s=bcpDot,
                 scale=scale,
                 stacked=stackedbh)
        ctx.save()
        ctx.stroke(1, 0, 0, .4)
        ctx.fill(0, 0, 0, 0.03)
        ctx.strokeWidth(.5 * scale)
        self.buildShapePath(scale)
        ctx.drawPath()

        center = .5 * (self._xMax + self._xMin), .5 * (self._yMax + self._yMin)
        self.dot(center, scale=scale)
        ctx.fontSize(10 * scale)
        ctx.fill(1, 0.5, 0)
        ctx.font("Menlo-Regular")
        ctx.stroke(None)
        t = "the symmetrical,\nround shape\ndrawing tool\npress command to move the flat\npress option to move the bcps\n\nwidth %3.3f\nheight %3.3f" % (
            self._width, self._height)
        if self._orientation:
            t += "\nhorizontal"
        else:
            t += "\nvertical"
        if self.dragState == "flats":
            t += "\n\nyou're changing the flat factor\nx %3.3f\ny %3.3f" % (
                self.flatFactor_x, self.flatFactor_y)
        elif self.dragState == "curves":
            t += "\n\nyou're changing the bcp factor\nx %3.3f\ny %3.3f" % (
                self.bcpFactor_x, self.bcpFactor_y)
        ctx.text(t, center)
        ctx.restore()
コード例 #12
0
 def draw(self):
     drawPath()