From 068ed6f678e6ff2369e51d927f6ecee2a0ba2825 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Thu, 20 Dec 2012 21:57:42 +0000 Subject: cache cairo surfaces instead of pixbufs --- diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 2e45ff9..ef34226 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -20,6 +20,7 @@ #THE SOFTWARE. import gtk +import cairo from gettext import gettext as _ from taconstants import EXPANDABLE, EXPANDABLE_ARGS, OLD_NAMES, CONSTANTS, \ @@ -1091,13 +1092,27 @@ class Block: self._set_colors(svg) self.svg.set_gradient(True, GRADIENT_COLOR) if arg is None: - self.shapes[0] = svg_str_to_pixbuf(function()) + pixbuf = svg_str_to_pixbuf(function()) else: - self.shapes[0] = svg_str_to_pixbuf(function(arg)) + pixbuf = svg_str_to_pixbuf(function(arg)) self.width = self.svg.get_width() self.height = self.svg.get_height() + self.shapes[0] = _pixbuf_to_cairo_surface(pixbuf, + self.width, self.height) self.svg.set_gradient(False) if arg is None: - self.shapes[1] = svg_str_to_pixbuf(function()) + pixbuf = svg_str_to_pixbuf(function()) else: - self.shapes[1] = svg_str_to_pixbuf(function(arg)) + pixbuf = svg_str_to_pixbuf(function(arg)) + self.shapes[1] = _pixbuf_to_cairo_surface(pixbuf, + self.width, self.height) + +def _pixbuf_to_cairo_surface(image, width, height): + surface = cairo.ImageSurface( + cairo.FORMAT_ARGB32, int(width), int(height)) + context = cairo.Context(surface) + context = gtk.gdk.CairoContext(context) + context.set_source_pixbuf(image, 0, 0) + context.rectangle(0, 0, int(width), int(height)) + context.fill() + return surface -- cgit v0.9.1