Ejemplo n.º 1
0
    def draw(self, canvas: Canvas):
        min_x = self.margin_left.pt
        min_y = self.margin_top.pt
        max_x = canvas.width - self.margin_right.pt
        max_y = canvas.height - self.margin_bottom.pt

        exterior_shape = Polygon([(0, 0), (canvas.width, 0),
                                  (canvas.width, canvas.height),
                                  (0, canvas.height), (0, 0)], [
                                      list(
                                          reversed([(min_x, min_y),
                                                    (max_x, min_y),
                                                    (max_x, max_y),
                                                    (min_x, max_y),
                                                    (min_x, min_y)]))
                                  ])

        if self.stroke_width is not None:
            interior_outline = Polygon([(min_x, min_y), (max_x, min_y),
                                        (max_x, max_y), (min_x, max_y),
                                        (min_x, min_y)])
            canvas.context.set_line_width(self.stroke_width.pt)
            canvas.context.set_source_rgba(*self.stroke_color)
            CairoHelper.draw_polygon(canvas.context, interior_outline)
            canvas.context.stroke()

        canvas.context.set_source_rgba(*self.fill_color)
        CairoHelper.draw_polygon(canvas.context, exterior_shape)
        canvas.context.fill()
Ejemplo n.º 2
0
 def draw_symbol(self, key, point: Point, canvas: Canvas):
     canvas.context.set_source_rgba(point.x/100, point.y/100, 0, 1)
     CairoHelper.draw_point(
         canvas.context,
         point,
         Cu.from_pt(key).pt
     )
Ejemplo n.º 3
0
 def draw_polygon(self, canvas: Canvas, polygon: Polygon):
     CairoHelper.draw_polygon(canvas.context, polygon)
     if self._has_fill() and self._has_stroke():
         canvas.context.set_source_rgba(*self.fill_color)
         canvas.context.fill_preserve()
     elif self._has_fill():
         canvas.context.set_source_rgba(*self.fill_color)
         canvas.context.fill()
     if self._has_stroke():
         canvas.context.set_line_width(self.stroke_width.pt)
         canvas.context.set_source_rgba(*self.stroke_color)
         canvas.context.stroke()
Ejemplo n.º 4
0
    def draw(self, canvas: Canvas):
        top_left = (0, 0)
        top_right = (canvas.width, 0)
        bottom_left = (0, canvas.height)
        bottom_right = (canvas.width, canvas.height)

        background_shape = Polygon(
            [top_left, top_right, bottom_right, bottom_left, top_left])

        canvas.context.set_source_rgba(*self.color)
        CairoHelper.draw_polygon(canvas.context, background_shape)
        canvas.context.fill()
Ejemplo n.º 5
0
    def draw_rectangle(self, canvas: Canvas, offset: int, unit: str):
        height = CanvasUnit.from_pt(10).pt
        width = CanvasUnit.from_unit(1, unit).pt
        offset_height = height * offset
        top_left = (0, offset_height)
        top_right = (width, offset_height)
        bottom_left = (0, offset_height + height)
        bottom_right = (width, offset_height + height)

        shape = Polygon([
            top_left,
            top_right,
            bottom_right,
            bottom_left,
            top_left
        ])

        canvas.context.set_source_rgba(*self.color)
        CairoHelper.draw_polygon(canvas.context, shape)
        canvas.context.set_source_rgba(0.5, 0.5, 0.5, 1)
        canvas.context.fill()
    def draw_rectangle_top_left(canvas: Canvas, unit: str):
        if unit in ['in', 'cm']:
            # Setting to a smaller size to avoid disk space issues
            midpoint = CanvasUnit.from_unit(2, unit).pt
        else:
            midpoint = CanvasUnit.from_unit(50, unit).pt
        top_left = (0, 0)
        top_right = (midpoint, 0)
        bottom_left = (0, midpoint)
        bottom_right = (midpoint, midpoint)

        shape = Polygon(
            [top_left, top_right, bottom_right, bottom_left, top_left])

        canvas.context.set_source_rgb(0, 0, 0)
        CairoHelper.draw_polygon(canvas.context, shape)
        canvas.context.fill()

        point_unit_shape = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])

        canvas.context.set_source_rgb(1, 0, 0)
        CairoHelper.draw_polygon(canvas.context, point_unit_shape)
        canvas.context.fill()
Ejemplo n.º 7
0
 def draw_line_string(canvas: Canvas, line_string: LineString):
     CairoHelper.draw_line_string(canvas.context, line_string)
     canvas.context.stroke()