How to use the xhtml2pdf.reportlab_paragraph.ParaLines function in xhtml2pdf

To help you get started, we’ve selected a few xhtml2pdf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
if not isinstance(width, (list, tuple)):
            maxWidths = [width]
        else:
            maxWidths = width
        style = self.style

        #for bullets, work out width and ensure we wrap the right amount onto line one
        _handleBulletWidth(self.bulletText, style, maxWidths)
        if len(self.frags) > 1:
            autoLeading = getattr(self, 'autoLeading', getattr(style, 'autoLeading', ''))
            calcBounds = autoLeading not in ('', 'off')
            return cjkFragSplit(self.frags, maxWidths, calcBounds, self.encoding)

        elif not len(self.frags):
            return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
                             textColor=style.textColor, lines=[], ascent=style.fontSize, descent=-0.2 * style.fontSize)
        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)
        lines = []

        self.height = 0

        f = self.frags[0]

        if hasattr(f, 'text'):
            text = f.text
        else:
            text = ''.join(getattr(f, 'words', []))
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
if s <= 1:    # orphan?
                del self.blPara
                return []
        if n <= s: return [self]
        if not allowWidows:
            if n == s + 1: # widow?
                if (allowOrphans and n == 3) or n > 3:
                    s -= 1  # give the widow some company
                else:
                    del self.blPara # no room for adjustment; force the whole para onwards
                    return []
        func = self._get_split_blParaFunc()

        P1 = self.__class__(None, style, bulletText=self.bulletText, frags=func(blPara, 0, s))
        #this is a major hack
        P1.blPara = ParaLines(kind=1, lines=blPara.lines[0:s], aH=availHeight, aW=availWidth)
        P1._JustifyLast = 1
        P1._splitpara = 1
        P1.height = height
        P1.width = availWidth
        if style.firstLineIndent != 0:
            style = deepcopy(style)
            style.firstLineIndent = 0
        P2 = self.__class__(None, style, bulletText=None, frags=func(blPara, s, n))
        for a in ('autoLeading',    # possible attributes that might be directly on self.
        ):
            if hasattr(self, a):
                setattr(P1, a, getattr(self, a))
                setattr(P2, a, getattr(self, a))
        return [P1, P2]
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
extraSpace -= w
                i += 1
            lines.append(makeCJKParaLine(U[lineStartPos:i], extraSpace, calcBounds))
            try:
                maxWidth = maxWidths[len(lines)]
            except IndexError:
                maxWidth = maxWidths[-1]  # use the last one

            lineStartPos = i
            widthUsed = w
            i -= 1
        #any characters left?
    if widthUsed > 0:
        lines.append(makeCJKParaLine(U[lineStartPos:], maxWidth - widthUsed, calcBounds))

    return ParaLines(kind=1, lines=lines)
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
if getattr(cbDefn, 'width', 0):
                                descent, ascent = imgVRange(cbDefn.height, cbDefn.valign, fontSize)
                            else:
                                ascent, descent = getAscentDescent(g.fontName, fontSize)
                        else:
                            ascent, descent = getAscentDescent(g.fontName, fontSize)
                        maxSize = max(maxSize, fontSize)
                        maxAscent = max(maxAscent, ascent)
                        minDescent = min(minDescent, descent)

            #deal with any leftovers on the final line
            if words != []:
                if currentWidth > self.width: self.width = currentWidth
                lines.append(ParaLines(extraSpace=(maxWidth - currentWidth), wordCount=n,
                                       words=words, fontSize=maxSize, ascent=maxAscent, descent=minDescent))
            return ParaLines(kind=1, lines=lines)

        return lines
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
cLine = [word]
                    currentWidth = wordWidth
                    lineno += 1
                    try:
                        maxWidth = maxWidths[lineno]
                    except IndexError:
                        maxWidth = maxWidths[-1]  # use the last one

            #deal with any leftovers on the final line
            if cLine != []:
                if currentWidth > self.width: self.width = currentWidth
                lines.append((maxWidth - currentWidth, cLine))

            return f.clone(kind=0, lines=lines, ascent=ascent, descent=descent, fontSize=fontSize)
        elif nFrags <= 0:
            return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
                             textColor=style.textColor, ascent=style.fontSize, descent=-0.2 * style.fontSize,
                             lines=[])
        else:
            if hasattr(self, 'blPara') and getattr(self, '_splitpara', 0):
                #NB this is an utter hack that awaits the proper information
                #preserving splitting algorithm
                return self.blPara
            n = 0
            words = []
            for w in _getFragWords(frags):
                f = w[-1][0]
                fontName = f.fontName
                fontSize = f.fontSize
                spaceWidth = stringWidth(' ', fontName, fontSize)

                if not words:
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
extraSpace -= w
                i += 1
            lines.append(makeCJKParaLine(U[lineStartPos:i], extraSpace, calcBounds))
            try:
                maxWidth = maxWidths[len(lines)]
            except IndexError:
                maxWidth = maxWidths[-1]  # use the last one

            lineStartPos = i
            widthUsed = w
            i -= 1
        #any characters left?
    if widthUsed > 0:
        lines.append(makeCJKParaLine(U[lineStartPos:], maxWidth - widthUsed, calcBounds))

    return ParaLines(kind=1, lines=lines)
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
if s <= 1:    # orphan?
                del self.blPara
                return []
        if n <= s: return [self]
        if not allowWidows:
            if n == s + 1: # widow?
                if (allowOrphans and n == 3) or n > 3:
                    s -= 1  # give the widow some company
                else:
                    del self.blPara # no room for adjustment; force the whole para onwards
                    return []
        func = self._get_split_blParaFunc()

        P1 = self.__class__(None, style, bulletText=self.bulletText, frags=func(blPara, 0, s))
        #this is a major hack
        P1.blPara = ParaLines(kind=1, lines=blPara.lines[0:s], aH=availHeight, aW=availWidth)
        P1._JustifyLast = 1
        P1._splitpara = 1
        P1.height = height
        P1.width = availWidth
        if style.firstLineIndent != 0:
            style = deepcopy(style)
            style.firstLineIndent = 0
        P2 = self.__class__(None, style, bulletText=None, frags=func(blPara, s, n))
        for a in ('autoLeading',    # possible attributes that might be directly on self.
        ):
            if hasattr(self, a):
                setattr(P1, a, getattr(self, a))
                setattr(P2, a, getattr(self, a))
        return [P1, P2]
github xhtml2pdf / xhtml2pdf / xhtml2pdf / reportlab_paragraph.py View on Github external
if calcBounds:
                            cbDefn = getattr(g, 'cbDefn', None)
                            if getattr(cbDefn, 'width', 0):
                                descent, ascent = imgVRange(cbDefn.height, cbDefn.valign, fontSize)
                            else:
                                ascent, descent = getAscentDescent(g.fontName, fontSize)
                        else:
                            ascent, descent = getAscentDescent(g.fontName, fontSize)
                        maxSize = max(maxSize, fontSize)
                        maxAscent = max(maxAscent, ascent)
                        minDescent = min(minDescent, descent)

            #deal with any leftovers on the final line
            if words != []:
                if currentWidth > self.width: self.width = currentWidth
                lines.append(ParaLines(extraSpace=(maxWidth - currentWidth), wordCount=n,
                                       words=words, fontSize=maxSize, ascent=maxAscent, descent=minDescent))
            return ParaLines(kind=1, lines=lines)

        return lines