diff options
author | Simon Schampijer <simon@laptop.org> | 2012-08-30 12:36:05 (GMT) |
---|---|---|
committer | Simon Schampijer <simon@laptop.org> | 2012-08-30 12:36:05 (GMT) |
commit | 3fc7028617fe423e0e5424407f7b652dc550c76c (patch) | |
tree | 6688176f1c328c40dcb78d526f22e92206f2c2ff | |
parent | 29791a56cf5aa40c0ec14d42610a215a3be999be (diff) |
Journal detail view: draw the thumbnail without using a Gdk.Pixmap
Code based on the one in get_preview in toolkit-gtk3 and the
one in Browse for the linkbutton.
-rw-r--r-- | src/jarabe/journal/expandedentry.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py index f1ad35a..e6bbbdc 100644 --- a/src/jarabe/journal/expandedentry.py +++ b/src/jarabe/journal/expandedentry.py @@ -218,16 +218,31 @@ class ExpandedEntry(Gtk.EventBox): png_file = StringIO.StringIO(preview_data) try: # Load image and scale to dimensions + im = Gtk.Image() surface = cairo.ImageSurface.create_from_png(png_file) png_width = surface.get_width() png_height = surface.get_height() - pixmap = Gdk.Pixmap(None, png_width, png_height, 24) - cr = pixmap.cairo_create() - cr.set_source_surface(surface, 0, 0) - cr.scale(width / png_width, height / png_height) + + preview_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, + width, height) + cr = cairo.Context(preview_surface) + + scale_w = width * 1.0 / png_width + scale_h = height * 1.0 / png_height + scale = min(scale_w, scale_h) + + cr.scale(scale, scale) + + cr.set_source_rgba(1, 1, 1, 0) + cr.set_operator(cairo.OPERATOR_SOURCE) + cr.paint() + cr.set_source_surface(surface) cr.paint() - im = Gtk.image_new_from_pixmap(pixmap, None) + pixbuf_bg = Gdk.pixbuf_get_from_surface(preview_surface, 0, 0, + width, height) + im.set_from_pixbuf(pixbuf_bg) + has_preview = True except Exception: logging.exception('Error while loading the preview') |