コード例 #1
0
ファイル: StrokePen.py プロジェクト: jtanadi/robofontScripts
    def draw(self):
        """
        This function is what Canvas calls to draw
        """

        db.translate(400, 400)
        db.scale(self.scale)

        for letter in self.letters:
            rotateFlag = False
            glyph = self.f[letter]

            pt0 = (glyph.contours[0].points[0].x,
                   glyph.contours[0].points[0].y)
            pt1 = (glyph.contours[0].points[1].x,
                   glyph.contours[0].points[1].y)
            pt2 = (glyph.contours[0].points[-2].x,
                   glyph.contours[0].points[-2].y)
            pt3 = (glyph.contours[0].points[-1].x,
                   glyph.contours[0].points[-1].y)

            if getAngle(pt0, pt1) >= 90 or getAngle(pt0, pt1) <= -90:
                rotateFlag = True
                db.translate(0, -820)

            db.newPath()
            pen = StrokePen(glyph.getParent(), self.widthValue)
            glyph.draw(pen)
            db.drawPath()

            if rotateFlag:
                db.rotate(-90)
                db.translate(0, 0)
            else:
                db.translate(glyph.width, 0)
コード例 #2
0
def hslDonut(rings,
             ringThickness,
             holeRadius,
             fixedValue,
             isLuminosityConst,
             captions=True):
    for angle in range(FULL_CIRCLE):
        for eachRing in range(rings):
            ringFactor = eachRing / (rings - 1)
            radius = holeRadius + eachRing * ringThickness

            if isLuminosityConst:
                rgbClr = hls_to_rgb(angle / FULL_CIRCLE, fixedValue,
                                    ringFactor)
            else:
                rgbClr = hls_to_rgb(angle / FULL_CIRCLE, ringFactor,
                                    fixedValue)
            lineQualities(rgbClr, ringThickness)

            newPath()
            arc((0, 0), radius, angle - .5, angle + .5, clockwise=False)
            drawPath()

        with savedState():
            if angle % 10 == 0 and captions:
                captionRadius = radius + ringThickness
                rotate(angle)

                lineQualities(thickness=.5)
                line((captionRadius - 2, 0), (captionRadius + 2, 0))

                typeQualities()
                text(f'{angle}', (radius + ringThickness + 6, 0))
コード例 #3
0
    def draw(self, origin, view):

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        save()
        sh = 1.0 * self.h / self.ih
        transform((1, 0, 0, 1, px, py))
        scale(sh)
        if self.pathFilter is not None:
            self.pathFilter(self, self.glyph.path)
        if self.css('fill') != NO_COLOR or self.css('stroke') != NO_COLOR:
            setFillColor(self.css('fill'))
            print(self.css('strokeWidth') or 1), sh
            setStrokeColor(self.css('stroke', NO_COLOR),
                           (self.css('strokeWidth') or 20))
            fill(0)
            stroke(1, 0, 0)
            strokeWidth(20)
            drawPath(self.glyph.path)
        restore()

        # If there are child elements, draw them over the polygon.
        self._drawElements(p, view)

        # Draw optional bounding box.
        #self.drawFrame(origin, view)

        self._restoreScale()
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
コード例 #4
0
ファイル: StrokePen.py プロジェクト: jtanadi/robofontScripts
    def _lineTo(self, pt):
        x0, y0 = self._getCurrentPoint()
        x, y = pt

        db.fill(None)
        db.stroke(r.random(), r.random(), r.random(), 1)
        db.strokeWidth(self.width)

        # db.newPath()
        db.moveTo((x0, y0))
        db.lineTo(pt)
        db.drawPath()

        # Or use line() instead of newPath, moveTo, lineTo, drawPath combo
        # line((x0, y0), (x, y))

        # Use rectangle below... still not sure why one over the other
        # angle = self.getAngle((x0, y0), (x, y))
        # distance = self.getDistance((x0, y0), (x, y))

        # fill(0, 0, 1, 1)

        # with savedState():
        #     rotate(angle, (x0, y0))
        #     rect(x0, y0 - self.width / 2, distance, self.width)

        self.pointsList.append(pt)
コード例 #5
0
ファイル: draw.py プロジェクト: musca1997/shitdraw-bot
def draw():
    for i in range(0, 100):
        drawBot.newDrawing()
        drawBot.newPage(1000, 1000)
        drawBot.radialGradient(
            (randint(1,500), randint(1,500)),                         # startPoint
            (randint(1,800), randint(1,800)),                         # endPoint
            [(randint(0,1), randint(0,1), randint(0,1)), (randint(0,1), randint(0,1), randint(0,1)), (randint(0,1), randint(0,1), randint(0,1))],  # colors
            [randint(0,1), randint(0,1), randint(0,1)],                         # locations
            randint(0,1),                                  # startRadius
            randint(0,800)                                # endRadius
        )
# draw a rectangle
        drawBot.rect(randint(0,100), randint(0,100), randint(0,1000), randint(0,1000))

# draw the path
        drawBot.drawPath()
        drawBot.blendMode("multiply")
# set a color
        drawBot.rect(randint(1,10), randint(1,10), randint(1,100), randint(1,100))

# draw oval x, y, width, height
        drawBot.oval(randint(1,500), randint(1,500), randint(1,500), randint(1,500))
        drawBot.oval(randint(1,500), randint(1,500), randint(1,500), randint(1,500))
        drawBot.cmykFill(randint(0,1), randint(0,1), randint(0,1), randint(0,1))
# draw a rectangle
        drawBot.rect(randint(1,10), randint(1,10), randint(1,1000), randint(1,1000))
# set an other color
        drawBot.cmykFill(randint(0,1), randint(0,1), randint(0,1), randint(0,1))
# overlap a second rectangle
        drawBot.rect(randint(1,500), randint(1,500), randint(1,600), randint(1,600))
        drawBot.saveImage(str(i) + '.png' )
        drawBot.endDrawing()
        print(str(i) + ' done.')
コード例 #6
0
    def drawMissingElementRect(self, e, origin):
        u"""When designing templates and pages, this will draw a filled rectangle on the element
        bounding box (if self.css('missingElementFill' is defined) and a cross, indicating
        that this element has missing content (as in unused image frames).
        Only draw if self.css('showGrid') is True."""
        if self.showMissingElementRect:

            p = pointOffset(e.point, origin)
            p = e._applyOrigin(p)
            p = e._applyScale(p)
            px, py, _ = e._applyAlignment(p)  # Ignore z-axis for now.
            self.setShadow()

            sMissingElementFill = self.css('viewMissingElementFill', NO_COLOR)
            if sMissingElementFill is not NO_COLOR:
                setFillColor(sMissingElementFill)
                setStrokeColor(None)
                rect(px, py, self.w, self.h)
            # Draw crossed rectangle.
            setFillColor(None)
            setStrokeColor(0, 0.5)
            rect(px, py, self.w, self.h)
            newPath()
            moveTo((px, py))
            lineTo((px + self.w, py + self.h))
            moveTo((px + self.w, py))
            lineTo((px, py + self.h))
            drawPath()

            self.resetShadow()
            e._restoreScale()
コード例 #7
0
ファイル: type.py プロジェクト: gferreira/fontPartsMap
    def drawContour(self):

        color = self.colorScheme.colorsRGB['contour']

        drawBot.save()
        drawBot.fontSize(self.captionSize)
        drawBot.font(self.captionFont)

        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            # draw contours
            drawBot.stroke(*color)
            drawBot.strokeWidth(self.contourStrokeWidth)
            drawBot.fill(None)
            B = drawBot.BezierPath()
            for contour in glyph.contours:
                contour.draw(B)
            drawBot.drawPath(B)

            # done glyph
            drawBot.translate(glyph.width, 0)

        drawBot.restore()
コード例 #8
0
    def drawLetters(self):    
    
        xFactor = self.xHeightTarget / xHeightCurrent
        descenderTarget = descender * xFactor
        
        pageWidth = drawBot.width()
        pageHeight = drawBot.height()
        
        if self.descBox == 1:
            drawBot.stroke(1,0,0, 1)
            drawBot.line((margin, pageHeight-margin-self.xHeightTarget+descenderTarget),(pageWidth-dpi, pageHeight-margin-self.xHeightTarget+descenderTarget))
        
        elif self.descBox == 0:
            drawBot.stroke(0,0,0,0)
        
        drawBot.fill(0,0,0, 1)
        drawBot.stroke(0,0,0, 0)

        drawBot.translate(margin, pageHeight-margin-self.xHeightTarget)

        drawBot.scale(xFactor)

        for g in self.text:
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawBot.drawPath(pen.path)
            drawBot.translate(f[g].width, 0)
        

        pdf = drawBot.pdfImage()
        self.w.canvas.setPDFDocument(pdf)
コード例 #9
0
    def draw(self):
        self.xFactor = self.targetXheight / currentXheight

        drawBot.newDrawing()
        drawBot.newPage("LetterLandscape")

        pageWidth = drawBot.width()

        drawBot.fill(0, 0, 0, 0.5)
        drawBot.stroke(0, 0, 0, 1)

        drawBot.rect(.5 * dpi, .5 * dpi, pageWidth - (1 * dpi),
                     self.targetXheight)

        drawBot.translate(0.5 * dpi, .5 * dpi)
        drawBot.scale(self.xFactor)

        for g in self.text:
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawBot.drawPath(pen.path)
            drawBot.translate(f[g].width, 0)

        pdf = drawBot.pdfImage()
        # set the pdf data in the canvas
        self.w.canvas.setPDFDocument(pdf)
コード例 #10
0
ファイル: type.py プロジェクト: gferreira/fontPartsMap
    def drawGlyph(self):
        color = self.colorScheme.colorsRGB['glyph']
        drawBot.save()
        drawBot.fontSize(self.captionSize)
        drawBot.font(self.captionFont)
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            # contours
            drawBot.fill(*color)
            B = drawBot.BezierPath()
            for contour in glyph.contours:
                contour.draw(B)
            drawBot.drawPath(B)

            # advance width
            if self.glyphWidthDraw:
                drawBot.save()
                drawBot.strokeWidth(self.glyphWidthStrokeWidth)
                drawBot.stroke(*color)
                drawBot.line((0, self.yBottom), (0, self.yTop))
                drawBot.restore()

            # glyph data
            if self.glyphDataDraw:
                h = self.captionSize * 1.5
                m = 40
                w = glyph.width - m * 2
                drawBot.save()
                drawBot.stroke(None)
                drawBot.fill(*color)
                y = self.yTop - h
                drawBot.textBox(glyph.name, (m, y, w, h))
                drawBot.textBox(str(glyph.unicode), (m, y, w, h), align='right')
                y = self.yBottom
                drawBot.textBox(str(int(glyph.width)), (m, y, w, h), align='center')
                drawBot.restore()

            # done glyph
            drawBot.translate(glyph.width, 0)

        # last margin
        if self.glyphWidthDraw:
            drawBot.strokeWidth(self.glyphWidthStrokeWidth)
            drawBot.stroke(*color)
            drawBot.line((0, self.yBottom), (0, self.yTop))

        # done
        drawBot.restore()
コード例 #11
0
ファイル: animation.py プロジェクト: stenson/furniture
    def draw(self, saving=False, saveTo=None, fmt="pdf", layers=[], fill=None):
        savingToFont = isinstance(fmt, defcon.Font)
        if saving:
            db.newDrawing()
            self.saving = True
        else:
            self.saving = False

        db.newPage(*self.animation.dimensions)
        self.page = Rect.page()

        self.bps = {}
        for l in layers:
            self.bps[l] = RichBezier()

        with db.savedState():
            if fill and not saveTo:
                with db.savedState():
                    db.fill(*fill)
                    db.rect(*self.page)
            self.layers = layers
            self.animation.fn(self)
            self.layers = None
        if self.animation.burn:
            box = self.page.take(64,
                                 Edge.MinY).take(120,
                                                 Edge.MaxX).offset(-24, 24)
            db.fontSize(20)
            db.lineHeight(20)
            db.font("Menlo-Bold")
            db.fill(0, 0.8)
            db.rect(*box.inset(-14, -14).offset(0, 2))
            db.fill(1)
            db.textBox("{:07.2f}\n{:04d}\n{:%H:%M:%S}".format(
                self.time, self.i, datetime.datetime.now()),
                       box,
                       align="center")

        for k, bez in self.bps.items():
            with db.savedState():
                db.fill(*bez.fill)
                db.drawPath(bez.bp)

        if saving:
            if savingToFont:
                for k, bez in self.bps.items():
                    g = defcon.Glyph()
                    g.name = "frame_" + str(self.i)
                    g.unicode = self.i + 48  # to get to 0
                    g.width = self.animation.dimensions[0]
                    bez.bp.drawToPen(g.getPen())
                    fmt.insertGlyph(g)
            else:
                db.saveImage(f"{saveTo}/{self.i}.{fmt}")
            db.endDrawing()

        self.saving = False
コード例 #12
0
def drawGlyphPath(font, glyphName, x, y, s=0.1, fillColor=0, strokeColor=None, strokeWidth=0):
    glyph = font[glyphName]
    save()
    setFillColor(fillColor)
    setStrokeColor(strokeColor, strokeWidth)
    transform((1, 0, 0, 1, x - glyph.width/2*s, y))
    scale(s)
    drawPath(glyph.path)
    restore()
コード例 #13
0
    def renderPath(self, pathCommands, isClosed=True):

        self.begin()
        for command in pathCommands:
            command.render(ctx, self)

        if isClosed:
            self.closePath()

        ctx.drawPath()
コード例 #14
0
def drawGlyph(g):
    # Get glyph outline
    f = g.font
    pen = CocoaPen(f)
    g.draw(pen)
    bezierPath = pen.path
    # Draw
    with db.savedState():
        db.translate(-g.width * 0.5, 450)  # Center the glyph
        path = db.BezierPath()
        path.setNSBezierPath(bezierPath)
        db.drawPath(path)
コード例 #15
0
    def drawGrid(self, e, origin):
        u"""Draw grid of lines and/or rectangles if colors are set in the style.
        Normally px and py will be 0, but it's possible to give them a fixed offset."""
        # Drawing the grid as squares.
        if not self.showGrid:
            return
        #if not self.showGridColumns or not self.showGrid:
        #    return
        p = pointOffset(e.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = e._applyAlignment(p)  # Ignore z-axis for now.

        sGridFill = e.css('viewGridFill', NO_COLOR)
        gutterW = e.gw  # Gutter width
        gutterH = e.gh  # Gutter height
        columnWidth = e.cw  # Column width
        columnHeight = e.ch  # Column height
        padL = e.pl  # Padding left
        padT = e.pt  # Padding top
        padR = e.pr  # padding right
        padB = e.pb  # padding bottom
        padW = e.pw  # Padding width
        padH = e.ph  # Padding height

        w = e.w
        h = e.h

        if e.isRight():
            ox = px + padR
        else:
            ox = px + padL
        oy = py + padB

        if self.showGrid and self.css('viewGridStroke',
                                      NO_COLOR) is not NO_COLOR:
            setFillColor(None)
            setStrokeColor(self.css('viewGridStroke', NO_COLOR),
                           self.css('viewGridStrokeWidth'))
            newPath()
            for cx, cw in e.getGridColumns():
                moveTo((ox + cx, oy))
                lineTo((ox + cx, oy + padH))
                moveTo((ox + cx + cw, oy))
                lineTo((ox + cx + cw, oy + padH))
            for cy, ch in e.getGridRows():
                moveTo((ox, oy + cy))
                lineTo((ox + padW, oy + cy))
                moveTo((ox, oy + cy + ch))
                lineTo((ox + padW, oy + cy + ch))
            drawPath()
            #text(fs+repr(index), (ox + M * 0.3, oy + M / 4))
        """
コード例 #16
0
def draw(txt="a", variations={}, caption=""):
    db.newPage(w * scale, h * scale)
    db.scale(scale)
    db.fill(*BACKCOL)
    db.rect(0, 0, w, h)
    txt = db.FormattedString(txt, font="Handjet-Regular", fontSize=500, fontVariations=variations)
    db.fill(*TEXTCOL)
    db.stroke(None)
    path = db.BezierPath()
    path.text(txt, (w / 2, 95), align="center")
    db.drawPath(path)
    txt = db.FormattedString(caption, font="AdapterMonoPE-Regular", fontSize=11, fill=TEXTCOL)
    db.text(txt, (w / 2, 40), align="center")
コード例 #17
0
ファイル: StrokePen.py プロジェクト: jtanadi/robofontScripts
    def _curveToOne(self, pt1, pt2, pt3):
        x0, y0 = self._getCurrentPoint()

        db.fill(None)
        db.stroke(r.random(), r.random(), r.random(), 1)
        db.strokeWidth(self.width)

        # db.newPath()
        db.moveTo((x0, y0))
        db.curveTo(pt1, pt2, pt3)
        db.drawPath()

        self.pointsList.append(pt3)
コード例 #18
0
    def drawPageCropMarks(self, e, origin):
        u"""If the show flag is set, then draw the cropmarks or page frame."""
        if self.showPageCropMarks:
            x, y, _ = point3D(origin)  # Ignore z-axus for now.
            w, h = e.w, e.h
            folds = self.css('folds')
            bleed = self.css('bleed') / 2  # 1/2 overlap with image bleed
            cmSize = min(self.css('viewCropMarkSize', 32), self.pl)
            cmStrokeWidth = self.css('viewCropMarkStrokeWidth')

            fill(None)
            cmykStroke(1, 1, 1, 1)
            strokeWidth(cmStrokeWidth)
            newPath()
            # Bottom left
            moveTo((x - bleed, y))
            lineTo((x - cmSize, y))
            moveTo((x, y - bleed))
            lineTo((x, y - cmSize))
            # Bottom right
            moveTo((x + w + bleed, y))
            lineTo((x + w + cmSize, y))
            moveTo((x + w, y - bleed))
            lineTo((x + w, y - cmSize))
            # Top left
            moveTo((x - bleed, y + h))
            lineTo((x - cmSize, y + h))
            moveTo((x, y + h + bleed))
            lineTo((x, y + h + cmSize))
            # Top right
            moveTo((x + w + bleed, y + h))
            lineTo((x + w + cmSize, y + h))
            moveTo((x + w, y + h + bleed))
            lineTo((x + w, y + h + cmSize))
            # Any fold lines to draw?
            if folds is not None:
                for fx, fy in folds:
                    if fx is not None:
                        moveTo((x + fx, y - bleed))
                        lineTo((x + fx, y - cmSize))
                        moveTo((x + fx, y + h + bleed))
                        lineTo((x + fx, y + h + cmSize))
                    if fy is not None:
                        moveTo((x - bleed, y + fy))
                        lineTo((x - cmSize, y + fy))
                        moveTo((x + w + bleed, y + fy))
                        lineTo((x + w + cmSize, y + fy))
            drawPath()
コード例 #19
0
    def draw(self, origin, view):
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        setStrokeColor(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        newPath()
        moveTo((px, py))
        lineTo((px + self.w, py + self.h))
        drawPath()

        # If there are child elements, draw them over the line.
        self._drawElements(p, view)

        self._restoreScale()
        view.drawElementMetaInfo(self, origin)
コード例 #20
0
 def drawCurrentGlyph(self):
     db.newDrawing()
     db.translate(100, 100)
     db.scale(0.8)
     db.fill(None)
     db.stroke(0.2, 0.3, 1)
     db.rect(0, 0, 1000, 1000)
     db.stroke(None)
     db.translate(
         0, 120
     )  # Baseline at 120 from the bottom of the Ideographic Em Square
     db.fill(0, 0.3)
     db.stroke(0)
     if self._currentGlyphPath is not None:
         db.drawPath(self._currentGlyphPath)
     db.endDrawing()
コード例 #21
0
def drawArrow(e, view, xs, ys, xt, yt, onText=1, startMarker=False, endMarker=False):
    u"""Draw curved arrow marker between the two points.
    TODO: Add drawing of real arrow-heads, rotated in the right direction."""
    fms = e.css('flowMarkerSize')
    fmf = e.css('flowCurvatureFactor')
    if onText == 1:
        c = e.css('flowConnectionStroke2', NO_COLOR)
    else:
        c = e.css('flowConnectionStroke1', NO_COLOR)
    setStrokeColor(c, e.css('flowConnectionStrokeWidth'))
    if startMarker:
        setFillColor(e.css('flowMarkerFill', NO_COLOR))
        oval(xs - fms, ys - fms, 2 * fms, 2 * fms)
    xm = (xt + xs)/2
    ym = (yt + ys)/2
    xb1 = xm + onText * (yt - ys) * fmf
    yb1 = ym - onText * (xt - xs) * fmf
    xb2 = xm - onText * (yt - ys) * fmf
    yb2 = ym + onText * (xt - xs) * fmf
    # Arrow head position
    arrowSize = 12
    arrowAngle = 0.4
    angle = atan2(xt-xb2, yt-yb2)
    hookedAngle = radians(degrees(angle)-90)
    ax1 = xt - cos(hookedAngle+arrowAngle) * arrowSize
    ay1 = yt + sin(hookedAngle+arrowAngle) * arrowSize
    ax2 = xt - cos(hookedAngle-arrowAngle) * arrowSize
    ay2 = yt + sin(hookedAngle-arrowAngle) * arrowSize
    newPath()
    setFillColor(None)
    moveTo((xs, ys))
    curveTo((xb1, yb1), (xb2, yb2), ((ax1+ax2)/2, (ay1+ay2)/2)) # End in middle of arrow head.
    drawPath()

    #  Draw the arrow head.
    newPath()
    setFillColor(c)
    setStrokeColor(None)
    moveTo((xt, yt))
    lineTo((ax1, ay1))
    lineTo((ax2, ay2))
    closePath()
    drawPath()
    if endMarker:
        oval(xt - fms, yt - fms, 2 * fms, 2 * fms)
def drawPlusMinus(sf, a):
    x, y = a.x, a.y
    x, y, ang = a.x, a.y, a.angle
    path = d.BezierPath()
    path.moveTo((-50, 0))
    path.lineTo((50, 0))
    if a.type == PLUS:
        path.moveTo((0, 50))
        path.lineTo((0, -50))
    path.closePath()
    path.scale(sf)
    d.lineCap("round")
    d.lineJoin("round")
    path.translate(x, y)
    d.fill(None)
    d.stroke(1, 0, 0, 0.5)
    d.strokeWidth(annoThickness / sf)
    d.drawPath(path)
def drawArrow(sf, a):
    x, y, ang = a.x, a.y, a.angle
    path = d.BezierPath()
    path.moveTo((50, 40))
    path.lineTo((0, 0))
    path.lineTo((50, -40))
    path.moveTo((0, 0))
    path.lineTo((120, 0))
    path.closePath()
    path.scale(sf)
    d.lineCap("round")
    d.lineJoin("round")
    path.rotate(ang, center=(0, 0))
    path.translate(x, y)
    d.fill(None)
    d.stroke(1, 0, 0, 0.5)
    d.strokeWidth(annoThickness / sf)
    d.drawPath(path)
コード例 #24
0
ファイル: type.py プロジェクト: gferreira/fontPartsMap
 def drawComponent(self):
     color = self.colorScheme.colorsRGB['component']
     tempName = '_tmp_'
     drawBot.save()
     for char in self.txt:
         uni = ord(char)
         glyphName = UV2AGL.get(uni)
         glyph = self.font[glyphName]
         drawBot.fill(*color + (0.5,))
         drawBot.stroke(*color)
         if len(glyph.components):
             B = drawBot.BezierPath()
             for component in glyph.components:
                 component.draw(B)
             drawBot.drawPath(B)
         # done glyph
         drawBot.translate(glyph.width, 0)
     drawBot.restore()
コード例 #25
0
def draw(gn="a", variations={}, caption=""):
    db.newPage(w * scale, h * scale)
    db.scale(scale)
    db.fill(*BACKCOL)
    db.rect(0, 0, w, h)
    fs = db.FormattedString()
    fs.font("Handjet-Regular")
    fs.fontSize(200)
    fs.appendGlyph(gn)
    db.fill(*TEXTCOL)
    db.stroke(None)
    path = db.BezierPath()
    path.text(fs, (w / 2, 145), align="center")
    db.drawPath(path)
    fs = db.FormattedString(caption,
                            font="AdapterMonoPE-Regular",
                            fontSize=10,
                            fill=TEXTCOL)
    db.text(fs, (w / 2, 40), align="center")
コード例 #26
0
def drawCropMarks(origin, w, h, bleed, cmSize, cmStrokeWidth, folds=None):
    u"""If the show flag is set, then draw the cropmarks or page frame."""
    x, y, _ = point3D(origin)  # Ignore z-axus for now.
    fill(None)
    cmykStroke(1, 1, 1, 1)
    strokeWidth(cmStrokeWidth)
    newPath()
    # Bottom left
    moveTo((x - bleed, y))
    lineTo((x - cmSize, y))
    moveTo((x, y - bleed))
    lineTo((x, y - cmSize))
    # Bottom right
    moveTo((x + w + bleed, y))
    lineTo((x + w + cmSize, y))
    moveTo((x + w, y - bleed))
    lineTo((x + w, y - cmSize))
    # Top left
    moveTo((x - bleed, y + h))
    lineTo((x - cmSize, y + h))
    moveTo((x, y + h + bleed))
    lineTo((x, y + h + cmSize))
    # Top right
    moveTo((x + w + bleed, y + h))
    lineTo((x + w + cmSize, y + h))
    moveTo((x + w, y + h + bleed))
    lineTo((x + w, y + h + cmSize))
    # Any fold lines to draw?
    if folds is not None:
        for fx, fy in folds:
            if fx is not None:
                moveTo((x + fx, y - bleed))
                lineTo((x + fx, y - cmSize))
                moveTo((x + fx, y + h + bleed))
                lineTo((x + fx, y + h + cmSize))
            if fy is not None:
                moveTo((x - bleed, y + fy))
                lineTo((x - cmSize, y + fy))
                moveTo((x + w + bleed, y + fy))
                lineTo((x + w + cmSize, y + fy))
    drawPath()
コード例 #27
0
def drawRegistrationMark(origin, cmSize, cmStrokeWidth, vertical):
    u"""Draw registration mark as position x, y."""
    x, y = origin
    if vertical:
        dx = cmSize / 2
        dy = cmSize
    else:
        dx = cmSize
        dy = cmSize / 2
    fill(None)
    cmykStroke(1, 1, 1, 1)
    strokeWidth(cmStrokeWidth)
    newPath()
    # Registration circle
    oval(x - cmSize / 4, y - cmSize / 4, cmSize / 2, cmSize / 2)
    # Registration cross, in length of direction.
    moveTo((x - dx, y))  # Horizontal line.
    lineTo((x + dx, y))
    moveTo((x, y + dy))  # Vertical line.
    lineTo((x, y - dy))
    drawPath()
コード例 #28
0
ファイル: type.py プロジェクト: gferreira/fontPartsMap
    def drawLayer(self):

        steps = 3
        alpha = 0.2 + 0.8 / (steps + 1)
        color = self.colorScheme.colorsRGB['layer']

        drawBot.save()

        # drawBot.fill(None)
        # drawBot.stroke(*color)
        # drawBot.strokeWidth(self.layerStrokeWidth)

        color += (alpha,)
        drawBot.fill(*color)
        drawBot.stroke(None)

        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')

            layerGlyphs = []
            for i in range(steps):
                factor = i * 1.0 / (steps - 1)
                g3 = RGlyph()
                g3.name = g1.name
                g3.unicode = g1.unicode
                g3.interpolate(factor, g1, g2)
                layerGlyphs.append(g3)

            for g in layerGlyphs:
                B = drawBot.BezierPath()
                g.draw(B)
                drawBot.drawPath(B)

            drawBot.translate(g2.width, 0)

        drawBot.restore()
コード例 #29
0
    def test_export_SVG_mixin(self):
        expectedPath = os.path.join(testDataDir, "expected_svgMixin.svg")
        drawBot.newDrawing()
        drawBot.newPage(100, 100)
        path = drawBot.BezierPath()
        path.svgID = "hello"
        path.svgClass = "foo bar"
        path.svgLink = "drawbot.com"
        path.rect(0, 0, 20, 20)
        drawBot.drawPath(path)
        txt = drawBot.FormattedString()
        txt += "world"
        txt.svgID = "hello"
        txt.svgClass = "foo bar"
        txt.svgLink = "drawbot.com"
        drawBot.text(txt, (20, 20))

        with TempFile(suffix=".svg") as tmp:
            drawBot.saveImage(tmp.path)
            self.assertEqual(
                readData(tmp.path), readData(expectedPath),
                "Files %r and %s are not the same" % (tmp.path, expectedPath))
コード例 #30
0
ファイル: type.py プロジェクト: gferreira/fontPartsMap
    def drawSegment(self):

        color = self.colorScheme.colorsRGB['segment']
        r = self.bPointSize * 0.5        

        drawBot.save()
        drawBot.fontSize(self.captionSize)
        drawBot.font(self.captionFont)
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            # draw segment contours
            drawBot.stroke(*color)
            drawBot.strokeWidth(self.segmentStrokeWidth)
            drawBot.fill(None)

            B = drawBot.BezierPath()
            glyph.draw(B)
            drawBot.drawPath(B)

            # draw segment points
            drawBot.stroke(None)
            drawBot.fill(*color)
            for x, y in B.onCurvePoints:
                drawBot.oval(x - r, y - r, r * 2, r * 2)

            drawBot.translate(glyph.width, 0)

        drawBot.restore()
コード例 #31
0
import drawBot
drawBot.newDrawing()
drawBot.size(600, 100)
p1 = drawBot.BezierPath()
p1.oval(5, 5, 70, 70)
p2 = drawBot.BezierPath()
p2.rect(25, 25, 70, 70)
drawBot.fill(0, 0.3)
drawBot.stroke(0)

drawBot.drawPath(p1)
drawBot.drawPath(p2)

pUnion = p1 | p2
pIntersection = p1 & p2
pXor = p1 ^ p2
pDiff1 = p1 % p2
pDiff2 = p2 % p1

for p in [pUnion, pIntersection, pXor, pDiff1, pDiff2]:
    drawBot.translate(100, 0)
    drawBot.drawPath(p)
コード例 #32
0
ファイル: pathWithCounter.py プロジェクト: typemytype/drawbot
import drawBot
drawBot.size(200, 200)

drawBot.newPath()
drawBot.moveTo((20, 20))
drawBot.lineTo((20, 100))
drawBot.lineTo((100, 100))
drawBot.lineTo((100, 180))
drawBot.curveTo((150, 180), (180, 150), (180, 100))
drawBot.lineTo((180, 20))
drawBot.closePath()

drawBot.moveTo((40, 40))
drawBot.lineTo((160, 40))
drawBot.curveTo((160, 65), (145, 80), (120, 80))
drawBot.lineTo((40, 80))
drawBot.closePath()

drawBot.fill(0.5, 0, 0)
drawBot.stroke(None)
drawBot.strokeWidth(10)
drawBot.drawPath()
コード例 #33
0
ファイル: removeOverlap.py プロジェクト: typemytype/drawbot
import drawBot
drawBot.newDrawing()
drawBot.size(200, 100)
p = drawBot.BezierPath()
p.oval(5, 5, 70, 70)
p.rect(25, 25, 70, 70)
drawBot.fill(0, 0.3)
drawBot.stroke(0)
drawBot.drawPath(p)
p.removeOverlap()
drawBot.translate(100, 0)
drawBot.drawPath(p)
コード例 #34
0
import drawBot
drawBot.newDrawing()
drawBot.size(200, 200)

testData = [
    ((25, 25, 50, 50), "rotate", (20,), (25, 25)),
    ((125, 25, 50, 50), "skew", (10, 10), (175, 25)),
    ((25, 125, 50, 50), "scale", (1.2, 1.4), (25, 175)),
]

for r, op, args, center in testData:
    drawBot.fill(0)
    bez = drawBot.BezierPath()
    bez.rect(*r)
    drawBot.drawPath(bez)
    with drawBot.savedState():
        drawBot.fill(1, 0, 0, 0.5)
        bez = drawBot.BezierPath()
        bez.rect(*r)
        getattr(bez, op)(*args, center=center)
        drawBot.drawPath(bez)