Пример #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
        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()