Example #1
0
    def wrap(self, availWidth, availHeight):
        # work out widths array for breaking
        self.width = availWidth
        leftIndent = self.style.leftIndent
        first_line_width = availWidth - (leftIndent+self.style.firstLineIndent) - self.style.rightIndent
        later_widths = availWidth - leftIndent - self.style.rightIndent

        if self.style.wordWrap == 'CJK':
            #use Asian text wrap algorithm to break characters
            self.blPara = self.breakLinesCJK([first_line_width, later_widths])
        else:
            self.blPara = self.breakLines([first_line_width, later_widths])
            new = []
            for line in self.blPara.lines:
                if self.blPara.kind == 0 and line[0] < 0 or self.blPara.kind == 1 and line.extraSpace < 0:
                    if self.blPara.kind == 1:
                        for txt in line.words:
                            for w in wordSplit(txt.text, first_line_width, txt.fontName, txt.fontSize):
                                abag = txt.clone()
                                abag.text = w[1]
                                new.append(platypus.ParaLines(extraSpace=w[0], wordCount=1, fontSize=txt.fontSize, fontName=txt.fontName, words=[abag]))

                    else:
                        for w in wordSplit(line[1][0], first_line_width, self.blPara.fontName, self.blPara.fontSize):
                            new.append((w[0], [w[1]]))
                else:
                    new.append(line)

            self.blPara.lines = new
        self.height = len(self.blPara.lines) * self.style.leading
        return (self.width, self.height)
    def breakLinesCJK(self, width):
        """Initially, the dumbest possible wrapping algorithm.
        Cannot handle font variations."""

        style = self.style
        #for now we only handle one fragment.  Need to generalize this quickly.
        if len(self.frags) > 1:
            raise ValueError(
                'CJK Wordwrap can only handle one fragment per paragraph for now'
            )
        elif len(self.frags) == 0:
            return ParaLines(
                kind=0,
                fontSize=style.fontSize,
                fontName=style.fontName,
                textColor=style.textColor,
                lines=[])
        f = self.frags[0]
        if 1 and hasattr(self, 'blPara') and getattr(self, '_splitpara', 0):
            #NB this is an utter hack that awaits the proper information
            #preserving splitting algorithm
            return f.clone(kind=0, lines=self.blPara.lines)
        if type(width) != ListType: maxWidths = [width]
        else: maxWidths = width
        lines = []
        lineno = 0
        fFontSize = float(style.fontSize)

        #for bullets, work out width and ensure we wrap the right amount onto line one
        _handleBulletWidth(self.bulletText, style, maxWidths)

        maxWidth = maxWidths[0]

        self.height = 0

        f = self.frags[0]

        if hasattr(f, 'text'):
            text = f.text
        else:
            text = ''.join(getattr(f, 'words', []))

        from reportlab.lib.textsplit import wordSplit
        lines = wordSplit(text, maxWidths[0], f.fontName, f.fontSize)
        #the paragraph drawing routine assumes multiple frags per line, so we need an
        #extra list like this
        #  [space, [text]]
        #
        wrappedLines = [(sp, [line]) for (sp, line) in lines]
        return f.clone(kind=0, lines=wrappedLines)
Example #3
0
 def get_data(self):
     """Return the word_wrapped data string. 
     Use this for Pdf only. This exists because Reportlab does not enforce 
     wordwrap for table cells.
     """
     font_vals = self.get_font()
     if not font_vals:
         # No font defined for this cell! return the row data
         return self.data
     # Leave a 5% space. We need to accommodate a hyphen(-) also.
     width = int(self.get_col_width() * 95 / 100)
     data = ''.join(self.data.split('\n'))
     lines = wordSplit(data, width, *font_vals)
     return "-\n".join([split[1] for split in lines])
Example #4
0
    def breakLinesCJK(self, width):
        """Initially, the dumbest possible wrapping algorithm.
        Cannot handle font variations."""

        style = self.style
        #for now we only handle one fragment.  Need to generalize this quickly.
        if len(self.frags) > 1:
            raise ValueError(
                'CJK Wordwrap can only handle one fragment per paragraph for now'
            )
        elif len(self.frags) == 0:
            return ParaLines(kind=0,
                             fontSize=style.fontSize,
                             fontName=style.fontName,
                             textColor=style.textColor,
                             lines=[])
        f = self.frags[0]
        if 1 and hasattr(self, 'blPara') and getattr(self, '_splitpara', 0):
            #NB this is an utter hack that awaits the proper information
            #preserving splitting algorithm
            return f.clone(kind=0, lines=self.blPara.lines)
        if type(width) != ListType: maxWidths = [width]
        else: maxWidths = width
        lines = []
        lineno = 0
        fFontSize = float(style.fontSize)

        #for bullets, work out width and ensure we wrap the right amount onto line one
        _handleBulletWidth(self.bulletText, style, maxWidths)

        maxWidth = maxWidths[0]

        self.height = 0

        f = self.frags[0]

        if hasattr(f, 'text'):
            text = f.text
        else:
            text = ''.join(getattr(f, 'words', []))

        from reportlab.lib.textsplit import wordSplit
        lines = wordSplit(text, maxWidths[0], f.fontName, f.fontSize)
        #the paragraph drawing routine assumes multiple frags per line, so we need an
        #extra list like this
        #  [space, [text]]
        #
        wrappedLines = [(sp, [line]) for (sp, line) in lines]
        return f.clone(kind=0, lines=wrappedLines)
Example #5
0
 def myLaterPages(c, doc):
     c.saveState()
     c.setFont("Times-Bold", 82)
     c.rotate(45)
     c.setFillColorRGB(0.9,0.9,0.9)
     c.drawString(11*cm,2*cm, copia)
     c.rotate(-45)
     c.setFillColorRGB(0,0,0)
     # HEADER
     if tipodoc == "Fattura Accompagnatoria":
         subt = 0
     else:
         subt = 3
     c.setLineWidth(0.1*cm)
     c.setStrokeColorRGB(0,0,0)
     c.line(1.8*cm,(6.2-subt)*cm,19.5*cm,(6.2-subt)*cm)
     c.setStrokeColorRGB(0.5,0.5,0.5)
     c.line(1.9*cm,(6.1-subt)*cm,19.6*cm,(6.1-subt)*cm)
     # cerchi carta
     c.circle(0.9*cm,6*cm,0.3*cm, fill=1)
     c.circle(0.9*cm,24*cm,0.3*cm, fill=1)
     c.setFont("Times-Bold", 14)
     c.drawCentredString(5*cm, 28*cm, r1)
     c.setFont("Times-Bold", 9)
     c.drawCentredString(5*cm, 27.5*cm, r2)
     c.drawCentredString(5*cm, 27*cm, r3)
     c.drawCentredString(5*cm, 26.5*cm, r4)
     c.drawCentredString(5*cm, 26*cm, r5)
     # numero ddt e descrizione copia
     c.setFont("Times-Bold", 12)
     c.drawCentredString(18*cm, 28*cm, "DOC N: %s" % (numdoc))
     c.setFont("Times-Bold", 7)
     c.drawCentredString(18*cm, 27.6*cm, "(%s)" % (copia))
     c.drawCentredString(18*cm, 27.2*cm, "%s" % (tipodoc.toUpper()))
     # Data e causale
     c.setFont("Times-Bold", 10)
     c.drawString(1.8*cm, 25*cm, "Data:")
     c.drawString(1.8*cm, 24.5*cm, "Causale:")
     c.setFont("Times-Roman", 10)
     c.drawString(4*cm, 25*cm, unicode(datadoc))
     c.drawString(4*cm, 24.5*cm, unicode(causaledoc))
     # Cliente
     c.setFont("Times-Bold", 10)
     c.drawString(11*cm, 25*cm, "Destinatario:")
     c.setFont("Times-Roman", 10)
     c.drawCentredString(16*cm, 25*cm, unicode(cliragsoc))
     c.drawCentredString(16*cm, 24.5*cm, unicode(cliind))
     c.drawCentredString(16*cm, 24*cm, unicode(clipiva))
     # FOOTER
     c.setFont("Times-Bold", 10)
     c.setLineWidth(0.01*cm)
     c.drawString(1.8*cm, (5.5-subt)*cm, "Note:")
     c.setFont("Times-Roman", 10)
     strt = (5.5-subt)*cm
     for i in textsplit.wordSplit(unicode(notedoc),6*cm,
                                 "Times-Roman", 10):
         c.drawString(3*cm, strt, i[1])
         strt -= 0.5*cm
     if tipodoc == "Fattura Accompagnatoria":
         c.setFont("Times-Bold", 10)
         c.drawString(12*cm, 5.5*cm, "Data inizio trasporto:")
         c.line(15.5*cm,5.4*cm,19*cm,5.4*cm)
         c.drawString(12*cm, 5*cm, "Aspetto dei beni:")
         c.line(15*cm,4.9*cm,19*cm,4.9*cm)
         c.drawString(12*cm, 4.5*cm, "Numero colli:")
         c.line(15*cm,4.4*cm,19*cm,4.4*cm)
         c.drawString(12*cm, 3.8*cm, "Conducente:")
         c.line(15*cm,3.7*cm,19*cm,3.7*cm)
         c.drawString(12*cm, 3*cm, "Destinatario:")
         c.line(15*cm,2.9*cm,19*cm,2.9*cm)
         c.drawString(1.8*cm, 4*cm, "Trasporto a Mezzo:")
         c.line(2.3*cm,3*cm,7*cm,3*cm)
     # note pie' pagina
     c.setFont('Times-Roman',9)
     c.drawString(12.4*cm, 1.5*cm, "Pagina %d %s" % (doc.page, pageinfo))
     c.restoreState()