コード例 #1
0
 def render(self, graphics, width = None, height = None, x_offset = 0, y_offset = 0):
     graphics.save_context( )
     graphics.translate( x_offset, y_offset )
     graphics.rectangle( 0, 0, width or self.width, height or self.height)
     graphics.clip()
     graphics.set_source_surface(self.image_data)
     graphics.paint()
     graphics.restore_context()
コード例 #2
0
ファイル: image.py プロジェクト: Geotexan/experiments
        def put_pattern(image, x, y, w, h):
            pattern = cairo.SurfacePattern(image[0])

            if w > 0 and h > 0:
                pattern.set_matrix(cairo.Matrix(x0=1, y0=1, xx = (image[1]) / float(w), yy = (image[2]) / float(h)))
                graphics.save_context()
                graphics.translate(x, y)
                graphics.set_source(pattern)
                graphics.rectangle(0, 0, w, h)
                graphics.fill()
                graphics.restore_context()
コード例 #3
0
        def put_pattern(image, x, y, w, h):
            pattern = cairo.SurfacePattern(image[0])

            if w > 0 and h > 0:
                pattern.set_matrix(
                    cairo.Matrix(x0=1,
                                 y0=1,
                                 xx=(image[1]) / float(w),
                                 yy=(image[2]) / float(h)))
                graphics.save_context()
                graphics.translate(x, y)
                graphics.set_source(pattern)
                graphics.rectangle(0, 0, w, h)
                graphics.fill()
                graphics.restore_context()
コード例 #4
0
        def put_pattern(image, x, y, w, h):
            if w <= 0 or h <= 0:
                return

            graphics.save_context()


            if not self.stretch_w or not self.stretch_h:
                # if we repeat then we have to cut off the top-left margin
                # that we put in there so that stretching does not borrow white
                # pixels
                img = cairo.ImageSurface(cairo.FORMAT_ARGB32, image[1], image[2])
                ctx = cairo.Context(img)
                ctx.set_source_surface(image[0],
                                       0 if self.stretch_w else -1,
                                       0 if self.stretch_h else -1)
                ctx.rectangle(0, 0, image[1], image[2])
                ctx.clip()
                ctx.paint()
            else:
                img = image[0]

            pattern = cairo.SurfacePattern(img)
            pattern.set_extend(cairo.EXTEND_REPEAT)
            pattern.set_matrix(cairo.Matrix(x0 = 1 if self.stretch_w else 0,
                                            y0 = 1 if self.stretch_h else 0,
                                            xx = (image[1]) / float(w) if self.stretch_w else 1,
                                            yy = (image[2]) / float(h) if self.stretch_h else 1))
            pattern.set_filter(self.stretch_filter_mode)

            # truncating as fill on half pixel will lead to nasty gaps
            graphics.translate(int(x + x_offset), int(y + y_offset))
            graphics.set_source(pattern)
            graphics.rectangle(0, 0, int(w), int(h))
            graphics.clip()
            graphics.paint()
            graphics.restore_context()
コード例 #5
0
    def render(self, graphics, width, height, x_offset=0, y_offset=0):
        """renders the image in the given graphics context with the told width
        and height"""
        def put_pattern(image, x, y, w, h):
            if w <= 0 or h <= 0:
                return

            graphics.save_context()


            if not self.stretch_w or not self.stretch_h:
                # if we repeat then we have to cut off the top-left margin
                # that we put in there so that stretching does not borrow white
                # pixels
                img = cairo.ImageSurface(cairo.FORMAT_ARGB32, image[1], image[2])
                ctx = cairo.Context(img)
                ctx.set_source_surface(image[0],
                                       0 if self.stretch_w else -1,
                                       0 if self.stretch_h else -1)
                ctx.rectangle(0, 0, image[1], image[2])
                ctx.clip()
                ctx.paint()
            else:
                img = image[0]

            pattern = cairo.SurfacePattern(img)
            pattern.set_extend(cairo.EXTEND_REPEAT)
            pattern.set_matrix(cairo.Matrix(x0 = 1 if self.stretch_w else 0,
                                            y0 = 1 if self.stretch_h else 0,
                                            xx = (image[1]) / float(w) if self.stretch_w else 1,
                                            yy = (image[2]) / float(h) if self.stretch_h else 1))
            pattern.set_filter(self.stretch_filter_mode)

            # truncating as fill on half pixel will lead to nasty gaps
            graphics.translate(int(x + x_offset), int(y + y_offset))
            graphics.set_source(pattern)
            graphics.rectangle(0, 0, int(w), int(h))
            graphics.clip()
            graphics.paint()
            graphics.restore_context()


        graphics.save_context()

        left, right, = self.left, self.right
        top, bottom = self.top, self.bottom

        # top-left
        put_pattern(self.slices[0], 0, 0, left, top)

        # top center - repeat width
        put_pattern(self.slices[1], left, 0, width - left - right, top)

        # top-right
        put_pattern(self.slices[2], width - right, 0, right, top)

        # left - repeat height
        put_pattern(self.slices[3], 0, top, left, height - top - bottom)

        # center - repeat width and height
        put_pattern(self.slices[4], left, top, width - left - right, height - top - bottom)

        # right - repeat height
        put_pattern(self.slices[5], width - right, top, right, height - top - bottom)

        # bottom-left
        put_pattern(self.slices[6], 0, height - bottom, left, bottom)

        # bottom center - repeat width
        put_pattern(self.slices[7], left, height - bottom, width - left - right, bottom)

        # bottom-right
        put_pattern(self.slices[8], width - right, height - bottom, right, bottom)

        graphics.rectangle(x_offset, y_offset, width, height)
        graphics.new_path()

        graphics.restore_context()