Exemple #1
0
    def wrap(self, availWidth, availHeight):
        """Adds hyperlink to toc entry."""

        widths = (availWidth - self.rightColumnWidth, self.rightColumnWidth)

        # makes an internal table which does all the work.
        # we draw the LAST RUN's entries!  If there are
        # none, we make some dummy data to keep the table
        # from complaining
        if len(self._lastEntries) == 0:
            if reportlab.Version <= '2.3':
                _tempEntries = [(0, 'Placeholder for table of contents', 0)]
            else:
                _tempEntries = [(0, 'Placeholder for table of contents', 0,
                                 None)]
        else:
            _tempEntries = self._lastEntries

        if _tempEntries:
            base_level = _tempEntries[0][0]
        else:
            base_level = 0
        tableData = []
        for entry in _tempEntries:
            level, text, pageNum = entry[:3]
            left_col_level = level - base_level
            if reportlab.Version > '2.3':  # For ReportLab post-2.3
                leftColStyle = self.getLevelStyle(left_col_level)
            else:  # For ReportLab <= 2.3
                leftColStyle = self.levelStyles[left_col_level]
            label = self.refid_lut.get((level, text, pageNum), None)
            if label:
                pre = u'<a href="%s" color="%s">' % (label, self.linkColor)
                post = u'</a>'
                if not isinstance(text, unicode):
                    text = unicode(text, 'utf-8')
                text = pre + text + post
            else:
                pre = ''
                post = ''
            #right col style is right aligned
            rightColStyle = ParagraphStyle(name='leftColLevel%d' %
                                           left_col_level,
                                           parent=leftColStyle,
                                           leftIndent=0,
                                           alignment=TA_RIGHT)
            leftPara = Paragraph(text, leftColStyle)
            rightPara = Paragraph(pre + str(pageNum) + post, rightColStyle)
            tableData.append([leftPara, rightPara])

        self._table = Table(tableData, colWidths=widths, style=self.tableStyle)

        self.width, self.height = self._table.wrapOn(self.canv, availWidth,
                                                     availHeight)
        return self.width, self.height
Exemple #2
0
 def __init__(self, text, style, bulletText=None, caseSensitive=1, level=0,
              snum=None, parent_id=None, node=None, section_header_depth=2):
     # Issue 114: need to convert "&amp;" to "&" and such.
     # Issue 140: need to make it plain text
     self.stext=re.sub(r'<[^>]*?>', '', unescape(text))
     self.stext = self.stext.strip()
     self.level = int(level)
     self.snum = snum
     self.parent_id=parent_id
     self.node=node
     self.section_header_depth = section_header_depth
     Paragraph.__init__(self, text, style, bulletText)
Exemple #3
0
 def __init__(self, text, style, bulletText=None, caseSensitive=1, level=0,
              snum=None, parent_id=None, node=None, section_header_depth=2):
     # Issue 114: need to convert "&amp;" to "&" and such.
     # Issue 140: need to make it plain text
     self.stext=re.sub(r'<[^>]*?>', '', unescape(text))
     self.stext = self.stext.strip()
     self.level = int(level)
     self.snum = snum
     self.parent_id=parent_id
     self.node=node
     self.section_header_depth = section_header_depth
     Paragraph.__init__(self, text, style, bulletText)
Exemple #4
0
 def gather_elements(self, client, node, style):
     # Based on the graphviz extension
     global graphviz_warn
     try:
         # Is vectorpdf enabled?
         if hasattr(VectorPdf, 'load_xobj'):
             # Yes, we have vectorpdf
             fname, outfn = sphinx.ext.graphviz.render_dot(
                 node['builder'], node['code'], node['options'], 'pdf')
         else:
             # Use bitmap
             if not graphviz_warn:
                 log.warning(
                     'Using graphviz with PNG output. You get much better results if you enable the vectorpdf extension.'
                 )
                 graphviz_warn = True
             fname, outfn = sphinx.ext.graphviz.render_dot(
                 node['builder'], node['code'], node['options'], 'png')
         if outfn:
             client.to_unlink.append(outfn)
             client.to_unlink.append(outfn + '.map')
         else:
             # Something went very wrong with graphviz, and
             # sphinx should have given an error already
             return []
     except sphinx.ext.graphviz.GraphvizError as exc:
         log.error('dot code %r: ' % node['code'] + str(exc))
         return [Paragraph(node['code'], client.styles['code'])]
     return [MyImage(filename=outfn, client=client)]
Exemple #5
0
    def draw(self):

        # Add outline entry
        self.canv.bookmarkHorizontal(self.parent_id, 0, 0 + self.height)
        if self.canv.firstSect:
            self.canv.sectName = self.stext
            self.canv.firstSect = False
            if self.snum is not None:
                self.canv.sectNum = self.snum
            else:
                self.canv.sectNum = ""

        self.canv.addOutlineEntry(self.stext.encode('utf-8', 'replace'),
                                  self.parent_id.encode('utf-8', 'replace'),
                                  int(self.level), False)
        Paragraph.draw(self)
Exemple #6
0
    def draw(self):

        # Add outline entry
        self.canv.bookmarkHorizontal(self.parent_id,0,0+self.height)
        # self.section_header_depth is for Issue 391
        if self.canv.firstSect and self.level < self.section_header_depth:
            self.canv.sectName = self.stext
            self.canv.firstSect=False
            if self.snum is not None:
                self.canv.sectNum = self.snum
            else:
                self.canv.sectNum = ""

        self.canv.addOutlineEntry(self.stext.encode('utf-8','replace'),
                                  self.parent_id.encode('utf-8','replace'),
                                  int(self.level), False)
        Paragraph.draw(self)
Exemple #7
0
 def gather_elements(self, client, node, style):
     # Based on the graphviz extension
     try:
         fname, outfn = sphinx.ext.graphviz.render_dot(
             node['builder'], node['code'], node['options'], 'pdf')
         client.to_unlink.append(outfn)
         client.to_unlink.append(outfn + '.map')
     except sphinx.ext.graphviz.GraphvizError, exc:
         log.error('dot code %r: ' % node['code'] + str(exc))
         return [Paragraph(node['code'], client.styles['code'])]
Exemple #8
0
 def gather_elements(self, client, node, style):
     # Need to add ids as targets, found this when using one of the
     # django docs extensions
     targets = [i.replace(' ', '') for i in node['ids']]
     pre = ''
     for i in targets:
         if i not in client.targets:
             pre += '<a name="%s" />' % i
             client.targets.append(i)
     return [Paragraph(pre + client.gather_pdftext(node), style)]
Exemple #9
0
    def draw(self):

        # Add outline entry
        self.canv.bookmarkHorizontal(self.parent_id,0,0+self.height)
        # self.section_header_depth is for Issue 391
        if self.canv.firstSect and self.level < self.section_header_depth:
            self.canv.sectName = self.stext
            self.canv.firstSect=False
            if self.snum is not None:
                self.canv.sectNum = self.snum
            else:
                self.canv.sectNum = ""

        self.canv.addOutlineEntry(self.stext.encode('utf-8','replace'),
                                  self.parent_id.encode('utf-8','replace'),
                                  int(self.level), False)
        Paragraph.draw(self)
        #ADD BY FAO
        if self.style.__dict__['underline'] == 1:
            self.canv.setLineWidth(.3)
            self.canv.setStrokeColor(self.style.textColor)
            self.canv.line(0,0, self._frame._width,0)
Exemple #10
0
    def draw(self):

        # Add outline entry
        self.canv.bookmarkHorizontal(self.parent_id, 0, 0 + self.height)
        # self.section_header_depth is for Issue 391
        if self.canv.firstSect and self.level < self.section_header_depth:
            self.canv.sectName = self.stext
            self.canv.firstSect = False
            if self.snum is not None:
                self.canv.sectNum = self.snum
            else:
                self.canv.sectNum = ""

        self.canv.addOutlineEntry(self.stext.encode('utf-8', 'replace'),
                                  self.parent_id.encode('utf-8', 'replace'),
                                  int(self.level), False)
        Paragraph.draw(self)
        #ADD BY FAO
        if self.style.__dict__['underline'] == 1:
            self.canv.setLineWidth(.3)
            self.canv.setStrokeColor(self.style.textColor)
            self.canv.line(0, 0, self._frame._width, 0)
Exemple #11
0
 def __init__(self,
              text,
              style,
              bulletText=None,
              caseSensitive=1,
              level=0,
              snum=None,
              parent_id=None,
              node=None):
     #if label is None: # it happens
     #self.label = text.replace(u'\xa0', ' ').strip(
     #).replace(' ', '-').encode('ascii', 'replace').lower()
     #else:
     #self.label = label.strip()
     # Issue 114: need to convert "&amp;" to "&" and such.
     # Issue 140: need to make it plain text
     self.stext = re.sub(r'<[^>]*?>', '', unescape(text))
     self.stext = self.stext.strip()
     self.level = int(level)
     self.snum = snum
     self.parent_id = parent_id
     self.node = node
     Paragraph.__init__(self, text, style, bulletText)
Exemple #12
0
 def gather_elements(self, client, node, style):
     return [Paragraph(client.gather_pdftext(node), style)]
Exemple #13
0
 def gather_elements(self, client, node, style):
     return [
         Paragraph(client.gather_pdftext(node), client.styles['centered'])
     ]