[Sugar-devel] [PATCH sugar-toolkit-gtk3] Do the preview in the activity using cairo intead of GdkPixbufa -v2

Manuel Quiñones manuq at laptop.org
Fri Feb 10 15:16:39 EST 2012


That does the job, great!  I will change Browse accordingly.  It will
be similar than this, but I have to remove the tabs there too.

El día 10 de febrero de 2012 16:39,  <godiard at sugarlabs.org> escribió:
> From: Gonzalo Odiard <godiard at gmail.com>
>
> Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>

Reviewed-by: Manuel Quiñones <manuq at laptop.org>

>
> -------
>
> v2: Create the image without the toolbar
> ---
>  src/sugar3/activity/activity.py |   39 ++++++++++++++++++++++++---------------
>  1 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/src/sugar3/activity/activity.py b/src/sugar3/activity/activity.py
> index 19c1974..8c1200c 100644
> --- a/src/sugar3/activity/activity.py
> +++ b/src/sugar3/activity/activity.py
> @@ -54,11 +54,12 @@ import os
>  import time
>  from hashlib import sha1
>  from functools import partial
> +import StringIO
>
>  from gi.repository import GConf
>  from gi.repository import Gtk
>  from gi.repository import Gdk
> -from gi.repository import GdkPixbuf
> +import cairo
>  from gi.repository import GObject
>  import dbus
>  import dbus.service
> @@ -642,26 +643,34 @@ class Activity(Window, Gtk.Container):
>         binary content of a png image with a width of 300 and a height of 225
>         pixels.
>         """
> -        if self.canvas is None or not hasattr(self.canvas, 'get_snapshot'):
> +        if self.canvas is None or not hasattr(self.canvas, 'get_window'):
>             return None
> -        pixmap = self.canvas.get_snapshot((-1, -1, 0, 0))
>
> -        width, height = pixmap.get_size()
> -        pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, 0, 8, width, height)
> -        pixbuf = pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
> -                                          0, 0, 0, 0, width, height)
> -        pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
> -                                     GdkPixbuf.InterpType.BILINEAR)
> +        window = self.canvas.get_window()
>
> -        preview_data = []
> +        x, y = 0, 0
> +        width, height = window.get_width(), window.get_height()
>
> -        def save_func(buf, data):
> -            data.append(buf)
> +        if not self.canvas.get_has_window():
> +            alloc = self.canvas.get_allocation()
> +            x, y = alloc.x, alloc.y
> +            width, height = alloc.width, alloc.height
>
> -        pixbuf.save_to_callback(save_func, 'png', user_data=preview_data)
> -        preview_data = ''.join(preview_data)
> +        preview_width, preview_height = style.zoom(300), style.zoom(225)
>
> -        return preview_data
> +        preview_surface = Gdk.Window.create_similar_surface(window,
> +            cairo.CONTENT_COLOR, preview_width, preview_height)
> +
> +        cairo_context = cairo.Context(preview_surface)
> +        preview_scale_w = preview_width * 1.0 / width
> +        preview_scale_h = preview_height * 1.0 / height
> +        cairo_context.scale(preview_scale_w, preview_scale_h)
> +        Gdk.cairo_set_source_window(cairo_context, window, -x, -y)
> +        cairo_context.paint()
> +
> +        preview_str = StringIO.StringIO()
> +        preview_surface.write_to_png(preview_str)
> +        return preview_str.getvalue()
>
>     def _get_buddies(self):
>         if self.shared_activity is not None:
> --
> 1.7.7.6
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel



-- 
.. manuq ..


More information about the Sugar-devel mailing list