Exemplo n.º 1
0
    def Composite(pens, rect, save_to, scale=2):
        db.newDrawing()
        rect = rect.scale(scale)
        db.newPage(rect.w, rect.h)

        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))
        
        if isinstance(pens, DATPen):
            pens = [pens]
        for dps in pens:
            dps.walk(draw)
        
        db.saveImage(str(save_to))
        db.endDrawing()
Exemplo n.º 2
0
def makeFlash(s, w, h, px, py, color1=None, color2=None, flashSpeed=4):
    if color1 is None:
        r1, g1, b1 = 1, 0, 0
    else:
        r1, g1, b1 = color1
    if color2 is None:
        r2, g2, b2 = 0.2, 0, 0
    else:
        r2, g2, b2 = color2
    for n in range(flashSpeed):
        newPage(w, h)
        fill(0)
        rect(0, 0, w, h)
        drawString(s, px, py, 'PropSingleBold', (r1, g1, b1, 0.2))
        drawString(s, px, py, 'PropSingleMedium', (r1, g1, b1, 0.5))
        if HIGHLIGHT:
            drawString(s, px, py, 'PropSingle',
                       (r1 * 0.9, g1 * 0.9, b1 * 0.9, 1))
            drawString(s, px - 1, py + 1, 'PropSingleLight', (r1, g1, b1, 1))
        else:
            drawString(s, px, py, 'PropSingle', (r1, g1, b1, 1))

    for n in range(flashSpeed):
        newPage(w, h)
        fill(0)
        rect(0, 0, w, h)
        drawString(s, px, py, 'PropSingleBold', (r2, g2, b2, 0.2))
        drawString(s, px, py, 'PropSingleMedium', (r2, g2, b2, 0.5))
        if HIGHLIGHT:
            drawString(s, px, py, 'PropSingle',
                       (r2 * 0.9, g2 * 0.9, b2 * 0.9, 1))
            drawString(s, px - 1, py + 1, 'PropSingleLight', (r2, g2, b2, 1))
        else:
            drawString(s, px, py, 'PropSingle', (r2, g2, b2, 1))
    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)
Exemplo n.º 4
0
    def updateCanvas(self):
        db.newDrawing()
        db.newPage(1200, 740)
        self.draw()

        pdf = db.pdfImage()
        self.w.canvas.setPDFDocument(pdf)
Exemplo n.º 5
0
 def test_newPage_empty_implicit_first_page(self):
     drawBot.newDrawing()
     drawBot.rect(100, 100, 200, 200)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 6
0
    def pageSetup(self):
        drawBot.newDrawing()
        drawBot.newPage("LetterLandscape")
        
        pageWidth = drawBot.width()
        pageHeight = drawBot.height()
        
        #drawBot.fill(0,0,0, 0.5)
        drawBot.stroke(0,0,0,.5)
        drawBot.strokeWidth(0.5)
        
        #this needs major clean up
        drawBot.line((margin, pageHeight-margin), (pageWidth-dpi, pageHeight-margin)) #xHeight line
        drawBot.line((margin, pageHeight-margin-self.xHeightTarget), (pageWidth-dpi, pageHeight-margin-self.xHeightTarget)) #baseline
        
        drawBot.line((margin, pageHeight-margin-(2.5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-(2.5*self.xHeightTarget))) #xHeight line
        drawBot.line((margin, pageHeight-margin-self.xHeightTarget-(2.5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-self.xHeightTarget-(2.5*self.xHeightTarget))) #baseline
        
        drawBot.line((margin, pageHeight-margin-(5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-(5*self.xHeightTarget))) #xHeight line
        drawBot.line((margin, pageHeight-margin-self.xHeightTarget-(5*self.xHeightTarget)), (pageWidth-dpi, pageHeight-margin-self.xHeightTarget-(5*self.xHeightTarget))) #baseline

        #drawBot.rect(margin, pageHeight-margin, pageWidth-dpi, -self.xHeightTarget)
        
        pdf = drawBot.pdfImage()
        # set the pdf data in the canvas
        self.w.canvas.setPDFDocument(pdf)
Exemplo n.º 7
0
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.')
Exemplo n.º 8
0
 def test_newPage_following(self):
     drawBot.newDrawing()
     drawBot.size(400, 500)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 400)
     self.assertEqual(drawBot.height(), 500)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 9
0
 def test_newPage_following(self):
     drawBot.newDrawing()
     drawBot.size(400, 500)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 400)
     self.assertEqual(drawBot.height(), 500)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 10
0
 def makeTestICNSDrawing(self, formats):
     drawBot.newDrawing()
     for i, size in enumerate(formats):
         drawBot.newPage(size, size)
         f = i / (len(formats) + 1)
         drawBot.fill(f, f, 1 - f)
         drawBot.rect(0, 0, size, size)
Exemplo n.º 11
0
 def test_newPage_empty_implicit_first_page(self):
     drawBot.newDrawing()
     drawBot.rect(100, 100, 200, 200)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 12
0
    def export(self, path):
        """Draw a page and export the document into the _export folder.
        Note that in this version, we still generate the document page
        just before it is exported. Not Page instances are stored in the 
        Document yet.

        >>> doc = Document()
        >>> doc.export('_export/Document-export.jpg') # Exporting the JPG
        """
        # Make sure that the _export folder exists, as it does not standard
        # dowload from Github, nor it is committed to Github.
        if path.startswith(EXPORT_DIR) and not os.path.exists(EXPORT_DIR):
            os.mkdir(EXPORT_DIR)
        # Now let DrawBot do its work, creating the page canvas, filling it
        # black, add the title text and then saving it.
        drawBot.newPage(self.w, self.h)
        # For now to have something visible, draw a gray rectangle filling the page.
        drawBot.fill(0.2)  # Set fill color at 20% dark gray.
        drawBot.rect(0, 0, self.w,
                     self.h)  # Draw the rectangle for the entire page.
        # Create a Formatted String for white text with the specified font/fontSize.
        fs = drawBot.FormattedString('My specimen',
                                     font='Georgia',
                                     fontSize=80,
                                     fill=1)
        # Draw the FormattedString on this fixed position: x from left and y from top.
        drawBot.text(fs, (50, self.h - 100))
        # Save the drawn DrawBot page into the _export folder, using `path` as file name.
        # File in the _export folder are ignored by Git, so they don't upload.
        drawBot.saveImage(path)
Exemplo n.º 13
0
 def _initPage(self, fontStyles):
     db.newPage('A3Landscape')
     db.fontSize(BODY_SIZE_TEXT)
     quota = db.height() - PDF_MARGIN
     self._drawHeader(quota, fontStyles)
     db.font('LucidaGrande')
     quota -= TAB_LINE_HEIGHT * 2
     return quota
Exemplo n.º 14
0
def page_with_lines(width, height, x_lines, y_lines, mult, dur, color=False):
    drawBot.newPage(width*mult, height*mult)
    drawBot.frameDuration(dur)
    drawBot.fill(1, 1, 1)
    drawBot.rect(0, 0, width*mult, height*mult)
    if color:
        draw_colors(x_lines, y_lines, width, height, mult)
    draw_lines(x_lines, y_lines, mult)
Exemplo n.º 15
0
 def test_font_install(self):
     fontPath = os.path.join(testDataDir, "MutatorSans.ttf")
     drawBot.newDrawing()
     drawBot.newPage()
     postscriptName = drawBot.font(fontPath)
     self.assertEqual(postscriptName, "MutatorMathTest-LightCondensed")
     variations = drawBot.listFontVariations()
     self.assertEqual(variations, {'wdth': {'name': 'Width', 'minValue': 0.0, 'maxValue': 1000.0, 'defaultValue': 0.0}, 'wght': {'name': 'Weight', 'minValue': 0.0, 'maxValue': 1000.0, 'defaultValue': 0.0}})
Exemplo n.º 16
0
 def __init__(self):
     drawBot.newDrawing()
     # A3, TODO: switch to A2.
     drawBot.newPage(1190, 842)
     self.stepIntoArena()
     self.juggle()
     path = '/Users/michiel/Desktop/circus.pdf'
     drawBot.saveImage(path)
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
 def test_linkURL_svg(self):
     expectedPath = os.path.join(testDataDir, "expected_svgLinkURL.svg")
     drawBot.newDrawing()
     drawBot.newPage(200, 200)
     drawBot.rect(10, 10, 20, 20)
     drawBot.linkURL("http://drawbot.com", (10, 10, 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))
Exemplo n.º 19
0
    def draw(self, sender):

        db.newDrawing()
        db.newPage(300, 300)
        fill(random(), random(), random())
        db.rect(0, 0, 50, 50)

        self.pdf = db.pdfImage()
        self.w.drawView.setPDFDocument(self.pdf)
Exemplo n.º 20
0
 def test_formattedStringURL_svg(self):
     expectedPath = os.path.join(testDataDir, "expected_formattedStringURL.svg")
     drawBot.newDrawing()
     drawBot.newPage(200, 200)
     drawBot.underline("single")
     drawBot.url("http://drawbot.com")
     drawBot.text("foo", (10, 10))
     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))
Exemplo n.º 21
0
 def test_export_svg_fallbackFont(self):
     expectedPath = os.path.join(testDataDir, "expected_svgSaveFallback.svg")
     drawBot.newDrawing()
     drawBot.newPage(100, 100)
     drawBot.fallbackFont("Courier")
     drawBot.font("Times")
     drawBot.text("a", (10, 10))
     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))
Exemplo n.º 22
0
def drawProof(proofSet, postscriptFontName):
    txt = '\n'.join(proofSet)
    while txt:
        newPage(PAGE_FORMAT)
        fill(0)
        if fileName == './txt/paragraph.txt':
            txt = drawTwoColumnsLayout(txt, postscriptFontName)
        else:
            txt = drawOneColumnLayout(txt, postscriptFontName)
        drawHeaderFooter(postscriptFontName, fileName)
Exemplo n.º 23
0
 def makeTestAnimation(self, numFrames=25, pageWidth=500, pageHeight=500):
     randomSeed(0)
     drawBot.newDrawing()
     for i in range(numFrames):
         drawBot.newPage(pageWidth, pageHeight)
         drawBot.frameDuration(1/25)
         drawBot.fill(1)
         drawBot.rect(0, 0, pageWidth, pageHeight)
         drawBot.fill(0)
         drawBot.rect(random.randint(0, 100), random.randint(0, 100), 400, 400)
Exemplo n.º 24
0
    def newPage(self, w, h):
        """Create a new page canvas in the context. Convert the (w, h)
        units to points before passing on.

        >>> from pagebotnano.toolbox.units import pt, mm
        >>> context = DrawBotContext()
        >>> page = context.newPage(400, 500)
        >>> context.newPage(pt(400), mm(200))
        """
        drawBot.newPage(upt(w), upt(h))
Exemplo n.º 25
0
    def drawPages(self, pageSelection=None):
        u"""Draw the selected pages. pageSelection is an optional set of y-pageNumbers to draw."""
        doc = self.parent

        w, h, _ = doc.getMaxPageSizes(pageSelection)
        w2 = 2 * w  # Make spread width
        for pn, pages in doc.getSortedPages():
            #if pageSelection is not None and not page.y in pageSelection:
            #    continue
            # Create a new DrawBot viewport page to draw template + page, if not already done.
            # In case the document is oversized, then make all pages the size of the document, so the
            # pages can draw their crop-marks. Otherwise make DrawBot pages of the size of each page.
            # Size depends on the size of the larges pages + optional decument padding.
            page = pages[
                0]  # TODO: Make it work if there as multiple pages on the same page number.
            pw, ph = w, h  # Copy from main (w, h), since they may be altered.
            if self.pl > self.MIN_PADDING and self.pt > self.MIN_PADDING and self.pb > self.MIN_PADDING and self.pr > self.MIN_PADDING:
                pw += self.pl + self.pr
                ph += self.pt + self.pb
                if self.originTop:
                    origin = self.pl, self.pt, 0
                else:
                    origin = self.pl, self.pb, 0
            else:
                pw = page.w  # No padding defined, follow the size of the page.
                ph = page.h
                origin = (0, 0, 0)
            pw2 = 2 * pw

            if (pn % 2 == 0):  # Is even?
                newPage(
                    pw2, ph
                )  #  Make page in DrawBot of self size, actual page may be smaller if showing cropmarks.
                # View may have defined a background
                if self.style.get('fill') is not None:
                    setFillColor(self.style['fill'])
                    rect(0, 0, pw2, ph)
            else:  # Odd, shift origin to right
                origin = origin[0] + pw, origin[1], origin[2]

            if self.drawBefore is not None:  # Call if defined
                self.drawBefore(page, origin, self)

            self.drawPageFrame(page, origin)

            # Use the (docW, docH) as offset, in case cropmarks need to be displayed.
            page.draw(origin, self)

            if self.drawAfter is not None:  # Call if defined
                self.drawAfter(page, origin, self)

            # Self.infoElements now may have collected elements needed info to be drawn, after all drawing is done.
            # So the info boxes don't get covered by regular page content.
            for e in self.elementsNeedingInfo.values():
                self._drawElementsNeedingInfo()
Exemplo n.º 26
0
 def Composite1(pens, rect, save_to, paginate=False, scale=2):
     db.newDrawing()
     rect = rect.scale(scale)
     if not paginate:
         db.newPage(rect.w, rect.h)
     for pen in DrawBotPen.FindPens(pens):
         if paginate:
             db.newPage(rect.w, rect.h)
         DrawBotPen(pen, rect).draw(scale=scale)
     db.saveImage(str(save_to))
     db.endDrawing()
Exemplo n.º 27
0
def makeRunningLeds(s, w, h, px, py, speed=1):
    newPage(w, h)
    fill(0)
    rect(0, 0, w, h)
    drawString(s, px, py, 'PropSingleBoldItalic', (0.3, 0, 0, 1))
    drawString(s, px, py, 'PropSingleMediumItalic', (0.6, 0.0, 0, 1))
    if HIGHLIGHT:
        drawString(s, px, py, 'PropSingleItalic', (0.8, 0, 0, 1))
        drawString(s, px - 1, py + 1, 'PropSingleLightItalic', (1, 0, 0, 1))
    else:
        drawString(s, px, py, 'PropSingleItalic', (1, 0, 0, 1))
Exemplo n.º 28
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)
Exemplo n.º 29
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))
Exemplo n.º 30
0
def draw_board(board: array) -> array:
    n = board.shape[0]
    square_size = BOARD_SIZE / n
    draw.newPage(BOARD_SIZE, BOARD_SIZE)
    draw.frameDuration(FRAME_DURATION)
    for i in range(n):
        for j in range(n):
            if board[i,j] == 0:
                draw.fill(0, 0, 0, 1)
            else:
                draw.fill(255, 255, 255, 1)
            draw.rect(square_size * j, square_size * i, square_size, square_size)
Exemplo n.º 31
0
    def build(self, doc):
        """Draw the page and recursively make the child elements to draw 
        themselves in DrawBot. The build is “broadcast” to all the elements 
        on the page.

        """
        drawBot.newPage(self.w, self.h) # Create a new DrawBot page.
        for element in self.elements:
            # Passing on doc and this page in case an element needs more info.
            # Since this bottom-left corner of the page is the origin for position,
            # set it to (0, 0)
            element.build(x=0, y=0, doc=doc, page=self, parent=self) 
Exemplo n.º 32
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")
Exemplo n.º 33
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")
Exemplo n.º 34
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)
Exemplo n.º 35
0
 def test_newPage_empty_multiple(self):
     drawBot.newDrawing()
     drawBot.newPage()
     drawBot.newPage()
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 3)