Пример #1
0
    def updateCanvas(self):
        db.newDrawing()
        db.newPage(1200, 740)
        self.draw()

        pdf = db.pdfImage()
        self.w.canvas.setPDFDocument(pdf)
    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)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
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")
Пример #8
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)
Пример #9
0
    def makeInstance(self, axes, gname, glyph):
        nbAxes = maxNbAxes = len(axes)
        # steps = [1, 2]
        # maxNbAxes = max(steps)
        # for nbAxes in steps:

        speeds = [1 for i in range(nbAxes)]
        # LCM = self.ilcm(speeds)
        LCM = 60
        # print(LCM)
        # while ((LCM < 600 or LCM > 1200) or self.checkEqual(speeds)):
        #     speeds = [int(10/nbAxes + random.random()*60/nbAxes) for i in range(nbAxes)]
        #     LCM = self.ilcm(speeds)
        #     print(speeds, LCM, (LCM < 600 or LCM > 1200))

        alpha = 2 * math.pi / maxNbAxes
        ld = [{'Axis': l, 'PreviewValue': 0} for l in axes]
        # glyph.preview.computeDeepComponentsPreview(ld)
        origineGlyph = RGlyph()
        for atomicInstance in glyph.preview():
            atomicInstance = atomicInstance.glyph
            atomicInstance.draw(origineGlyph.getPen())
        # origineGlyph = glyph.preview.variationPreview.copy()
        origineGlyph.name = "interpo"
        db.newDrawing()
        for k in range(nbAxes):
            start = time.time()
            ld = [{
                'Axis': l,
                'PreviewValue': j == k
            } for j, l in enumerate(axes)]
            # glyph.preview.computeDeepComponentsPreview(ld)
            for g in range(LCM):

                H = 700
                W = 700
                db.newPage(W * 2.5, H)
                db.frameDuration(1 / 30)

                db.fill(1)
                db.rect(0, 0, W * 2.5, H)

                r = W / 3
                ainc = 0
                lines = []
                rands = []
                values = []

                for i in range(nbAxes):
                    path = db.BezierPath()
                    path.moveTo((H / 2, W / 2))
                    line = (r * math.sin(ainc), r * math.cos(ainc))
                    path.lineTo((H / 2 + line[0], W / 2 + line[1]))
                    dx = line[0] * .05
                    dy = line[1] * .05
                    path.moveTo((H / 2 + line[0] - dy, W / 2 + line[1] + dx))
                    path.lineTo((H / 2 + line[0] + dy, W / 2 + line[1] - dx))
                    db.stroke(.2)
                    db.strokeWidth(1.5)
                    db.fill(None)
                    db.drawPath(path)
                    ainc += alpha
                    lines.append((line, axes[i]["sourceName"]))
                    # v = getValueForAxeAtFrame(i, g, nbAxes, LCM, speeds[i])
                    # values.append(v)
                    if i == k:
                        rands.append([
                            1000 * abs(
                                math.sin(math.pi *
                                         (speeds[i] * c / LCM + speeds[i])))
                            for c in range(LCM)
                        ])
                    else:
                        rands.append([0 for c in range(LCM)])

                db.fill(1)
                db.oval(H / 2 - H * .01, W / 2 - W * .01, H * .02, W * .02)

                patharea = db.BezierPath()
                patharea.moveTo((H / 2, W / 2))
                patharea.lineTo((H / 2 + lines[0][0][0] * rands[0][g] / 1000,
                                 W / 2 + lines[0][0][1] * rands[0][g] / 1000))
                db.fill(0, 0, 0, .1)
                db.stroke(None)
                for c, (line, lineName) in enumerate(lines):
                    patharea.lineTo((H / 2 + line[0] * rands[c][g] / 1000,
                                     W / 2 + line[1] * rands[c][g] / 1000))
                patharea.lineTo((H / 2 + lines[0][0][0] * rands[0][g] / 1000,
                                 W / 2 + lines[0][0][1] * rands[0][g] / 1000))
                patharea.lineTo((H / 2, W / 2))
                db.drawPath(patharea)

                for c, (line, lineName) in enumerate(lines):
                    db.fill(0)  #1-rands[c]
                    db.stroke(.2)
                    db.strokeWidth(1)
                    db.oval(H / 2 + line[0] * rands[c][g] / 1000 - 4.5,
                            W / 2 + line[1] * rands[c][g] / 1000 - 4.5, 9, 9)
                    db.fill(.2)
                    ftxt = db.FormattedString(txt=lineName,
                                              font="GrtskZetta-Light",
                                              fontSize=14,
                                              align="center")
                    db.textBox(ftxt, (H / 2 + line[0] * 1.3 - 30,
                                      W / 2 + line[1] * 1.3 - 10, 60, 20))

                #########
                db.save()
                # ld = []
                # for j, l in enumerate(axes):
                #     ld.append({'Axis': l, 'PreviewValue':rands[j][g]/1000})

                # # d = {l:rands[j][g]/1000 for (j, l) in enumerate(axes)}

                # # glyph = interpolation(NewFont().newGlyph('temp'), ufo[gname], layersInfo = d)
                # # glyph = self.RCJKI.currentFont.get(gname)
                # glyph.preview.computeDeepComponentsPreview(ld)
                #########
                # print(glyph)
                db.translate(W * 1.3, H * .15)
                db.scale(.7 * H / 1000)
                db.stroke(.5)
                db.fill(None)
                db.rect(0, 0, 1000, 1000)
                db.fill(0)
                db.stroke(None)
                db.save()
                db.translate(0, 120)

                ratioX = ratioY = (rands[k][g]) / 1000
                resultGlyph = RGlyph()
                locations = {}
                for e in ld:
                    locations[e["Axis"]["sourceName"]] = e["PreviewValue"]
                for c in glyph.preview(locations):
                    c = c.glyph
                    c.draw(resultGlyph.getPen())
                interpoGlyph = interpolation.interpol_glyph_glyph_ratioX_ratioY_scaleX_scaleY(
                    origineGlyph, resultGlyph, ratioX, ratioY, 1, 1,
                    NewFont(showUI=False))
                db.drawGlyph(interpoGlyph)

                #         for aes in glyph.preview:
                #             # axis2layerName = {axisName:layerName for axisName, layerName in self.RCJKI.currentFont[aes['name']].lib['robocjk.atomicElement.glyphVariations'].items()}

                #             # lInfos = {axis2layerName[axisName]:v for axisName, v in aes['coord'].items()}
                # #            print(ae['coord'])
                #             for ae in aes.values():
                #                 glyph = ae[0]
                #                 print(glyph)
                #                 db.save()
                #                 self._drawGlyph(glyph)
                #                 db.restore()
                db.restore()
                db.restore()
                caption = db.FormattedString(txt='%s-axis' % (nbAxes),
                                             font="GrtskMega-Medium",
                                             fontSize=14,
                                             align="left")
                db.textBox(caption, (10, 10, W - 20, 20))

            stop = time.time()
            print(stop - start, "seconde for axis")

        pdfData = db.pdfImage()
Пример #10
0
    def draw(self):
        user = self.RCJKI.gitUserName
        now = datetime.datetime.now()
        date = "%s%s%s_%s%s%s" % (now.year, str(
            now.month).zfill(2), str(now.day).zfill(2), str(
                now.hour).zfill(2), str(now.minute).zfill(2), str(
                    now.second).zfill(2))

        if self.RCJKI.currentFont.mysql:
            mysqlpath = vanilla.dialogs.getFolder()[0]

        def drawDesignFrame():
            for e in self.designFrameViewer.elements:
                glyph, color, type = e
                if type == 'stroke':
                    db.stroke(*color)
                    db.fill(None)
                else:
                    db.stroke(None)
                    db.fill(*color)
                db.drawGlyph(glyph)

        for pageIndex, page in enumerate(self.pages):
            db.newDrawing()
            self.designFrameViewer.draw()

            glyphsVariations = {}
            # light = []
            db.newPage(FRAMEX, FRAMEY)
            db.textBox(user, (0, FRAMEY - 85, FRAMEX, 55), align='center')
            db.textBox('%s-Overlay' % self.RCJKI.currentFont.fontName,
                       (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)
            for i, glyph in enumerate(page):
                name = glyph.name
                try:
                    for variation in self.RCJKI.currentFont.fontVariations:
                        glyph1 = glyph
                        if variation not in glyphsVariations.keys():
                            glyphsVariations[variation] = []
                        resultGlyph = []
                        for c in glyph1.preview({variation: 1}):
                            c = c.glyph
                            c.markColor = glyph1.markColor
                            c.name = glyph1.name
                            resultGlyph.append(c)
                        glyphsVariations[variation].append(resultGlyph)

                        drawDesignFrame()
                        if glyph1.markColor:
                            db.fill(*glyph1.markColor)
                        else:
                            db.fill(*INPROGRESS)
                        db.rect(0, 900, 250, 100)
                        db.fill(0, 0, 0, 1)
                        db.stroke(None)
                        db.textBox(name, (0, 900, 1000, 100), align="center")

                        db.fill(1, 1, 1, 1)
                        db.stroke(0, 0, 0, 1)
                        db.strokeWidth(1)
                        for c in resultGlyph:
                            db.drawGlyph(c)
                        variation = "normal"
                        if variation not in glyphsVariations.keys():
                            glyphsVariations[variation] = []
                        resultGlyph = []
                        for c in glyph1.preview({variation: 0}):
                            c = c.glyph
                            c.markColor = glyph1.markColor
                            c.name = glyph1.name
                            resultGlyph.append(c)
                        glyphsVariations[variation].append(resultGlyph)
                        for c in resultGlyph:
                            db.drawGlyph(c)

                        if (i + 1) % 4:
                            db.translate(1000, 0)
                        else:
                            db.translate(-1000 * 3, -1200)
                except Exception as e:
                    raise e
            db.restore()

            pdfData = db.pdfImage()
            if not self.RCJKI.currentFont.mysql:
                outputPath = os.path.join(
                    self.RCJKI.currentFont.fontPath, "Proofing", user,
                    '%s_%s_%s-%s.pdf' %
                    (date, str(pageIndex).zfill(2),
                     self.RCJKI.currentFont.fontName, "Overlay"))
            else:
                outputPath = os.path.join(
                    mysqlpath, '%s_%s_%s-%s.pdf' %
                    (date, str(pageIndex).zfill(2),
                     self.RCJKI.currentFont.fontName, "Overlay"))
            files.makepath(outputPath)
            db.saveImage(outputPath)
            os.rename(outputPath, outputPath[:-3] + "ai")

            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")

            for variations, weights in glyphsVariations.items():
                drawWeight(
                    weights,
                    '%s-%s' % (self.RCJKI.currentFont.fontName, variations))

            if not self.RCJKI.currentFont.mysql:
                textPath = os.path.join(
                    self.RCJKI.currentFont.fontPath, "Proofing", user,
                    '%s_%s_text.txt' % (date, str(pageIndex).zfill(2)))
            else:
                textPath = os.path.join(
                    mysqlpath,
                    '%s_%s_text.txt' % (date, str(pageIndex).zfill(2)))
            files.makepath(textPath)
            with open(textPath, 'w', encoding='utf-8') as file:
                file.write("".join([chr(int(x.name[3:], 16)) for x in page]))