Example #1
0
    def __init__(self, document_part, chain, title_flowables=None,
                 header=True, footer=True):
        paper = document_part.document.options['page_size']
        orientation = document_part.document.options['page_orientation']
        super().__init__(document_part, paper, orientation)
        document = document_part.document
        h_margin = document.options['page_horizontal_margin']
        v_margin = document.options['page_vertical_margin']
        num_cols = document.options['columns']
        body_width = self.width - (2 * h_margin)
        body_height = self.height - (2 * v_margin)
        total_column_spacing = self.column_spacing * (num_cols - 1)
        column_width = (body_width - total_column_spacing) / num_cols
        self.body = Container('body', self, h_margin, v_margin,
                              body_width, body_height)

        footnote_space = FootnoteContainer('footnotes', self.body, 0*PT,
                                           self.body.height)
        float_space = DownExpandingContainer('floats', self.body, 0*PT,
                                             0*PT, max_height=body_height / 2)
        self.body.float_space = float_space
        if title_flowables:
            self.title = DownExpandingContainer('title', self.body,
                                                top=float_space.bottom)
            self.title.append_flowable(title_flowables)
            column_top = self.title.bottom + self.column_spacing
        else:
            column_top = float_space.bottom
        self.columns = [ChainedContainer('column{}'.format(i + 1), self.body,
                                         chain,
                                         left=i * (column_width
                                                   + self.column_spacing),
                                         top=column_top, width=column_width,
                                         bottom=footnote_space.top)
                        for i in range(num_cols)]
        for column in self.columns:
            column._footnote_space = footnote_space

        if header and document_part.header:
            header_bottom = self.body.top - self.header_footer_distance
            self.header = UpExpandingContainer('header', self,
                                               left=h_margin,
                                               bottom=header_bottom,
                                               width=body_width)
            self.header.append_flowable(Header(document_part.header))
            self.header.append_flowable(HorizontalRule(style='header'))
        if footer and document_part.footer:
            footer_vpos = self.body.bottom + self.header_footer_distance
            self.footer = DownExpandingContainer('footer', self,
                                                 left=h_margin,
                                                 top=footer_vpos,
                                                 width=body_width)
            self.footer.append_flowable(HorizontalRule(style='footer'))
            self.footer.append_flowable(Footer(document_part.footer))
Example #2
0
class SimplePage(Page):
    header_footer_distance = 14*PT
    column_spacing = 1*CM

    def __init__(self, chain, paper, orientation):
        super().__init__(chain.document_part, paper, orientation)
        h_margin = self.document.options['page_horizontal_margin']
        v_margin = self.document.options['page_vertical_margin']
        num_cols = self.document.options['columns']
        body_width = self.width - (2 * h_margin)
        body_height = self.height - (2 * v_margin)
        total_column_spacing = self.column_spacing * (num_cols - 1)
        column_width = (body_width - total_column_spacing) / num_cols
        self.body = Container('body', self, h_margin, v_margin,
                              body_width, body_height)

        footnote_space = FootnoteContainer('footnotes', self.body, 0*PT,
                                           body_height)
        self.columns = [Container('column{}'.format(i + 1), self.body,
                                  left=i * (column_width + self.column_spacing),
                                  top=0*PT,
                                  width=column_width,
                                  bottom=footnote_space.top,
                                  chain=chain)
                        for i in range(num_cols)]
        footnote_space.max_height = body_height - self.columns[0]._cursor
        for column in self.columns:
            column._footnote_space = footnote_space

        if self.document_part.header:
            header_bottom = self.body.top - self.header_footer_distance
            self.header = UpExpandingContainer('header', self,
                                               left=h_margin,
                                               bottom=header_bottom,
                                               width=body_width)
            self.header.append_flowable(Header(self.document_part.header))
        if self.document_part.footer:
            footer_vpos = self.body.bottom + self.header_footer_distance
            self.footer = DownExpandingContainer('footer', self,
                                                 left=h_margin,
                                                 top=footer_vpos,
                                                 width=body_width)
            self.footer.append_flowable(Footer(self.document_part.footer))
Example #3
0
    def __init__(self, document, first=False):
        super().__init__(document, LETTER, PORTRAIT)

        body_width = self.width - (self.leftmargin + self.rightmargin)
        body_height = self.height - (self.topmargin + self.bottommargin)
        body = Container('body', self, self.leftmargin, self.topmargin,
                         body_width, body_height)

        column_width = (body.width - self.column_spacing) / 2.0
        column_top = 0 * PT
        if first:
            self.title_box = DownExpandingContainer('title', body)
            column_top = self.title_box.bottom

        self.float_space = TopFloatContainer('top floats',
                                             body,
                                             top=column_top)
        column_top = self.float_space.bottom

        self.content = document.content

        self.footnote_space = FootnoteContainer('footnotes', body, 0 * PT,
                                                body_height)
        self._footnote_number = 0

        self.column1 = Container('column1',
                                 body,
                                 0 * PT,
                                 column_top,
                                 width=column_width,
                                 bottom=self.footnote_space.top,
                                 chain=document.content)
        self.column2 = Container('column2',
                                 body,
                                 column_width + self.column_spacing,
                                 column_top,
                                 width=column_width,
                                 bottom=self.footnote_space.top,
                                 chain=document.content)

        self.column1._footnote_space = self.footnote_space
        self.column2._footnote_space = self.footnote_space
        self.column1.float_space = self.float_space
        self.column2.float_space = self.float_space

        self.header = Container('header', self, self.leftmargin,
                                self.topmargin / 2, body_width, 12 * PT)
        footer_vert_pos = self.topmargin + body_height + self.bottommargin / 2
        self.footer = Container('footer', self, self.leftmargin,
                                footer_vert_pos, body_width, 12 * PT)
        header_text = Header(styles['header'])
        self.header.append_flowable(header_text)
        footer_text = Footer(styles['footer'])
        self.footer.append_flowable(footer_text)
Example #4
0
 def __init__(self, document_part, template_name, page_number, after_break):
     super().__init__(document_part, template_name, page_number,
                      after_break)
     metadata = self.document.metadata
     get_metadata = self.document.get_metadata
     self.title = DownExpandingContainer('title', CONTENT, self,
                                         self.left_margin, self.top_margin,
                                         self.body_width)
     if 'logo' in metadata:
         self.title << Image(get_metadata('logo'),
                             style='title page logo',
                             limit_width=100 * PERCENT)
     self.title << Image(Path(__file__).parent / 'page_template.png',
                         scale=2)
     self.title << self.document.TEMPLATE_IMAGE
Example #5
0
    def __init__(self,
                 document_part,
                 chain,
                 title_flowables=None,
                 header=True,
                 footer=True):
        paper = document_part.document.options['page_size']
        orientation = document_part.document.options['page_orientation']
        super().__init__(document_part, paper, orientation)
        document = document_part.document
        h_margin = document.options['page_horizontal_margin']
        v_margin = document.options['page_vertical_margin']
        num_cols = document.options['columns']
        body_width = self.width - (2 * h_margin)
        body_height = self.height - (2 * v_margin)
        total_column_spacing = self.column_spacing * (num_cols - 1)
        column_width = (body_width - total_column_spacing) / num_cols
        self.body = Container('body', self, h_margin, v_margin, body_width,
                              body_height)

        footnote_space = FootnoteContainer('footnotes', self.body, 0 * PT,
                                           self.body.height)
        float_space = DownExpandingContainer('floats',
                                             self.body,
                                             0 * PT,
                                             0 * PT,
                                             max_height=body_height / 2)
        self.body.float_space = float_space
        if title_flowables:
            self.title = DownExpandingContainer('title',
                                                self.body,
                                                top=float_space.bottom)
            self.title.append_flowable(title_flowables)
            column_top = self.title.bottom + self.column_spacing
        else:
            column_top = float_space.bottom
        self.columns = [
            ChainedContainer('column{}'.format(i + 1),
                             self.body,
                             chain,
                             left=i * (column_width + self.column_spacing),
                             top=column_top,
                             width=column_width,
                             bottom=footnote_space.top)
            for i in range(num_cols)
        ]
        for column in self.columns:
            column._footnote_space = footnote_space

        if header and document_part.header:
            header_bottom = self.body.top - self.header_footer_distance
            self.header = UpExpandingContainer('header',
                                               self,
                                               left=h_margin,
                                               bottom=header_bottom,
                                               width=body_width)
            self.header.append_flowable(Header(document_part.header))
            self.header.append_flowable(HorizontalRule(style='header'))
        if footer and document_part.footer:
            footer_vpos = self.body.bottom + self.header_footer_distance
            self.footer = DownExpandingContainer('footer',
                                                 self,
                                                 left=h_margin,
                                                 top=footer_vpos,
                                                 width=body_width)
            self.footer.append_flowable(HorizontalRule(style='footer'))
            self.footer.append_flowable(Footer(document_part.footer))