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)
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
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, 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()
Ejemplo n.º 4
0
 def test_instructionStack(self):
     expected = [
         "reset None", "newPage 200 200", "save",
         "clipPath moveTo 5.0 5.0 lineTo 15.0 5.0 lineTo 15.0 15.0 lineTo 5.0 15.0 closePath",
         "restore", "image Image Object 10 10 0.5 None",
         "blendMode saturation", "transform 1 0 0 1 10 10",
         "drawPath moveTo 10.0 10.0 lineTo 110.0 10.0 lineTo 110.0 110.0 lineTo 10.0 110.0 closePath",
         "textBox foo bar 72.48291015625 84.0 55.0341796875 26.0 center",
         "frameDuration 10", "saveImage * {'myExtraAgrument': True}"
     ]
     with StdOutCollector() as output:
         import drawBot
         drawBot.newDrawing()
         drawBot.size(200, 200)
         drawBot.save()
         path = drawBot.BezierPath()
         path.rect(5, 5, 10, 10)
         drawBot.clipPath(path)
         drawBot.restore()
         im = drawBot.ImageObject()
         with im:
             drawBot.size(20, 20)
             drawBot.rect(5, 5, 10, 10)
         drawBot.image(im, (10, 10), alpha=.5)
         drawBot.blendMode("saturation")
         drawBot.translate(10, 10)
         drawBot.rect(10, 10, 100, 100)
         drawBot.text("foo bar", (100, 100), align="center")
         drawBot.frameDuration(10)
         drawBot.saveImage("*", myExtraAgrument=True)
         drawBot.endDrawing()
     self.assertEqual(output.lines(), expected)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
def kerningHeatMap(kerning, glyphNames, isFirstVertical):
    corrections = [kerning[pair] for pair in product(glyphNames, repeat=2)]
    corrections.sort()
    minCorrection, maxCorrection = abs(corrections[0]), abs(corrections[-1])
    if minCorrection < maxCorrection:
        reference = maxCorrection
    else:
        reference = minCorrection

    for jj, glyphY in enumerate(glyphNames):

        # vertical captions
        with savedState():
            translate(-CELL_SIZE, jj * CELL_SIZE)
            typeQualities()
            text(f'{glyphY}', (CELL_SIZE * .5, CELL_SIZE * .2), align='center')

        # drawing the row
        for ii, glyphX in enumerate(glyphNames):
            pair = (glyphY, glyphX) if isFirstVertical else (glyphX, glyphY)
            correction = kerning[pair]

            with savedState():
                translate(ii * CELL_SIZE, jj * CELL_SIZE)

                # horizontal captions
                if jj == 0:
                    typeQualities()
                    text(f'{glyphX}', (CELL_SIZE * .5, -CELL_SIZE * .8),
                         align='center')

                # draw the cells
                factor = .5 + .5 * abs(correction) / reference
                if correction == 0:
                    rectClr = BLACK
                    typeClr = WHITE
                elif correction < 0:
                    rectClr = lerpRGB(WHITE, RED, factor)
                    typeClr = WHITE
                else:
                    rectClr = lerpRGB(WHITE, GREEN, factor)
                    typeClr = BLACK
                shapeQualities(rectClr)
                rect(0, 0, CELL_SIZE, CELL_SIZE)

                if correction != 0:
                    corrStr = f'{abs(correction)}'

                    # just a check for body size
                    if textSize(corrStr)[0] > CELL_SIZE:
                        print(f'[WARNING] {pair} text is too big!')

                    typeQualities(clr=typeClr)
                    text(corrStr, (CELL_SIZE * .5, CELL_SIZE * .2),
                         align='center')
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def startNewPage(pageWidth, pageHeight, margin, header):
    db.newPage(pageWidth, pageHeight)
    # Draw the header
    with db.savedState():
        fs = db.FormattedString("%s Glyph Overview\n" % HEADER_STYLENAME,
                                font="Tilt Neon",
                                fontSize=15)
        fs.append("by Andy Clymer\n%s" % HEADER_URL,
                  font="Tilt Neon",
                  fontSize=8)
        db.translate(margin, db.height() - header - margin)
        db.textBox(fs, (0, 0, db.width() - (margin * 2), header))
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
def GoldFactory(glyph, font=None, offset=10):
    glyph = RGlyph(glyph)
    box = glyph.bounds if version >= "3.0" else glyph.box
    if box is None:
        return None
    margin = offset * 2
    minx, miny, maxx, maxy = box
    w = maxx - minx + margin * 2
    h = maxy - miny + margin * 2

    drawBot.newDrawing()
    drawBot.newPage(w, h)
    drawBot.translate(-minx + margin, -miny + margin)

    if font is None:
        font = glyph.font if version >= "3.0" else glyph.getParent()

    glyphSet = font

    g = glyph.copy()

    for component in reversed(g.components):
        if version >= "3.0":
            decomposePen = DecomposePointPen(glyphSet, g.getPointPen())
        else:
            decomposePen = DecomposePointPen(glyphSet, g.getPointPen(), [1, 0, 0, 1, 0, 0])
        component.drawPoints(decomposePen)
        g.removeComponent(component)

    g.removeOverlap()

    minx, miny, maxx, maxy = g.bounds if version >= "3.0" else g.box

    setGoldGradient(minx, miny, maxx, maxy)
    drawBot.drawGlyph(g)

    pen = OutlinePen(glyphSet, offset=offset)
    g.draw(pen)
    pen.drawSettings(drawInner=True, drawOuter=True)

    dest = RGlyph()
    pen.drawPoints(dest.getPointPen())

    setGoldGradient(minx, miny, maxx, maxy, 4)
    drawBot.drawGlyph(dest)

    pdf = drawBot.pdfImage()
    page = pdf.pageAtIndex_(0)
    image = NSImage.alloc().initWithData_(page.dataRepresentation())
    return image, (minx-margin, miny-margin)
Ejemplo n.º 13
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()
Ejemplo n.º 14
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')
Ejemplo n.º 15
0
    def prerenderDrawBot(self):

        ctx.newPage(self.width, self.height)
        if self.color is not None:
            color = hexToRGB(self.color) if type(
                self.color) is str and self.color.startswith(
                    '#') else self.color
            ctx.fill(*color)
            ctx.rect(0, 0, self.width, self.height)

        ctx.blendMode(self.blendMode)
        ctx.save()

        if self.centered:
            centerX = self.width / 2  # * self.pixelRatio
            centerY = self.height / 2  # * self.pixelRatio
            ctx.translate(centerX, centerY)
Ejemplo n.º 16
0
 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()
Ejemplo n.º 17
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))
Ejemplo n.º 18
0
 def drawAnchor(self):
     r = self.anchorSize * 0.5
     color = self.colorScheme.colorsRGB['anchor']
     drawBot.save()
     drawBot.strokeWidth(self.anchorStrokeWidth)
     drawBot.stroke(*color)
     drawBot.fill(None)
     for char in self.txt:
         uni = ord(char)
         glyphName = UV2AGL.get(uni)
         glyph = self.font[glyphName]
         if len(glyph.anchors):
             for anchor in glyph.anchors:
                 x, y = anchor.x, anchor.y
                 drawBot.oval(x-r, y-r, r*2, r*2)
                 drawBot.line((x-r, anchor.y), (x+r, anchor.y))
                 drawBot.line((anchor.x, y-r), (anchor.x, y+r))
         drawBot.translate(glyph.width, 0)
     drawBot.restore()
Ejemplo n.º 19
0
 def draw(pen, state, data):
     if state == 0:
         DrawBotPen(pen, rect).draw(scale=scale)
     elif state == -1:
         imgf = pen.data.get("imgf")
         if imgf:
             im = db.ImageObject()
             im.lockFocus()
             db.size(rect.w+300, rect.h+300)
             db.translate(150, 150)
             db.scale(scale)
             pen.data["im"] = im
     elif state == 1:
         imgf = pen.data.get("imgf")
         im = pen.data.get("im")
         if imgf and im:
             im.unlockFocus()
             imgf(im)
             x, y = im.offset()
             db.translate(-150, -150)
             db.image(im, (x, y))
Ejemplo n.º 20
0
    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()
Ejemplo n.º 21
0
    def drawBPoint(self):

        r1 = self.bPointSize * 0.5
        r2 = self.pointSize * 0.5

        color = self.colorScheme.colorsRGB['bPoint']
        drawBot.save()
        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)

            for c in glyph.contours:
                for pt in c.bPoints:
                    x, y = pt.anchor
                    xIn,  yIn  = pt.bcpIn
                    xOut, yOut = pt.bcpOut

                    drawBot.fill(*color)
                    drawBot.stroke(None)
                    drawBot.oval(x - r1, y - r1, r1 * 2, r1 * 2)
                    if not self.layers['point']:
                        drawBot.oval(x + xIn - r2, y + yIn - r2, r2 * 2, r2 * 2)
                        drawBot.oval(x + xOut - r2, y + yOut - r2, r2 * 2, r2 * 2)

                    drawBot.fill(None)
                    drawBot.stroke(*color)
                    drawBot.strokeWidth(5)
                    drawBot.line((x, y), (x + xIn, y + yIn))
                    drawBot.line((x, y), (x + xOut, y + yOut))

            drawBot.translate(glyph.width, 0)
        drawBot.restore()
Ejemplo n.º 22
0
    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()
Ejemplo n.º 23
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()
Ejemplo n.º 24
0
    def drawPoint(self):
        r = self.pointSize * 0.5
        color = self.colorScheme.colorsRGB['point']
        drawBot.save()
        drawBot.fill(*color)
        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)

            for c in glyph.contours:
                for pt in c.points:
                    x, y = pt.x, pt.y
                    drawBot.oval(x-r, y-r, r*2, r*2)
            drawBot.translate(glyph.width, 0)
        drawBot.restore()
Ejemplo n.º 25
0
 def test_instructionStack(self):
     expected = [
         "reset None",
         "newPage 200 200",
         "save",
         "clipPath moveTo 5.0 5.0 lineTo 15.0 5.0 lineTo 15.0 15.0 lineTo 5.0 15.0 closePath",
         "restore",
         "image Image Object 10 10 0.5 None",
         "blendMode saturation",
         "transform 1 0 0 1 10 10",
         "drawPath moveTo 10.0 10.0 lineTo 110.0 10.0 lineTo 110.0 110.0 lineTo 10.0 110.0 closePath",
         "textBox foo bar 82.48291015625 84.0 35.0341796875 26.0 center",
         "frameDuration 10",
         "saveImage * {'myExtraAgrument': True}"
     ]
     with StdOutCollector() as output:
         import drawBot
         drawBot.newDrawing()
         drawBot.size(200, 200)
         drawBot.save()
         path = drawBot.BezierPath()
         path.rect(5, 5, 10, 10)
         drawBot.clipPath(path)
         drawBot.restore()
         im = drawBot.ImageObject()
         with im:
             drawBot.size(20, 20)
             drawBot.rect(5, 5, 10, 10)
         drawBot.image(im, (10, 10), alpha=.5)
         drawBot.blendMode("saturation")
         drawBot.translate(10, 10)
         drawBot.rect(10, 10, 100, 100)
         drawBot.text("foo bar", (100, 100), align="center")
         drawBot.frameDuration(10)
         drawBot.saveImage("*", myExtraAgrument=True)
         drawBot.endDrawing()
     self.assertEqual(output.lines(), expected)
Ejemplo n.º 26
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")
Ejemplo n.º 27
0
def draw_block(box_size, box_depth, rows, columns, layers):

    box = make_box(box_size, box_depth)

    for column in range(columns):
        db.save()
        db.translate(-column * box_size[0], 0)
        db.drawPath(box)
        for row in range(rows):
            db.save()
            db.translate(0, row * box_size[1])
            db.drawPath(box)
            for layer in range(layers - 1):
                db.translate(math.fabs(box_depth[0]), -math.fabs(box_depth[1]))
                db.drawPath(box)
            db.restore()
        db.restore()
Ejemplo n.º 28
0
import drawBot
drawBot.size(200, 200)
for i in range(14):
    f = i / 14.0
    drawBot.fill(1-f, 1 - f, 0)
    drawBot.oval(10, 10, 50, 50)
    drawBot.translate(10, 10)
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
0
import drawBot
drawBot.size(200, 200)
for i in range(14):
    f = i / 14.0
    drawBot.fill(1 - f, 1 - f, 0)
    drawBot.oval(10, 10, 50, 50)
    drawBot.translate(10, 10)
Ejemplo n.º 31
0
# from the project folder
from HSLdonut import hslDonut

### Variables
discs = 16
rings = 22
ringThickness = 5
holeRadius = 45

### Instructions
if __name__ == '__main__':
    newDrawing()
    newPage(952, 488)

    translate(width() * .27, height() * .25)
    save()
    for eachDisc in range(discs):
        with savedState():
            scale(1, .65)
            hslDonut(rings,
                     ringThickness,
                     holeRadius,
                     fixedValue=eachDisc / (discs - 1),
                     isLuminosityConst=True,
                     captions=False)
        translate(0, 16)
    restore()

    translate(width() * .44, 0)
    save()
Ejemplo n.º 32
0
import drawBot
drawBot.size(300, 300)
with drawBot.savedState():
    drawBot.fill(1, 0, 0)
    drawBot.translate(150, 150)
    drawBot.rect(0, 0, 100, 100)
    with drawBot.savedState():
        drawBot.rotate(45)
        drawBot.fill(0, 1, 0)
        drawBot.rect(0, 0, 100, 100)
drawBot.rect(0, 0, 100, 100)
Ejemplo n.º 33
0
    margin = 20
    
    vertical_pigs = math.floor(CANVAS[1] / ((height + margin / 2) * scale))
    horizontal_pigs = math.floor(CANVAS[0] / ((width + margin) * scale))
    
#    for k in range(FRAMES):
        # db.newPage(*CANVAS)
        # db.frameDuration(1/FRAMES)
    db.save()
    db.scale(scale)
    y = -height
    for i in range(vertical_pigs + 2):
        x = -width
        for j in range(horizontal_pigs + 2):
            db.save()
            db.translate(x, y)
            pig = sh.getGlyphPath(ufo_path, random.choice(glyphs))
            # db.fill(j / random.randint(10, 15), i / random.randint(20, 30), random.uniform(0.6, 0.8), 1)
            db.fill(j / 15, i / 20, 0.7, 1)
            db.drawPath(pig)
            db.restore()
            x += width + margin
        y += height
    db.restore()

    db.fill(1)

    db.font('Cooper Std Black', 150)
    db.text('2019', (60, 200))

    db.saveImage('~/Downloads/pig.gif', imageResolution=300)
Ejemplo n.º 34
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()