Example #1
0
    def __init__(self, *args, **kwargs):
        # the initialization is taken from rst2pdf.flowables.Heading
        hstyle = kwargs.pop('hstyle')
        level = kwargs.pop('level')
        text = kwargs.pop('text')
        self.snum = kwargs.pop('snum')
        self.parent_id = kwargs.pop('parent_id')
        Heading.__init__(self,
                         text,
                         hstyle,
                         level=level,
                         parent_id=self.parent_id)

        # Stuff needed for the outline entry
        MyImage.__init__(self, *args, **kwargs)
Example #2
0
    def __init__(self, *args, **kwargs):
        # The inicialization is taken from rst2pdf.flowables.Heading
        hstyle = kwargs.pop('hstyle')
        level = 0
        text = kwargs.pop('text')
        self.snum = kwargs.pop('snum')
        self.parent_id = kwargs.pop('parent_id')
        # self.stext =
        Heading.__init__(self, text, hstyle, level=level, parent_id=self.parent_id)
        # Cleanup title text
        # self.stext = re.sub(r'<[^>]*?>', '', unescape(self.stext))
        # self.stext = self.stext.strip()

        # Stuff needed for the outline entry
        MyImage.__init__(self, *args, **kwargs)
Example #3
0
    def __init__(self, *args, **kwargs):
        # The inicialization is taken from rst2pdf.flowables.Heading
        hstyle = kwargs.pop('hstyle')
        level = 0
        text = kwargs.pop('text')
        self.snum = kwargs.pop('snum')
        self.parent_id= kwargs.pop('parent_id')
        #self.stext = 
        Heading.__init__(self,text,hstyle,level=level,
            parent_id=self.parent_id)
        # Cleanup title text
        #self.stext = re.sub(r'<[^>]*?>', '', unescape(self.stext))
        #self.stext = self.stext.strip()

        # Stuff needed for the outline entry
        MyImage.__init__(self, *args, **kwargs)
Example #4
0
    def gather_elements(self, client, node, style):
        # Special cases: (Not sure this is right ;-)
        if isinstance(node.parent, docutils.nodes.document):
            # node.elements = [Paragraph(client.gen_pdftext(node),
            # client.styles['title'])]
            # The visible output is now done by the cover template
            node.elements = []
            client.doc_title = node.rawsource
            client.doc_title_clean = node.astext().strip()
        elif isinstance(node.parent, docutils.nodes.topic):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['topic-title'])
            ]
        elif isinstance(node.parent, docutils.nodes.Admonition):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['admonition-title'])
            ]
        elif isinstance(node.parent, docutils.nodes.table):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['table-title'])
            ]
        elif isinstance(node.parent, docutils.nodes.sidebar):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['sidebar-title'])
            ]
        else:
            # Section/Subsection/etc.
            text = client.gen_pdftext(node)
            fch = node.children[0]
            if isinstance(fch, docutils.nodes.generated) and \
                fch['classes'] == ['sectnum']:
                snum = fch.astext()
            else:
                snum = None
            key = node.get('refid')
            maxdepth = 6

            # The parent ID is the refid + an ID to make it unique for Sphinx
            parent_id = (node.parent.get('ids', [None])
                         or [None])[0] + '-' + str(id(node))
            node.elements = [
                Heading(text,
                        client.styles['heading%d' %
                                      min(client.depth, maxdepth)],
                        level=client.depth - 1,
                        parent_id=parent_id,
                        node=node,
                        section_header_depth=client.section_header_depth)
            ]
            if client.depth <= client.breaklevel:
                node.elements.insert(0, MyPageBreak(breakTo=client.breakside))
        return node.elements
Example #5
0
    def gather_elements(self, client, node, style):
        # This method is copied from the HandleTitle class
        # in rst2pdf.genelements.

        # Special cases: (Not sure this is right ;-)
        if isinstance(node.parent, docutils.nodes.document):
            #node.elements = [Paragraph(client.gen_pdftext(node),
            #client.styles['title'])]
            # The visible output is now done by the cover template
            node.elements = []
            client.doc_title = node.rawsource
            client.doc_title_clean = node.astext().strip()
        elif isinstance(node.parent, docutils.nodes.topic):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['topic-title'])
            ]
        elif isinstance(node.parent, docutils.nodes.Admonition):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['admonition-title'])
            ]
        elif isinstance(node.parent, docutils.nodes.table):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['table-title'])
            ]
        elif isinstance(node.parent, docutils.nodes.sidebar):
            node.elements = [
                Paragraph(client.gen_pdftext(node),
                          client.styles['sidebar-title'])
            ]
        else:
            # Section/Subsection/etc.
            text = client.gen_pdftext(node)
            fch = node.children[0]
            if isinstance(fch, docutils.nodes.generated) and \
                fch['classes'] == ['sectnum']:
                snum = fch.astext()
            else:
                snum = None
            key = node.get('refid')
            maxdepth = 4
            if reportlab.Version > '2.1':
                maxdepth = 6

            # The parent ID is the refid + an ID to make it unique for Sphinx
            parent_id = (node.parent.get('ids', [None])
                         or [None])[0] + u'-' + unicode(id(node))
            if client.depth <= 3:
                depth = min(client.depth, maxdepth)
                bar = '%s' % depth
                height = self.heading_heights[depth]

                tfile = codecs.open('imagenes/titulo_%s.svg' % bar, 'r',
                                    'utf-8')
                tdata = tfile.read()
                tfile.close()
                tfile = tempfile.NamedTemporaryFile(dir='.',
                                                    delete=False,
                                                    suffix='.svg')
                tfname = tfile.name
                tfile.write(
                    tdata.replace('TITLEGOESHERE', text).encode('utf-8'))
                tfile.close()

                # Now tfname contains a SVG with the right title.
                # Make rst2pdf delete it later.
                client.to_unlink.append(tfname)

                e = FancyHeading(
                    tfname,
                    width=700,
                    height=height,
                    client=client,
                    snum=snum,
                    parent_id=parent_id,
                    text=text,
                    level=client.depth - 1,
                    hstyle=client.styles['heading%d' %
                                         min(client.depth, maxdepth)])

                node.elements = [e]
            else:
                node.elements = [
                    Heading(
                        text,
                        client.styles['heading%d' %
                                      min(client.depth, maxdepth)],
                        level=client.depth - 1,
                        parent_id=parent_id,
                        node=node,
                    )
                ]

            if client.depth <= client.breaklevel:
                node.elements.insert(0, MyPageBreak(breakTo=client.breakside))
        return node.elements