Exemple #1
0
    def addPara(self, force=False):

        # print self.force, repr(self.text)
        force = (force or self.force)
        self.force = False

        # Cleanup the trail
        try:
            rfragList = reversed(self.fragList)
        except:
            # For Python 2.3 compatibility
            rfragList = copy.copy(self.fragList)
            rfragList.reverse()

        #for frag in rfragList:
        #    frag.text = frag.text.rstrip()
        #    if frag.text:
        #        break

        # Find maximum lead
        maxLeading = 0
        #fontSize = 0
        for frag in self.fragList:
            leading = getSize(frag.leadingSource,
                              frag.fontSize) + frag.leadingSpace
            maxLeading = max(leading, frag.fontSize + frag.leadingSpace,
                             maxLeading)
            frag.leading = leading

        if force or (self.text.strip() and self.fragList):

            # Strip trailing whitespaces
            #for f in self.fragList:
            #    f.text = f.text.lstrip()
            #    if f.text:
            #        break
            #self.fragList[-1].lineBreak = self.fragList[-1].text.rstrip()

            # Update paragraph style by style of first fragment
            first = self.fragBlock
            style = self.toParagraphStyle(first)
            # style.leading = first.leading + first.leadingSpace
            if first.leadingSpace:
                style.leading = maxLeading
            else:
                style.leading = getSize(first.leadingSource,
                                        first.fontSize) + first.leadingSpace
            # style.leading = maxLeading # + first.leadingSpace
            #style.fontSize = fontSize

            # borderRadius: None,
            # print repr(self.text.strip()), style.leading, "".join([repr(x.text) for x in self.fragList])
            # print first.leftIndent, first.listStyleType,repr(self.text)

            bulletText = copy.copy(first.bulletText)
            first.bulletText = None

            # Add paragraph to story
            if force or len(self.fragAnchor + self.fragList) > 0:

                # We need this empty fragment to work around problems in
                # Reportlab paragraphs regarding backGround etc.
                if self.fragList:
                    self.fragList.append(self.fragList[-1].clone(text=''))
                else:
                    blank = self.frag.clone()
                    blank.fontName = "Helvetica"
                    blank.text = ''
                    self.fragList.append(blank)

                self.dumpPara(self.fragAnchor + self.fragList, style)
                para = PmlParagraph(self.text,
                                    style,
                                    frags=self.fragAnchor + self.fragList,
                                    bulletText=bulletText)

                # Mirrored and BIDI
                #import unicodedata
                #for c in self.text:
                #    print unicodedata.bidirectional(c),

                para.outline = first.outline
                para.outlineLevel = first.outlineLevel
                para.outlineOpen = first.outlineOpen
                para.keepWithNext = first.keepWithNext
                para.autoLeading = "max"

                if self.image:
                    para = PmlParagraphAndImage(para,
                                                self.image,
                                                side=self.imageData.get(
                                                    "align", "left"))

                self.addStory(para)

            self.fragAnchor = []
            first.bulletText = None

        # Reset data

        self.image = None
        self.imageData = {}

        self.clearFrag()
Exemple #2
0
    def addPara(self, force=False):

        force = (force or self.force)
        self.force = False

        # Cleanup the trail
        try:
            rfragList = reversed(self.fragList)
        except:
            # For Python 2.3 compatibility
            rfragList = copy.copy(self.fragList)
            rfragList.reverse()

        # Find maximum lead
        maxLeading = 0
        #fontSize = 0
        for frag in self.fragList:
            leading = getSize(frag.leadingSource,
                              frag.fontSize) + frag.leadingSpace
            maxLeading = max(leading, frag.fontSize + frag.leadingSpace,
                             maxLeading)
            frag.leading = leading

        if force or (self.text.strip() and self.fragList):

            # Update paragraph style by style of first fragment
            first = self.fragBlock
            style = self.toParagraphStyle(first)
            # style.leading = first.leading + first.leadingSpace
            if first.leadingSpace:
                style.leading = maxLeading
            else:
                style.leading = getSize(first.leadingSource,
                                        first.fontSize) + first.leadingSpace

            bulletText = copy.copy(first.bulletText)
            first.bulletText = None

            # Add paragraph to story
            if force or len(self.fragAnchor + self.fragList) > 0:

                # We need this empty fragment to work around problems in
                # Reportlab paragraphs regarding backGround etc.
                if self.fragList:
                    self.fragList.append(self.fragList[-1].clone(text=''))
                else:
                    blank = self.frag.clone()
                    blank.fontName = "Helvetica"
                    blank.text = ''
                    self.fragList.append(blank)

                self.dumpPara(self.fragAnchor + self.fragList, style)
                para = PmlParagraph(self.text,
                                    style,
                                    frags=self.fragAnchor + self.fragList,
                                    bulletText=bulletText)

                para.outline = first.outline
                para.outlineLevel = first.outlineLevel
                para.outlineOpen = first.outlineOpen
                para.keepWithNext = first.keepWithNext
                para.autoLeading = "max"

                if self.image:
                    para = PmlParagraphAndImage(para,
                                                self.image,
                                                side=self.imageData.get(
                                                    "align", "left"))

                self.addStory(para)

            self.fragAnchor = []
            first.bulletText = None

        # Reset data

        self.image = None
        self.imageData = {}

        self.clearFrag()
Exemple #3
0
    def addPara(self, force=False, incols=None):
        force = (force or self.force)
        self.force = False

        # Cleanup the trail
        rfragList = reversed(self.fragList)

        # Find maximum lead
        maxLeading = 0
        #fontSize = 0
        for frag in self.fragList:
            leading = getSize(frag.leadingSource,
                              frag.fontSize) + frag.leadingSpace
            maxLeading = max(leading, frag.fontSize + frag.leadingSpace,
                             maxLeading)
            frag.leading = leading

        if force or (self.text.strip() and self.fragList):

            # Update paragraph style by style of first fragment
            first = self.fragBlock
            style = self.toParagraphStyle(first)
            # style.leading = first.leading + first.leadingSpace
            if first.leadingSpace:
                style.leading = maxLeading
            else:
                style.leading = getSize(first.leadingSource,
                                        first.fontSize) + first.leadingSpace

            bulletText = copy.copy(first.bulletText)
            first.bulletText = None

            # Add paragraph to story
            if force or len(self.fragAnchor + self.fragList) > 0:

                # We need this empty fragment to work around problems in
                # Reportlab paragraphs regarding backGround etc.
                if self.fragList:
                    self.fragList.append(self.fragList[-1].clone(text=''))
                else:
                    blank = self.frag.clone()
                    blank.fontName = "Helvetica"
                    blank.text = ''
                    self.fragList.append(blank)

                self.dumpPara(self.fragAnchor + self.fragList, style)
                if hasattr(self, 'language'):
                    language = self.__getattribute__('language')
                    detect_language_result = arabic_format(self.text, language)
                    if detect_language_result != None:
                        self.text = detect_language_result
                para = PmlParagraph(self.text,
                                    style,
                                    frags=self.fragAnchor + self.fragList,
                                    bulletText=bulletText)

                para.outline = first.outline
                para.outlineLevel = first.outlineLevel
                para.outlineOpen = first.outlineOpen
                para.keepWithNext = first.keepWithNext
                para.autoLeading = "max"

                if self.image:
                    para = PmlParagraphAndImage(para,
                                                self.image,
                                                side=self.imageData.get(
                                                    "align", "left"))
                if isinstance(para, PmlParagraph):
                    para.frags[0].inCols = incols
                self.addStory(para)

            self.fragAnchor = []
            first.bulletText = None

        # Reset data

        self.image = None
        self.imageData = {}

        self.clearFrag()