Ejemplo n.º 1
0
    def drawRectangle(self, x1=None, y1=None, x2=None, y2=None, width=None, height=None, cursor1=None, cursor2=None, style='S'):
        if cursor1 is not None:
            if cursor2 is not None:
                pass
            elif width is not None and height is not None:
                dims = PDFCursor(width, height)
                cursor2 = cursor1.add(dims)
            elif x2 is not None and y2 is not None:
                cursor2 = PDFCursor(x2, y2)
            else:
                raise Exception("Rectanlge not defined")
        else:
            if x1 is not None and y1 is not None:
                cursor1 = PDFCursor(x1, y1)
                if x2 is not None and y2 is not None:
                    cursor2 = PDFCursor(x2, y2)
                elif width is not None and height is not None:
                    dims = PDFCursor(width, height)
                    cursor2 = cursor1.add(dims)
                else:
                    raise Exception("Rectanlge not defined")
            else:
                raise Exception("Rectanlge not defined")

        rect = PDFRectangle(self.SS, self.page, self.colorscheme, cursor1, cursor2, size=1, style=style)
        rect.draw()
Ejemplo n.º 2
0
 def set_background_image(self, image):
     background_cursor = PDFCursor(0, 0)
     background_cursor.set_bounds(xmin=0,
                                  ymin=0,
                                  xmax=self.page.width,
                                  ymax=self.page.height,
                                  ymaxmax=self.page.height)
     myimage = self.add_image(image)
     self.draw_image(myimage, background_cursor, width=self.page.width)
Ejemplo n.º 3
0
    def _add_page_number(self, page, number_of_pages):
        if self.page_numbers_font is not None:
            fs = 'BT /F%d %.2f Tf ET' % (self.page_numbers_font.index,
                                         self.page_numbers_font.font_size)
            self.session._out(fs, page)

        if self.page_numbers_color is not None:
            self.page_numbers_color._set_type('t')
            self.session._out(self.page_numbers_color._get_color_string(),
                              page)

        text_string = self.page_numbers_text1 % (page.index + 1)
        if self.page_numbers_text2 is not None:
            text_string += self.page_numbers_text2 % number_of_pages

        if self.page_numbers_cursor is None:
            sw = self.font._string_width(text_string)
            y = page.page_size[1]
            y = y - self.page.margin.bottom

            if self.page_numbers == 'left':
                x = self.page.margin.left
            elif self.page_numbers == 'right':
                x = page.page_size[0] - page.margin.right - sw
            else:
                x = page.page_size[0] / 2 - int(sw / 2.0)
            cursor = PDFCursor(x, y)
        else:
            cursor = self.page_numbers_cursor

        text_string = '(%s)' % text_string
        s = 'BT %.2f %.2f Td %s Tj ET' % (cursor.x, cursor.y_prime,
                                          text_string)
        self.session._out(s, page)
Ejemplo n.º 4
0
 def set_cursor(self, x=None, y=None):
     if x is not None and isinstance(x, PDFCursor):
         self.page.cursor = x
     elif x is not None and y is not None:
         self.page.cursor = PDFCursor(x, y, True)
     else:
         raise Exception("Invalid cursor input")
Ejemplo n.º 5
0
    def draw_rectangle(self,
                       x1=None,
                       y1=None,
                       x2=None,
                       y2=None,
                       width=None,
                       height=None,
                       cursor1=None,
                       cursor2=None,
                       style='S',
                       stroke="solid",
                       size=1):
        if cursor1 is not None:
            if cursor2 is not None:
                pass
            elif width is not None and height is not None:
                dims = PDFCursor(width, height)
                cursor2 = cursor1 + dims
            elif x2 is not None and y2 is not None:
                cursor2 = PDFCursor(x2, y2)
            else:
                raise Exception("Rectangle not defined")
        else:
            if x1 is not None and y1 is not None:
                cursor1 = PDFCursor(x1, y1)
                if x2 is not None and y2 is not None:
                    cursor2 = PDFCursor(x2, y2)
                elif width is not None and height is not None:
                    dims = PDFCursor(width, height)
                    cursor2 = cursor1 + dims
                elif cursor2 is not None:
                    pass
                else:
                    raise Exception("Rectangle not defined")
            else:
                raise Exception("Rectangle not defined")

        rectangle = PDFRectangle(self.session, self.page, cursor1, cursor2,
                                 self.draw_color, self.fill_color, style,
                                 stroke, size)

        rectangle._draw()
Ejemplo n.º 6
0
    def test_get_angle(self):
        center = PDFCursor(300, 300)
        radius = 30
        start_angle = 45
        arc_angle = 90
        inverted = False
        arc = PDFArc(self.session, self.page, center, radius, start_angle,
                     arc_angle, inverted)
        self.assertEqual(math.degrees(arc._start_angle), 45.0)
        self.assertEqual(math.degrees(arc._end_angle), 135.0)

        inverted = True
        arc = PDFArc(self.session, self.page, center, radius, start_angle,
                     arc_angle, inverted)
        self.assertEqual(math.degrees(arc._start_angle), 135.0)
        self.assertEqual(math.degrees(arc._end_angle), 45.0)

        center = PDFCursor(400, 400)
        start_angle = 0
        arc_angle = 180
        arc = PDFArc(self.session, self.page, center, 40, start_angle,
                     arc_angle, False)
        self.assertEqual(math.degrees(arc._start_angle), 0.0)
        self.assertEqual(math.degrees(arc._end_angle), 180.0)

        arc = PDFArc(self.session, self.page, center, 40, start_angle,
                     arc_angle, True)
        self.assertEqual(math.degrees(arc._start_angle), 180.0)
        self.assertEqual(math.degrees(arc._end_angle), 0.0)

        start_angle = 15
        arc_angle = 405
        arc = PDFArc(self.session, self.page, center, 40, start_angle,
                     arc_angle, False)
        self.assertEqual(round(math.degrees(arc._start_angle)), 15.0)
        self.assertEqual(round(math.degrees(arc._end_angle)), 60.0)

        arc = PDFArc(self.session, self.page, center, 40, start_angle,
                     arc_angle, True)
        self.assertEqual(round(math.degrees(arc._start_angle)), 60.0)
        self.assertEqual(round(math.degrees(arc._end_angle)), 15.0)
Ejemplo n.º 7
0
    def draw_ellipse(self,
                     center_cursor,
                     x_radius,
                     y_radius,
                     border_color=None,
                     fill_color=None,
                     style="S",
                     stroke='solid',
                     size=1):
        radius_cursor = PDFCursor(x_radius, y_radius)
        if isinstance(border_color, PDFColor):
            border_color = border_color
        else:
            border_color = self.draw_color
        if isinstance(fill_color, PDFColor):
            fill_color = fill_color
        else:
            fill_color = self.fill_color

        circle = PDFEllipse(self.session, self.page, center_cursor,
                            radius_cursor, border_color, fill_color, style,
                            stroke, size)
        circle._draw()
Ejemplo n.º 8
0
 def set_background_image(self, image):
     background_cursor = PDFCursor(0, 0)
     background_cursor.set_bounds(xmin=0, ymin=0, xmax=self.page.width, ymax=self.page.height, ymaxmax=self.page.height)
     myimage = self.add_image(image)
     self.draw_image(myimage, background_cursor, width=self.page.width)
Ejemplo n.º 9
0
 def get_new_cursor(self):
     """ Returns a new default cursor """
     return PDFCursor()