Beispiel #1
0
    def generatePML(self, page, pageNr, cfg):
        fl = 0

        if self.isBold:
            fl |= pml.BOLD

        if self.isItalic:
            fl |= pml.ITALIC

        if self.isUnderlined:
            fl |= pml.UNDERLINED

        if self.align == util.ALIGN_LEFT:
            x = cfg.marginLeft
        elif self.align == util.ALIGN_CENTER:
            x = (cfg.marginLeft + (cfg.paperWidth - cfg.marginRight)) / 2.0
        else:
            x = cfg.paperWidth - cfg.marginRight

        fs = cfg.fontSize

        if self.xoff != 0:
            x += util.getTextWidth(" ", pml.COURIER, fs) * self.xoff

        y = cfg.marginTop + (self.line - 1) * util.getTextHeight(fs)

        text = self.text.replace("${PAGE}", pageNr)

        page.add(pml.TextOp(text, x, y, fs, fl, self.align))
Beispiel #2
0
    def OnPreview(self, event):
        doc = pml.Document(self.cfg.paperWidth, self.cfg.paperHeight)

        pg = pml.Page(doc)
        self.headers.generatePML(pg, "99", self.cfg)

        fs = self.cfg.fontSize
        chY = util.getTextHeight(fs)

        y = self.cfg.marginTop + self.headers.getNrOfLines() * chY

        pg.add(pml.TextOp("Mindy runs away from the dinosaur, but trips on"
            " the power", self.cfg.marginLeft, y, fs))

        pg.add(pml.TextOp("cord. The raptor approaches her slowly.",
            self.cfg.marginLeft, y + chY, fs))

        doc.add(pg)

        tmp = pdf.generate(doc)
        gutil.showTempPDF(tmp, self.cfgGl, self)
Beispiel #3
0
    def drawLegend(self, pg, pos, color, name, lw):
        x = self.legendX + self.legendMargin
        y = self.legendY + self.legendMargin + pos * self.legendSpacing

        pg.add(pml.PDFOp("%f g" % color))

        pg.add(
            pml.RectOp(x, y, self.legendSize, self.legendSize, pml.STROKE_FILL,
                       lw))

        pg.add(pml.PDFOp("0.0 g"))

        pg.add(pml.TextOp(name, x + self.legendSize + 2.0, y, 6))
Beispiel #4
0
    def generatePML(self, page):
        y = self.y

        for line in self.items:
            x = self.x

            if self.isCentered:
                x = page.doc.w / 2.0

            page.add(
                pml.TextOp(line, x, y, self.size, self.getStyle(),
                           self.getAlignment()))

            y += util.getTextHeight(self.size)
Beispiel #5
0
    def generatePage(self, title, doc):
        pg = pml.Page(doc)

        pg.add(
            pml.TextOp(title, doc.w / 2.0, self.margin, 18,
                       pml.BOLD | pml.ITALIC | pml.UNDERLINED,
                       util.ALIGN_CENTER))

        pageCnt = len(self.pages)
        mmPerPage = max(0.1, self.chartWidth / pageCnt)

        pg.add(pml.TextOp("Page:", self.chartX - 1.0, self.pageY - 5.0, 10))

        # draw backround for every other row. this needs to be done before
        # drawing the grid.
        for i in range(len(self.cinfo)):
            y = self.chartY + i * self.charY

            if (i % 2) == 1:
                pg.add(pml.PDFOp("0.93 g"))
                pg.add(pml.RectOp(self.chartX, y, self.chartWidth, self.charY))
                pg.add(pml.PDFOp("0.0 g"))

        # line width to use
        lw = 0.25

        pg.add(pml.PDFOp("0.5 G"))

        # dashed pattern
        pg.add(pml.PDFOp("[2 2] 0 d"))

        # draw grid and page markers
        for i in xrange(pageCnt):
            if (i == 0) or ((i + 1) % 10) == 0:
                x = self.chartX + i * mmPerPage
                pg.add(
                    pml.TextOp("%d" % (i + 1),
                               x,
                               self.pageY,
                               10,
                               align=util.ALIGN_CENTER))
                if i != 0:
                    pg.add(pml.genLine(x, self.chartY, 0, self.chartHeight,
                                       lw))

        pg.add(
            pml.RectOp(self.chartX, self.chartY, self.chartWidth,
                       self.chartHeight, pml.NO_FILL, lw))

        pg.add(pml.PDFOp("0.0 G"))

        # restore normal line pattern
        pg.add(pml.PDFOp("[] 0 d"))

        # legend for page content bars
        pg.add(
            pml.RectOp(self.legendX, self.legendY, self.legendWidth,
                       self.legendHeight, pml.NO_FILL, lw))

        self.drawLegend(pg, 0, 1.0, "Other", lw)
        self.drawLegend(pg, 1, 0.7, "Character", lw)
        self.drawLegend(pg, 2, 0.5, "Dialogue", lw)
        self.drawLegend(pg, 3, 0.3, "Action", lw)

        # page content bars
        for i in xrange(pageCnt):
            x = self.chartX + i * mmPerPage
            y = self.barY + self.barHeight
            pi = self.pages[i]
            tlc = pi.getTotalLineCount()

            pg.add(pml.PDFOp("0.3 g"))
            pct = util.safeDivInt(pi.getLineCount(screenplay.ACTION), tlc)
            barH = self.barHeight * pct
            pg.add(pml.RectOp(x, y - barH, mmPerPage, barH))
            y -= barH

            pg.add(pml.PDFOp("0.5 g"))
            pct = util.safeDivInt(pi.getLineCount(screenplay.DIALOGUE), tlc)
            barH = self.barHeight * pct
            pg.add(pml.RectOp(x, y - barH, mmPerPage, barH))
            y -= barH

            pg.add(pml.PDFOp("0.7 g"))
            pct = util.safeDivInt(pi.getLineCount(screenplay.CHARACTER), tlc)
            barH = self.barHeight * pct
            pg.add(pml.RectOp(x, y - barH, mmPerPage, barH))
            y -= barH

        pg.add(pml.PDFOp("0.0 g"))

        # rectangle around page content bars
        pg.add(
            pml.RectOp(self.chartX, self.barY, self.chartWidth, self.barHeight,
                       pml.NO_FILL, lw))

        for i in range(len(self.cinfo)):
            y = self.chartY + i * self.charY
            ci = self.cinfo[i]

            pg.add(
                pml.TextOp(ci.name,
                           self.margin,
                           y + self.charY / 2.0,
                           self.charFs,
                           valign=util.VALIGN_CENTER))

            for i in xrange(pageCnt):
                pi = self.pages[i]
                cnt = pi.getSpeakerLineCount(ci.name)

                if cnt > 0:
                    h = self.charY * (float(cnt) / self.sp.cfg.linesOnPage)

                    pg.add(
                        pml.RectOp(self.chartX + i * mmPerPage,
                                   y + (self.charY - h) / 2.0, mmPerPage, h))

        return pg
Beispiel #6
0
    def generatePage(self, title, doc):
        pg = pml.Page(doc)

        pg.add(
            pml.TextOp(title, doc.w / 2.0, self.margin, 18,
                       pml.BOLD | pml.ITALIC | pml.UNDERLINED,
                       util.ALIGN_CENTER))

        pageCnt = len(self.pages)
        mmPerPage = max(0.1, self.chartWidth / pageCnt)

        pg.add(pml.TextOp("Page:", self.chartX - 1.0, self.pageY - 5.0, 10))

        # draw backround for every other row. this needs to be done before
        # drawing the grid.
        for i in range(len(self.cinfo)):
            y = self.chartY + i * self.charY

            if (i % 2) == 1:
                pg.add(pml.SetFillGray(0.93))
                pg.add(pml.RectOp(self.chartX, y, self.chartWidth, self.charY))
                pg.add(pml.SetFillGray(0.0))

        # line width to use
        lw = 0.25

        pg.add(pml.SetStrokeGray(0.5))

        # dashed pattern
        pg.add(pml.SetDash([2, 2], 0))

        # draw grid and page markers
        for i in xrange(pageCnt):
            if (i == 0) or ((i + 1) % 10) == 0:
                x = self.chartX + i * mmPerPage
                pg.add(
                    pml.TextOp("%d" % (i + 1),
                               x,
                               self.pageY,
                               10,
                               align=util.ALIGN_CENTER))
                if i != 0:
                    pg.add(pml.genLine(x, self.chartY, 0, self.chartHeight,
                                       lw))

        pg.add(
            pml.RectOp(self.chartX, self.chartY, self.chartWidth,
                       self.chartHeight, pml.STROKE, lw))

        pg.add(pml.SetStrokeGray(0.0))

        # restore normal line pattern
        pg.add(pml.SetDash())

        # legend for page content bars
        pg.add(
            pml.RectOp(self.legendX, self.legendY, self.legendWidth,
                       self.legendHeight, pml.STROKE, lw))

        self.drawLegend(pg, 0, 1.0, "Other", lw)
        self.drawLegend(pg, 1, 0.7, "Character", lw)
        self.drawLegend(pg, 2, 0.5, "Dialogue", lw)
        self.drawLegend(pg, 3, 0.3, "Action", lw)

        # page content bars
        for i in xrange(pageCnt):
            x = self.chartX + i * mmPerPage
            y = self.barY + self.barHeight
            page = self.pages[i]
            tlc = page.getTotalLineCount()

            if tlc <> 0:
                for greyvalue, itemType in [
                        (0.3, screenplay.ACTION),\
                        (0.5, screenplay.DIALOGUE),\
                        (0.7, screenplay.CHARACTER)]:
                    pg.add(pml.SetFillGray(greyvalue))
                    ratio = page.getLineCount(itemType) / tlc
                    barH = self.barHeight * ratio
                    pg.add(pml.RectOp(x, y - barH, mmPerPage, barH))
                    y -= barH

        pg.add(pml.SetFillGray(0.0))

        # rectangle around page content bars
        pg.add(
            pml.RectOp(self.chartX, self.barY, self.chartWidth, self.barHeight,
                       pml.STROKE, lw))

        for i, character in enumerate(self.cinfo):
            y = self.chartY + i * self.charY

            pg.add(
                pml.TextOp(character.name,
                           self.margin,
                           y + self.charY / 2.0,
                           self.charFs,
                           valign=util.VALIGN_CENTER))

            for i in xrange(pageCnt):
                page = self.pages[i]
                cnt = page.getSpeakerLineCount(character.name)

                if cnt > 0:
                    h = self.charY * (float(cnt) / self.sp.cfg.linesOnPage)

                    pg.add(
                        pml.RectOp(self.chartX + i * mmPerPage,
                                   y + (self.charY - h) / 2.0, mmPerPage, h))

        return pg
Beispiel #7
0
    def OnGenerate(self, event):
        watermarks = self.itemsEntry.GetValue().split("\n")
        common = self.commonMark.GetValue()
        directory = self.dirEntry.GetValue()
        fontsize = self.markSize.GetValue()
        fnprefix = self.filenamePrefix.GetValue()

        watermarks = set(watermarks)

        # keep track of ids allocated so far, just on the off-chance we
        # randomly allocated the same id twice
        usedIds = set()

        if not directory:
            wx.MessageBox("Please set directory.", "Error", wx.OK, self)
            self.dirEntry.SetFocus()
            return

        count = 0

        for item in watermarks:
            s = item.strip()

            if not s:
                continue

            basename = item.replace(" ", "-")
            fn = directory + "/" + fnprefix + '-' + basename + ".pdf"
            pmldoc = self.sp.generatePML(True)

            ops = []

            # almost-not-there gray
            ops.append(pml.SetFillGray(0.85))

            if common:
                wm = pml.TextOp(util.cleanInput(common),
                                self.sp.cfg.marginLeft + 20,
                                self.sp.cfg.paperHeight * 0.45,
                                fontsize,
                                pml.BOLD,
                                angle=45)
                ops.append(wm)

            wm = pml.TextOp(util.cleanInput(s),
                            self.sp.cfg.marginLeft + 20,
                            self.sp.cfg.paperHeight * 0.6,
                            fontsize,
                            pml.BOLD,
                            angle=45)
            ops.append(wm)

            # ...and back to black
            ops.append(pml.SetFillGray(0.0))

            for page in pmldoc.pages:
                page.addOpsToFront(ops)

            pmldoc.uniqueId = self.getUniqueId(usedIds)

            pdfdata = pdf.generate(pmldoc)

            if not util.writeToFile(fn, pdfdata, self):
                wx.MessageBox("PDF generation aborted.", "Error", wx.OK, self)
                return
            else:
                count += 1

        if count > 0:
            wx.MessageBox(
                "Generated %d files in directory %s." % (count, directory),
                "PDFs generated", wx.OK, self)
        else:
            wx.MessageBox("No watermarks specified.", "Error", wx.OK, self)