[Sugar-devel] [PATCH sugar-toolkit-gtk3] Avoid stretching the preview image.

godiard at sugarlabs.org godiard at sugarlabs.org
Mon Feb 13 09:16:39 EST 2012


From: Gonzalo Odiard <godiard at gmail.com>

This patch apply over "Do the preview in the activity using cairo intead of GdkPixbuf -v2"

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
---
 src/sugar3/activity/activity.py |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/sugar3/activity/activity.py b/src/sugar3/activity/activity.py
index 8c1200c..7b0693b 100644
--- a/src/sugar3/activity/activity.py
+++ b/src/sugar3/activity/activity.py
@@ -664,7 +664,20 @@ class Activity(Window, Gtk.Container):
         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)
+        scale = min(preview_scale_w, preview_scale_h)
+
+        margin_x = int((preview_width - (width * scale)) / 2)
+        margin_y = int((preview_height - (height * scale)) / 2)
+
+        cairo_context.rectangle(0, 0, preview_width, preview_height)
+        cairo_context.set_source_rgb(1, 1, 1)
+        cairo_context.fill()
+
+        cairo_context.rectangle(margin_x, margin_y, preview_width,
+                preview_height)
+        cairo_context.clip()
+        cairo_context.translate(margin_x, margin_y)
+        cairo_context.scale(scale, scale)
         Gdk.cairo_set_source_window(cairo_context, window, -x, -y)
         cairo_context.paint()
 
-- 
1.7.7.6



More information about the Sugar-devel mailing list