Exemple #1
0
def test_rect():

    r = Rect(12, 340, 80, 60)

    assert r.x == 12
    assert r.y == 340
    assert r.width == 80
    assert r.height == 60

    assert r.x2 == 92
    assert r.y2 == 400

    assert r.middle_x == 52
    assert r.middle_y == 370

    assert r.position == (12, 340)
    assert r.size == (80, 60)

    r2 = r.shrink(2, 0, 20, 5)
    assert r2.x == 14
    assert r2.y == 360
    assert r2.width == 78
    assert r2.height == 35

    r3 = Rect(14, 360, 78, 35)
    assert r2 == r3
    assert r != r3
Exemple #2
0
 def render_separator(self, ctx, rect, separator):
     thickness = separator.thickness
     if thickness is None:
         thickness = self.separator_thickness
     if separator.horizontal:
         r = Rect(rect.x, rect.y, rect.width, thickness)
     else:
         r = Rect(rect.x, rect.y, thickness, rect.height)
     ctx.renderer.draw_rect(r, self.separator_color)
Exemple #3
0
 def render_frame(self, ctx, rect, frame):
     ctx.renderer.draw_rect(rect, self.frame_bg_color)
     r = Rect(rect.x, rect.y, rect.width, 60)
     ctx.renderer.draw_rect(r, self.frame_title_color)
     style = self._get_text_style(ctx, "frame_title")
     self.draw_text(ctx, rect.x + rect.width - 20, rect.y + 5, frame.title,
                    style)
     rect = rect.shrink(0, 0, 80, 0)
     frame.box.render(ctx, rect)
Exemple #4
0
 def _draw_line_emphasis(self, ctx, rect, style, emphasis, default_color):
     for line_numbers, (start, end), color in emphasis:
         if start <= ctx.step and (end is None or ctx.step <= end):
             if color is None:
                 color = default_color
             for line_number in line_numbers:
                 offset_x, offset_y = self.get_text_offset(style)
                 line_size = style.size * style.line_spacing
                 y = rect.y + offset_y + line_size * (line_number - 1)
                 r = Rect(rect.x, y, rect.width, line_size + offset_y)
                 ctx.renderer.draw_rect(r, color)
Exemple #5
0
def test_svg_rect():
    r = RendererSVG()
    r.begin(300, 300)

    rc = Rect(0, 0, 100, 300)
    r.draw_rect(rc, "red")

    rc = Rect(100, 0, 100, 300)
    r.draw_rect(rc, "green")

    rc = Rect(20, 50, 260, 40)
    r.draw_rect(rc, fill_color="white", color="#000055", stroke_width=20)

    rc = Rect(20, 150, 260, 40)
    r.draw_rect(rc,
                fill_color="white",
                color="#000055",
                stroke_width=20,
                rx=50,
                ry=20)

    r.end()
    r.write(utils.output_name("rect.svg"))
Exemple #6
0
 def _make_rects_horizontal(self, ctx, rect, elements, padding, fill_y,
                            callback_fn):
     requests = self._get_size_requests(ctx, elements)
     width = sum(rq.width for rq in requests) + len(elements) * padding
     fill_x = sum(rq.fill_x for rq in requests)
     results = []
     assert fill_x == 0
     x = rect.x + (rect.width - width) / 2.0
     for rq, e in zip(requests, elements):
         if rq.fill_y or fill_y:
             h = rect.height
             y = rect.y
         else:
             h = rq.height
             y = rect.y + (rect.height - rq.height) / 2.0
         w = rq.width
         callback_fn(e, Rect(x, y, w, h))
         x += w + padding
     return results
Exemple #7
0
    def _make_rects_vertical(self, ctx, rect, elements, padding, fill_x,
                             callback_fn):
        requests = self._get_size_requests(ctx, elements)
        height = sum(rq.height for rq in requests) + len(elements) * padding
        fill_y = sum(rq.fill_y for rq in requests)
        results = []
        assert fill_y == 0

        y = rect.y + (rect.height - height) / 2.0
        for rq, e in zip(requests, elements):
            if rq.fill_x or fill_x:
                w = rect.width
                x = rect.x
            else:
                w = rq.width
                x = rect.x + (rect.width - rq.width) / 2.0
            h = rq.height
            callback_fn(e, Rect(x, y, w, h))
            y += h + padding
        return results
Exemple #8
0
    def render_slide(self, ctx):
        slide = ctx.slide
        renderer = ctx.renderer
        width = renderer.width
        height = renderer.height

        slide_rect = Rect(0, 0, width, height)
        renderer.draw_rect(slide_rect, self.bg_color)

        if slide.role == "title":
            title = slide.title
            if title is None:
                title = ""

            style = self.main_title_style
            rect = Rect(0, height / 2 - style.size * 1.2, width,
                        style.size * 2.4)
            renderer.draw_rect(rect, self.minor_color)
            rect = Rect(0, height / 2 - style.size, width, style.size * 2)
            renderer.draw_rect(rect, self.major_color)
            self.draw_text(ctx, width / 2, height / 2 - style.size * 0.8,
                           slide.title, style)
            top = height / 2 + style.size
            slide_rect = Rect(0, top, width, height - top)
            ctx.slide.element.render(ctx, slide_rect)
            return

        if slide.title is None:
            ctx.slide.element.render(ctx, slide_rect)
            return

        top = 80
        rect = Rect(0, 0, width, top)
        renderer.draw_rect(rect, self.major_color)

        rect = Rect(0, top - 10, width, 10)
        renderer.draw_rect(rect, self.minor_color)

        self.draw_text(ctx, width - 40, 10, ctx.slide.title, self.title_style)
        rect = Rect(0, top, width, height - top)
        ctx.slide.element.render(ctx, rect)