Example #1
0
    def canvas(self, margin=0, border=False, clip=False):
        """
        Return a canvas object for the whole page except a predefined
        set of margins.

        The margin parameter may be either:

          - an integer - all four margins the same
          - a pair - ( horizontal, vertical, )
          - a 4-tuple - ( left, top, right, bottom, )

        """

        if type(margin) == tuple:
            if len(margin) == 2:
                h, v = margin
                margin = ( h, v, h, v, )
        else:
            m = float(margin)
            margin = ( m, m, m, m, )

        l, t, r, b = margin

        from psg.drawing.box import canvas
        ret = canvas(self, l, b,
                     self.w() - r - l, self.h() - t - b,
                     border, clip)

        return ret
Example #2
0
    def render(self, layout_box):

        if self.splitable:
            # Check if there is room in the layout box for at least one line
            min_height = self.style.v_padding() + self.style.v_margin() + \
                         self.style.font_size * self.style.line_height
        else:
            min_height = self.height(layout_box.w())

        if layout_box.y_cursor() < min_height:
            return self

        needed_height = self.height(layout_box.w())

        if layout_box.y_cursor() < needed_height:
            height = layout_box.y_cursor()
        else:
            height = needed_height

        margin_box = canvas(
            layout_box,
            self.style.margin_left,
            layout_box.y_cursor() - height + self.style.margin_bottom,
            layout_box.w() - self.style.h_margin(),
            height - self.style.v_margin(),
            debug.verbose)

        layout_box.append(margin_box)

        self.border_and_background(margin_box)


        if self.style.hv_padding() == 0:
            x = 0
            y = 0
            w = margin_box.w()
            h = margin_box.h()
        else:
            x = self.style.padding_left
            y = self.style.padding_bottom
            w = margin_box.w() - self.style.h_padding()
            h = margin_box.h() - self.style.v_padding()

        if self.style.font.metrics.descender is not None:
            y -= float(self.style.font.metrics.descender) \
                 * self.style.font_size / 1000

        # Create a textbox
        rest = self.typeset(margin_box, x, y, w, h)

        if rest != "":
            rest = div(rest, self.style)
        else:
            rest = None

        layout_box.y_advance(min(height, layout_box.y_cursor()))

        return rest
Example #3
0
    def render(self, layout_box):

        if self.splitable:
            # Check if there is room in the layout box for at least one line
            min_height = self.style.v_padding() + self.style.v_margin() + \
                         self.style.font_size * self.style.line_height
        else:
            min_height = self.height(layout_box.w())

        if layout_box.y_cursor() < min_height:
            return self

        needed_height = self.height(layout_box.w())

        if layout_box.y_cursor() < needed_height:
            height = layout_box.y_cursor()
        else:
            height = needed_height

        margin_box = canvas(
            layout_box, self.style.margin_left,
            layout_box.y_cursor() - height + self.style.margin_bottom,
            layout_box.w() - self.style.h_margin(),
            height - self.style.v_margin(), debug.verbose)

        layout_box.append(margin_box)

        self.border_and_background(margin_box)

        if self.style.hv_padding() == 0:
            x = 0
            y = 0
            w = margin_box.w()
            h = margin_box.h()
        else:
            x = self.style.padding_left
            y = self.style.padding_bottom
            w = margin_box.w() - self.style.h_padding()
            h = margin_box.h() - self.style.v_padding()

        if self.style.font.metrics.descender is not None:
            y -= float(self.style.font.metrics.descender) \
                 * self.style.font_size / 1000

        # Create a textbox
        rest = self.typeset(margin_box, x, y, w, h)

        if rest != "":
            rest = div(rest, self.style)
        else:
            rest = None

        layout_box.y_advance(min(height, layout_box.y_cursor()))

        return rest
Example #4
0
def thumb_box_factory(output_document, paper_size_name, margin_width,
                      thumbs_per_page, thumb_width, thumb_height,thumb_spacing,
                      verbose, **kw):
    while True:
        page = output_document.page(page_size=paper_size_name)
        canvas = page.canvas(margin_width, border=False)

        for a in range(thumbs_per_page-1, -1, -1):
            thumb_box = box.canvas(canvas,
                                   0, a * ( thumb_height + thumb_spacing ),
                                   thumb_width, thumb_height,
                                   border=verbose, clipping=True)
            canvas.append(thumb_box)
            yield thumb_box
Example #5
0
def thumb_box_factory(output_document, paper_size_name, margin_width,
                      thumbs_per_page, thumb_width, thumb_height,
                      thumb_spacing, verbose, **kw):
    while True:
        page = output_document.page(page_size=paper_size_name)
        canvas = page.canvas(margin_width, border=False)

        for a in range(thumbs_per_page - 1, -1, -1):
            thumb_box = box.canvas(canvas,
                                   0,
                                   a * (thumb_height + thumb_spacing),
                                   thumb_width,
                                   thumb_height,
                                   border=verbose,
                                   clipping=True)
            canvas.append(thumb_box)
            yield thumb_box