ext/xhtml2fo.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 16 Sep 2009 21:29:17 +0200
branch3.5
changeset 3275 5247789df541
parent 3080 32c2b6a34ab2
child 3150 20c0ba65ee0b
permissions -rw-r--r--
[gettext] provide GNU contexts to avoid translations ambiguities
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     1
from cubicweb.utils import can_do_pdf_conversion
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
assert can_do_pdf_conversion()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     4
from xml.etree.ElementTree import QName, fromstring
2936
f35b64718d02 follow name change, fix pdf template registration, add debian package tracking
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2935
diff changeset
     5
from pysixt.standard.xhtml_xslfo.transformer import XHTML2FOTransformer
f35b64718d02 follow name change, fix pdf template registration, add debian package tracking
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2935
diff changeset
     6
from pysixt.utils.xslfo.standard import cm
f35b64718d02 follow name change, fix pdf template registration, add debian package tracking
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2935
diff changeset
     7
from pysixt.utils.xslfo import SimplePageMaster
f35b64718d02 follow name change, fix pdf template registration, add debian package tracking
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2935
diff changeset
     8
from pysixt.standard.xhtml_xslfo.default_styling import default_styles
f35b64718d02 follow name change, fix pdf template registration, add debian package tracking
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2935
diff changeset
     9
from pysixt.standard.xhtml_xslfo import XHTML_NS
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    10
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
class ReportTransformer(XHTML2FOTransformer):
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    13
    """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    14
    Class transforming an XHTML input tree into a FO document
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
    displaying reports (one report for each <div class="contentmain">
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    16
    element in the input tree.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
    """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    18
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
    def __init__(self, section,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
                 page_width=21.0, page_height=29.7,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
                 margin_top=1.0, margin_bottom=1.0,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    22
                 margin_left=1.0, margin_right=1.0,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
                 header_footer_height=0.75,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
                 standard_font_size=11.0, default_lang=u"fr" ):
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    25
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    26
        Initializes a transformer turning an XHTML input tree
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    27
        containing <div class="contentmain"> elements representing
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    28
        main content sections into a FO output tree displaying the
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    29
        reports.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    31
        page_width: float - width of the page (in cm)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    32
        page_height: float - height of the page (in cm)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    33
        margin_top: float - top margin of the page (in cm)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    34
        margin_bottom: float - bottom margin of the page (in cm)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
        margin_left: float - left margin of the page (in cm)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    36
        margin_right: float - right margin of the page (in cm)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    37
        header_footer_height: float - height of the header or the footer of the
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    38
                              page that the page number (if any) will be
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    39
                              inserted in.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    40
        standard_font_size: float - standard size of the font (in pt)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    41
        default_lang: u"" - default language (used for hyphenation)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    42
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    43
        self.section = section
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    44
        self.page_width = page_width
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    45
        self.page_height = page_height
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    46
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    47
        self.page_tmargin = margin_top
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    48
        self.page_bmargin = margin_bottom
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    49
        self.page_lmargin = margin_left
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    50
        self.page_rmargin = margin_right
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    51
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    52
        self.hf_height = header_footer_height
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    53
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    54
        self.font_size = standard_font_size
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    55
        self.lang = default_lang
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    56
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    57
        XHTML2FOTransformer.__init__(self)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    58
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    59
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    60
    def define_pagemasters(self):
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    61
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    62
        Defines the page masters for the FO output document.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    63
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    64
        pm = SimplePageMaster(u"page-report")
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    65
        pm.set_page_dims( self.page_width*cm, self.page_height*cm )
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    66
        pm.set_page_margins({u'top'   : self.page_tmargin*cm,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    67
                             u'bottom': self.page_bmargin*cm,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    68
                             u'left'  : self.page_lmargin*cm,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    69
                             u'right' : self.page_rmargin*cm })
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    70
        pm.add_peripheral_region(u"end",self.hf_height)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    71
        dims = {}
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    72
        dims[u"bottom"] = self.hf_height + 0.25
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    73
        pm.set_main_region_margins(dims)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    74
        return [pm]
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    75
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    76
    def _visit_report(self, in_elt, _out_elt, params):
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    77
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    78
        Specific visit function for the input <div> elements whose class is
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    79
        "report". The _root_visit method of this class selects these input
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    80
        elements and asks the process of these elements with this specific
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    81
        visit function.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    82
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    83
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    84
        ps = self.create_pagesequence(u"page-report")
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    85
        props = { u"force-page-count": u"no-force",
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    86
                  u"initial-page-number": u"1",
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    87
                  u"format": u"1", }
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    88
        self._output_properties(ps,props)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    89
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    90
        sc = self.create_staticcontent(ps, u"end")
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    91
        sc_bl = self.create_block(sc)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    92
        attrs = { u"hyphenate": u"false", }
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    93
        attrs[u"font-size"] = u"%.1fpt" %(self.font_size*0.7)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    94
        attrs[u"language"] = self.lang
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    95
        attrs[u"text-align"] = u"center"
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    96
        self._output_properties(sc_bl,attrs)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    97
        sc_bl.text = u"Page" + u" " # ### Should be localised!
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    98
        pn = self.create_pagenumber(sc_bl)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    99
        pn.tail = u"/"
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   100
        lpn = self.create_pagenumbercitation( sc_bl,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   101
                                              u"last-block-of-report-%d" % params[u"context_pos"]
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   102
                                              )
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   103
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   104
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   105
        fl = self.create_flow(ps,u"body")
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   106
        bl = self.create_block(fl)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   107
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   108
        # Sets on the highest block element the properties of the XHTML body
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   109
        # element. These properties (at the least the inheritable ones) will
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   110
        # be inherited by all the future FO elements.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   111
        bodies = list(self.in_tree.getiterator(QName(XHTML_NS,u"body")))
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   112
        if len(bodies) > 0:
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   113
            attrs = self._extract_properties([bodies[0]])
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   114
        else:
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   115
            attrs = default_styles[u"body"].copy()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   116
        attrs[u"font-size"] = u"%.1fpt" %self.font_size
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   117
        attrs[u"language"] = self.lang
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   118
        self._output_properties(bl,attrs)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   119
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   120
        # Processes the report content
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   121
        self._copy_text(in_elt,bl)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   122
        self._process_nodes(in_elt.getchildren(),bl)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   123
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   124
        # Inserts an empty block at the end of the report in order to be able
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   125
        # to compute the last page number of this report.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   126
        last_bl = self.create_block(bl)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   127
        props = { u"keep-with-previous": u"always", }
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   128
        props[u"id"] = u"last-block-of-report-%d" % params[u"context_pos"]
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   129
        self._output_properties(last_bl,props)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   130
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   131
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   132
    def _root_visit(self):
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   133
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   134
        Visit function called when starting the process of the input tree.
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   135
        """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   136
        content = [ d for d in self.in_tree.getiterator(QName(XHTML_NS,u"div"))
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   137
                    if d.get(u"id") == self.section ]
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   138
        # Asks the process of the report elements with a specific visit
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   139
        # function
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   140
        self._process_nodes(content, self.fo_root,
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   141
                            with_function=self._visit_report)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   142