Esempio n. 1
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)
Esempio n. 2
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'
 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, 1, 0, 0.3)
     db.stroke(0)
     db.lineJoin("round")
     dcSelection = set(self.w.deepComponentList.getSelection())
     aeSelection = set(self.w.atomicElementList.getSelection())
     if self._currentGlyphOutline is not None:
         drawOutline(self._currentGlyphOutline)
     if self._currentGlyphComponents:
         for dcIndex, (dcName, atomicElements) in enumerate(
             self._currentGlyphComponents
         ):
             for aeIndex, (aeName, atomicOutline) in enumerate(atomicElements):
                 if dcIndex in dcSelection:
                     if aeIndex in aeSelection:
                         db.fill(1, 0, 0, 0.3)
                     else:
                         db.fill(0, 0, 1, 0.3)
                 else:
                     db.fill(0, 0.3)
                 drawOutline(atomicOutline)
     db.endDrawing()
Esempio n. 4
0
 def run(self, render_pass, renderer_state):
     use_pool = True
     if use_pool:
         pool = AppKit.NSAutoreleasePool.alloc().init()
     try:
         db.newDrawing()
         if renderer_state.previewing:
             ps = renderer_state.preview_scale
             db.size(self.rect.w * ps, self.rect.h * ps)
             db.scale(ps, ps)
             DATPen().rect(self.rect).f(self.bg).db_drawPath()
         else:
             db.size(self.rect.w, self.rect.h)
         render_pass.fn(*render_pass.args)
         result = None
         if renderer_state.previewing:
             previews = (render_pass.output_path.parent / "_previews")
             previews.mkdir(exist_ok=True, parents=True)
             preview_frame = previews / render_pass.output_path.name
             db.saveImage(str(preview_frame))
             result = preview_frame
         else:
             render_pass.output_path.parent.mkdir(exist_ok=True,
                                                  parents=True)
             db.saveImage(str(render_pass.output_path))
             result = render_pass.output_path
         db.endDrawing()
     finally:
         if use_pool:
             del pool
     return result
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
def drawCell(glyphName, cellWidth, cellHeight, cellLegendSize):

    # Cell outline
    db.fill(None)
    db.stroke(0)
    db.strokeWidth(0.25)
    db.rect(0, 0, cellWidth, cellHeight)

    charArea = cellWidth / 3.5
    fontSize = charArea * 0.7
    charStartingOffset = (cellWidth * 0.5) - (charArea * 1.5)

    # Glyph sample
    for iH, aH in enumerate(angles):
        for iV, aV in enumerate(reversed(angles)):
            locStr = "%s %s" % (aH, aV)

            f = instances[locStr]
            if glyphName in f:
                g = f[glyphName]

                with db.savedState():
                    db.translate(charStartingOffset, charStartingOffset
                                 )  # Center the nine glyphs in the cell
                    db.translate(
                        iH * charArea,
                        iV * charArea)  # Move to the current glyph in the cell
                    db.translate(charArea * 0.5,
                                 0)  # Offset to center glyph in cell
                    db.translate(0, cellLegendSize *
                                 3)  # Leave room for the legend
                    # Draw
                    db.fill(0)
                    db.stroke(None)
                    db.scale(fontSize / 1000)
                    drawGlyph(g)

                # Legend
                db.fill(None)
                db.stroke(0)
                db.strokeWidth(0.25)
                db.lineCap("round")
                db.line((cellLegendSize, cellLegendSize * 3),
                        (cellWidth - cellLegendSize, cellLegendSize * 3))
                unicodeValueStr = ""
                if g.unicode:
                    unicodeValueStr = hex(g.unicode)
                legendText = "%s\n%s" % (g.name, unicodeValueStr)
                fs = db.FormattedString(legendText,
                                        font="Tilt Neon",
                                        fontSize=cellLegendSize,
                                        tracking=1,
                                        lineHeight=cellLegendSize)
                db.text(fs, (cellLegendSize, cellLegendSize * 1.7))
Esempio n. 8
0
def backgroundImage(canvasWidth, canvasHeight):
    background_images = os.listdir('background_images/')
    background_image_path = 'background_images/' + background_images[(int)(
        len(background_images) * random.random())]
    # https://forum.drawbot.com/topic/180/how-do-i-size-an-image-with-the-imageobject-or-without/4
    srcWidth, srcHeight = db.imageSize(background_image_path)
    dstWidth, dstHeight = canvasWidth, canvasHeight
    factorWidth = dstWidth / srcWidth
    factorHeight = dstHeight / srcHeight
    with db.savedState():
        db.scale(factorWidth, factorHeight)
        db.image(background_image_path, (0, 0))
Esempio n. 9
0
    def draw(self, pages: list, export=False):
        if not pages: return
        tbs = self.w.customPages.page.textBoxList.getSelection()
        db.newDrawing()
        for page in pages:
            if page is None: continue
            db.newPage(*page.size)

            db.save()
            db.fill(*page.backgroundColor)
            db.rect(0, 0, *page.size)
            db.restore()

            for i, textbox in enumerate(page.textBoxes):
                db.save()
                db.translate(*textbox.position[:2])
                if not export:
                    db.save()
                    db.fill(None)
                    if i in tbs:
                        db.stroke(1, 0, 0, 1)
                    if not textbox.text:
                        db.fill(.5, .5, .5, .5)
                    db.rect(0, 0, *textbox.position[2:])
                    db.restore()

                if textbox.type == "Text":
                    db.save()
                    db.fill(*textbox.color)
                    db.tracking(textbox.tracking)
                    db.font(textbox.font, textbox.fontSize)
                    db.textBox(textbox.text, (0, 0, *textbox.position[2:]),
                               textbox.align)
                    db.restore()

                elif textbox.type == "UfoText":
                    db.save()
                    db.fill(*textbox.color)

                    s = textbox.fontSize / 1000
                    db.scale(s, s)
                    for pos, glyph in textbox.glyphs:
                        db.save()
                        db.translate(*pos)
                        if export:
                            glyph.round()
                        db.drawGlyph(glyph)
                        db.restore()
                    db.restore()
                db.restore()

        pdfData = db.pdfImage()
        self.w.customPages.canvas.setPDFDocument(pdfData)
Esempio n. 10
0
            def drawWeight(weight, text):

                db.newDrawing()
                self.designFrameViewer.draw()

                db.newPage(FRAMEX, FRAMEY)
                db.textBox(user, (0, FRAMEY - 85, FRAMEX, 55), align='center')
                db.textBox(text, (0, FRAMEY - 105, FRAMEX, 55), align='center')
                s = .11
                tx, ty = (FRAMEX / s - 1000 * 4) * .5, 1000 * 5.8
                db.save()
                db.scale(s, s)
                db.translate(tx, ty)
                db.fontSize(60)

                print(weight)
                for i, glyph in enumerate(weight):
                    drawDesignFrame()
                    if glyph[0].markColor:
                        db.fill(*glyph[0].markColor)
                    else:
                        db.fill(*INPROGRESS)
                    db.rect(0, 900, 250, 100)
                    db.fill(0, 0, 0, 1)
                    db.stroke(None)
                    db.textBox(glyph[0].name, (0, 900, 1000, 100),
                               align="center")

                    db.fill(0, 0, 0, 1)
                    db.stroke(None)
                    for c in glyph:
                        db.drawGlyph(c)
                    if (i + 1) % 4:
                        db.translate(1000, 0)
                    else:
                        db.translate(-1000 * 3, -1200)

                db.restore()
                pdfData = db.pdfImage()
                now = datetime.datetime.now()
                if not self.RCJKI.currentFont.mysql:
                    outputPath = os.path.join(
                        self.RCJKI.currentFont.fontPath, "Proofing", user,
                        '%s_%s_%s.pdf' % (date, str(pageIndex).zfill(2), text))
                else:
                    outputPath = os.path.join(
                        mysqlpath,
                        '%s_%s_%s.pdf' % (date, str(pageIndex).zfill(2), text))
                # os.rename(outputPath, outputPath[:-3]+'ai')
                files.makepath(outputPath)
                db.saveImage(outputPath)
                os.rename(outputPath, outputPath[:-3] + "ai")
Esempio n. 11
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")
Esempio n. 12
0
 def drawContent(self, ox, oy, doc, page, parent):
     """We just need to define drawing of the image. The rest of behavior
     for the Image element (including drawing on the background and the frame) 
     is handled by the base Element class.
     """
     # Get the scale of the image, comparing the file size with the size
     # of the image element.
     sx, sy = self.getScale()
     # In drawBot it is not possible to scale the image, so we need to scale
     # the canvas instead. Then also we need to scale the (ox, oy) positions.
     # After drawing, reverse scale the canvas back to 100%
     drawBot.scale(sx, sy)
     drawBot.image(self.path, (ox / sx, oy / sy))
     drawBot.scale(1 / sx, 1 / sy)
Esempio n. 13
0
def feelingSlide(canvasWidth, canvasHeight, polarity):
    db.newPage(canvasWidth, canvasHeight)

    background_fill = polarityBackground(polarity)

    db.fill(*background_fill)
    db.frameDuration(4)
    db.rect(0, 0, canvasWidth, canvasHeight)

    background_images = os.listdir('background_images/')
    background_image_path = 'background_images/' + background_images[(int)(
        len(background_images) * random.random())]
    # https://forum.drawbot.com/topic/180/how-do-i-size-an-image-with-the-imageobject-or-without/4
    srcWidth, srcHeight = db.imageSize(background_image_path)
    dstWidth, dstHeight = canvasWidth - 50, canvasHeight - 50
    factorWidth = dstWidth / srcWidth
    factorHeight = dstHeight / srcHeight
    with db.savedState():
        db.translate(25, 25)
        with db.savedState():
            db.scale(factorWidth, factorHeight)
            db.image(background_image_path, (0, 0))

    dril_feels_text = db.FormattedString()
    dril_feels_text.append("@dril feels",
                           font="Calibri-Bold",
                           fontSize=150,
                           fill=1,
                           align='center',
                           stroke=background_fill,
                           strokeWidth=0.5)
    db.shadow((0, 0), 50, background_fill)
    db.text(dril_feels_text, (canvasWidth / 2, canvasHeight - 300))

    if polarity < -0.1:
        drils_feeling = "angry"
        db.font("LucidaBlackletter", 250)
    elif polarity < 0.25:
        drils_feeling = "neutral"
        db.font("Helvetica", 180)
    else:
        drils_feeling = "happy"
        db.font("Cortado", 250)

    db.fill(1)
    db.shadow((0, 0), 50, background_fill)
    db.text(drils_feeling, (canvasWidth / 2, 250), align='center')
Esempio n. 14
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")
Esempio n. 15
0
    def draw(self, pos):
        x, y = pos
        drawBot.save()
        drawBot.translate(x, y)
        drawBot.scale(self.scale)
        if self.layers['font']:      self.drawFont()
        if self.layers['layer']:     self.drawLayer()
        if self.layers['info']:      self.drawInfo()
        if self.layers['guideline']: self.drawGuideline()
        if self.layers['glyph']:     self.drawGlyph()
        if self.layers['font lib']:  self.drawFontLib()
        if self.layers['kerning']:   self.drawKerning()
        if self.layers['features']:  self.drawFeatures()
        if self.layers['glyph lib']: self.drawGlyphLib()
        if self.layers['anchor']:    self.drawAnchor()
        if self.layers['component']: self.drawComponent()
        if self.layers['image']:     self.drawImage()
        if self.layers['contour']:   self.drawContour()
        if self.layers['point']:     self.drawPoint()
        if self.layers['bPoint']:    self.drawBPoint()
        if self.layers['segment']:   self.drawSegment()

        drawBot.restore()
def draw(txt="a", variations={}, caption=""):
    db.newPage(w * scale, h * scale)
    db.scale(scale)
    db.fill(*BACKCOL)
    db.stroke(None)
    db.rect(0, 0, w, h)
    fs = db.FormattedString(txt,
                            font="Handjet-Regular",
                            fontSize=4600,
                            fontVariations=variations)
    path = db.BezierPath()
    path.text(fs, (w / 2, 1.58 * h), align="center")
    path_optim = path.copy()
    # remove overlaps when drawing the fill
    # but use the original contour when drawing the nodes
    path_optim.removeOverlap()
    path_optim.optimizePath()
    # draw the fill
    db.fill(*TEXTCOL)
    db.drawPath(path_optim)
    # draw nodes
    if path.contours:
        # drawing just the first contour is enough
        for s in path.contours[0]:
            for x, y in s:
                if (x, y) in path.onCurvePoints:
                    db.fill(*NODECOL)
                    db.stroke(*TEXTCOL)
                    db.strokeWidth(1)
                    db.oval(x - 4, y - 4, 8, 8)
    # draw caption
    fs = db.FormattedString(caption,
                            font="AdapterMonoPE-Regular",
                            fontSize=10,
                            fill=TEXTCOL)
    if caption:
        db.text(fs, (w / 2, 40), align="center")
Esempio n. 17
0
import drawBot
drawBot.size(500, 500)
imagePath = "../data/drawBot.pdf"
w, h = drawBot.imageSize(imagePath)
drawBot.scale(250 / w)
drawBot.image(imagePath, (0, 0))
drawBot.image(imagePath, (w, 0), alpha=0.5)
drawBot.image(imagePath, (0, h), alpha=0.25)
drawBot.image(imagePath, (w, h), alpha=0.75)
Esempio n. 18
0
    db.size(*CANVAS)

    glyphs = ['A', 'A', 'B', 'C', 'D', 'E', 'F']

    pig_outline = sh.getGlyphPath(ufo_path, 'A')
    min_x, min_y, max_x, max_y = pig_outline.bounds()
    width = (max_x - min_x)
    height = (max_y - min_y)

    vertical_pigs = math.floor(CANVAS[1] / ((height + MARGIN / 2) * SCALE))
    horizontal_pigs = math.floor(CANVAS[0] / ((width + MARGIN) * SCALE))

    # bottom_margin = (CANVAS[1] - vertical_pigs * ((height + MARGIN / 2) * SCALE)) / 2

    db.save()
    db.scale(SCALE)
    # db.rotate(45)
    # db.translate(CANVAS[0] * 0.8, -CANVAS[1] * 2.5)
    y = -2 * height
    for i in range(vertical_pigs + 10):
        x = -6 * width
        y += height + MARGIN / 2
        for j in range(horizontal_pigs + 30):
            x += width + MARGIN
            db.save()
            if i % 2 == 0:
                db.translate(x - 0.3 * width, y)
            else:
                db.translate(x + 0.3 * width, y)
            pig = sh.getGlyphPath(ufo_path, random.choice(glyphs))
            db.fill(j / 15, i / 20, 0.7, 1)
Esempio n. 19
0
def rotateScale(r, s, center):
    drawBot.rotate(r, center=center)
    drawBot.scale(s, center=center)
Esempio n. 20
0
import drawBot
drawBot.size(250, 250)
imagePath = "http://f.cl.ly/items/1T3x1y372J371p0v1F2Z/drawBot.jpg"
drawBot.scale(250 / 700)
drawBot.image(imagePath, (20, 20))
Esempio n. 21
0
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, 50))
drawBot.qCurveTo((180, 20), (150, 20))

drawBot.fill(1, 0, 0)
drawBot.stroke(0)
drawBot.strokeWidth(10)
drawBot.drawPath()

drawBot.closePath()

drawBot.fill(None)
drawBot.stroke(1)
drawBot.translate(40, 15)
drawBot.scale(0.7)
drawBot.lineCap("round")
drawBot.lineJoin("round")

drawBot.drawPath()