Example #1
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()
Example #2
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()
Example #3
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()