Пример #1
0
    def clip_to_rect(self, x, y, w, h):
        """ Clip context to the given rectangular region.

            Region should be a 4-tuple or a sequence.
        """
        tx, ty = self.transform.tx, self.transform.ty
        self.canvas_state.clip_box = agg.Rect(tx + x, ty + y, w, h)
Пример #2
0
    def __init__(self, size, *args, **kwargs):
        super().__init__()
        self._width = size[0]
        self._height = size[1]
        self.pix_format = kwargs.get('pix_format', 'bgra32')

        shape = (self._height, self._width, 4)
        buffer = np.zeros(shape, dtype=np.uint8)
        canvas_klass = pix_format_canvases[self.pix_format]
        self.gc = canvas_klass(buffer, bottom_up=True)
        self.marker_gc = MarkerRenderer(
            buffer, pix_format=self.pix_format, bottom_up=True
        )

        # init the state variables
        clip = agg.Rect(0, 0, self._width, self._height)
        self.canvas_state = agg.GraphicsState(clip_box=clip)
        self.stroke_paint = agg.SolidPaint(0.0, 0.0, 0.0)
        self.fill_paint = agg.SolidPaint(0.0, 0.0, 0.0)
        self.path = CompiledPath()
        self.text_transform = agg.Transform()
        self.text_pos = (0.0, 0.0)
        self.transform = agg.Transform()
        self.font = None
        self.__state_stack = []

        # For HiDPI support
        self.base_scale = kwargs.pop('base_pixel_scale', 1)
        self.transform.scale(self.base_scale, self.base_scale)

        # Make this look like a kiva.agg GC
        self.bmp_array = buffer
Пример #3
0
    def clip_to_rect(self, x, y, w, h):
        """ Clip context to the given rectangular region.

            Region should be a 4-tuple or a sequence.
        """
        # The passed in rect should be transformed.
        # NOTE: Rotations will have an undefined result
        x0, y0 = self.transform.worldToScreen(x, y)
        x1, y1 = self.transform.worldToScreen(x + w, y + h)
        w, h = abs(x1 - x0), abs(y1 - y0)
        self.canvas_state.clip_box = agg.Rect(x0, y0, w, h)
Пример #4
0
    def _clip_impl(self, shape, drawing_mode):
        """ Internal implementation for the complex clipping methods.
        """
        size = (self._height, self._width)
        stencil = agg.CanvasG8(np.empty(size, dtype=np.uint8), bottom_up=True)
        stencil.clear(0.0, 0.0, 0.0)

        clip_box = agg.Rect(0, 0, self._width, self._height)
        gs = agg.GraphicsState(drawing_mode=drawing_mode, clip_box=clip_box)
        paint = agg.SolidPaint(1.0, 1.0, 1.0)
        stencil.draw_shape(shape, self.transform, gs, stroke=paint, fill=paint)

        self.canvas_state.stencil = stencil.image
Пример #5
0
    def __init__(self, size, *args, **kwargs):
        super(GraphicsContext, self).__init__()
        self._width = size[0]
        self._height = size[1]
        self.pix_format = kwargs.get('pix_format', 'rgba32')

        shape = (self._height, self._width, 4)
        canvas_klass = pix_format_canvases[self.pix_format]
        self.gc = canvas_klass(np.zeros(shape, dtype=np.uint8), bottom_up=True)

        # init the state variables
        clip = agg.Rect(0, 0, self._width, self._height)
        self.canvas_state = agg.GraphicsState(clip_box=clip)
        self.stroke_paint = agg.SolidPaint(0.0, 0.0, 0.0)
        self.fill_paint = agg.SolidPaint(0.0, 0.0, 0.0)
        self.path = CompiledPath()
        self.text_transform = agg.Transform()
        self.text_pos = (0.0, 0.0)
        self.transform = agg.Transform()
        self.font = None
        self.__state_stack = []