Exemple #1
0
    def typeset(self, parent_box, x, y, w, h):
        left_width, right_width = self.widths(w)
        
        line_spacing = ( self.style.line_height * self.style.font_size ) - \
                       self.style.font_size


        tb = textbox(parent_box, x, y, left_width, h, border=debug.verbose)
        parent_box.append(tb)
        
        tb.set_font(font = self.style.font,
                    font_size = self.style.font_size,
                    kerning = True,
                    alignment = self.style.text_align,
                    char_spacing = self.style.char_spacing,
                    line_spacing = line_spacing)


        if self.style.color is not None:
            print >> tb, self.style.color
            
        tb.typeset(self.left)
        
        tb = textbox(parent_box,
                     left_width, y, right_width, h,
                     border=debug.verbose)
        parent_box.append(tb)
        
        tb.set_font(font = self.style.font,
                    font_size = self.style.font_size,
                    kerning = True,
                    alignment = self.style.text_align,
                    char_spacing = self.style.char_spacing,
                    line_spacing = line_spacing)


        if self.style.color is not None:
            print >> tb, self.style.color
            
        tb.typeset(self.right)

        return ""
Exemple #2
0
    def draw(self, canvas):
        if canvas.h() < self.minimum_height(null_canvas(canvas)):
           raise ValueError("The canvas provided was smaller than the "
                             "minimum required vertical space.")

        self.split_lines(canvas)
        tb = box.textbox(canvas, 0, 0, canvas.w(), canvas.h(),
                         border=False)        
        canvas.append(tb)

        line_spacing = ( self.style.line_height * self.style.font_size ) - \
                       self.style.font_size
        
        self.style.set_font(tb)
        
        if self.style.color is not None:
            print >> tb, self.style.color

        room_for = int(canvas.h() /
                       (self.style.font_size * self.style.line_height))
        if room_for >= len(self.lines):
            lines = self.lines
            self.lines = []
        elif room_for == len(self.lines)-1:
            lines = self.lines[:-2]
            self.lines = self.lines[-2:]
        else:
            lines = self.lines[:room_for]
            self.lines = self.lines[room_for:]

        for line in lines:
            if len(line) > 0 and line[-1] == True:
                line = line[:-1]
                last_line = True
            else:
                last_line = False
                
            tb.typeset_line(line, last_line)

            if not last_line:
                try:
                    tb.newline()
                except EndOfBox:
                    pass
            
        return ( tb.text_height(), len(self.lines) == 0, )
Exemple #3
0
    def typeset(self, parent_box, x, y, w, h):
        line_spacing = ( self.style.line_height * self.style.font_size ) - \
                       self.style.font_size

        tb = textbox(parent_box, x, y, w, h, border=debug.verbose)
        parent_box.append(tb)
        
        tb.set_font(font = self.style.font,
                    font_size = self.style.font_size,
                    kerning = True,
                    alignment = self.style.text_align,
                    char_spacing = self.style.char_spacing,
                    line_spacing = line_spacing)

        if self.style.color is not None:
            print >> tb, self.style.color

        return tb.typeset(join(self.words(), u" "))        
Exemple #4
0
def new_page(document, background, italic):
    """
    This is the generator I was talking about in the comment to the
    layout() function above.
    """
    while True:
        page = document.page("a4", None)
        page.append(background)

        left = layout_box(page, mm(40), mm(25), mm(75), mm(242.99),
                          debug.verbose)
        right = layout_box(page, mm(124.75), mm(25), mm(75), mm(242.99),
                           debug.verbose)

        stand = textbox(page, mm(40), mm(19), mm(100), 7)
        stand.set_font(italic, 7)
        page.append(stand)
        stand.typeset(u"Stand: " + unicode(date.today().strftime("%d.%m.%Y")))

        page.append(left)
        yield left
        
        page.append(right)
        yield right