[maemo-commits] [maemo-commits] r19161 - in projects/haf/trunk/sapwood: . engine

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Aug 20 15:09:30 EEST 2009
Author: herzi
Date: 2009-08-20 15:08:57 +0300 (Thu, 20 Aug 2009)
New Revision: 19161

Modified:
   projects/haf/trunk/sapwood/ChangeLog
   projects/haf/trunk/sapwood/engine/sapwood-pixmap.c
Log:
2009-08-20  Christian Dywan  <christian at lanedo.com>

	NB#118393 - Crop images if they are supposed to be rendered too small

	* engine/sapwood-pixmap.c (sapwood_crop_pixmap),
	(sapwood_pixmap_render_rects): Implement sapwood_crop_pixmap and crop
	the image if it is too big.


Modified: projects/haf/trunk/sapwood/ChangeLog
===================================================================
--- projects/haf/trunk/sapwood/ChangeLog	2009-08-19 16:48:14 UTC (rev 19160)
+++ projects/haf/trunk/sapwood/ChangeLog	2009-08-20 12:08:57 UTC (rev 19161)
@@ -1,3 +1,11 @@
+2009-08-20  Christian Dywan  <christian at lanedo.com>
+
+	NB#118393 - Crop images if they are supposed to be rendered too small
+
+	* engine/sapwood-pixmap.c (sapwood_crop_pixmap),
+	(sapwood_pixmap_render_rects): Implement sapwood_crop_pixmap and crop
+	the image if it is too big.
+
 2009-08-07  Alejandro G. Castro  <alex at igalia.com>
 
 	Added a new debug enviroment option to enable the synchronous X

Modified: projects/haf/trunk/sapwood/engine/sapwood-pixmap.c
===================================================================
--- projects/haf/trunk/sapwood/engine/sapwood-pixmap.c	2009-08-19 16:48:14 UTC (rev 19160)
+++ projects/haf/trunk/sapwood/engine/sapwood-pixmap.c	2009-08-20 12:08:57 UTC (rev 19161)
@@ -372,6 +372,63 @@
     }
 }
 
+static void
+sapwood_crop_pixmap (GdkPixmap *pixmap,
+                     int        x,
+                     int        y,
+                     int        requested_width,
+                     int        requested_height,
+                     int        original_width,
+                     int        original_height)
+{
+  cairo_t *cr;
+  cairo_surface_t *surface;
+  int w1, h1, w2, h2;
+
+  cr = gdk_cairo_create (pixmap);
+  surface = cairo_get_target (cr);
+
+  w1 = requested_width / 2;
+  h1 = requested_height / 2;
+  w2 = (requested_width + 1) / 2;
+  h2 = (requested_height + 1) / 2;
+
+  /* top-left */
+  cairo_save (cr);
+  cairo_set_source_surface (cr, surface, x, y);
+  cairo_rectangle (cr, x, y, w2, h2);
+  cairo_clip (cr);
+  cairo_paint (cr);
+  cairo_restore (cr);
+
+  /* top-right */
+  cairo_save (cr);
+  cairo_set_source_surface (cr, surface, x + requested_width - original_width, y);
+  cairo_rectangle (cr, x + w1, y, w2, h2);
+  cairo_clip (cr);
+  cairo_paint (cr);
+  cairo_restore (cr);
+
+  /* bottom-left */
+  cairo_save (cr);
+  cairo_set_source_surface (cr, surface, x,  y + requested_height - original_height);
+  cairo_rectangle (cr, x, y + h1, w2, h2);
+  cairo_clip (cr);
+  cairo_paint (cr);
+  cairo_restore (cr);
+
+  /* bottom-right */
+  cairo_save (cr);
+  cairo_set_source_surface (cr, surface, x + requested_width - original_width,
+					 y + requested_height - original_height);
+  cairo_rectangle (cr, x + w1, y + h1, w2, h2);
+  cairo_clip (cr);
+  cairo_paint (cr);
+  cairo_restore (cr);
+
+  cairo_destroy (cr);
+}
+
 void
 sapwood_pixmap_render_rects (SapwoodPixmap *self,
                              GtkWidget     *widget,
@@ -458,7 +515,10 @@
 
   cairo_translate (cr, draw_x, draw_y);
 
-  if (width != tmp_width || height != tmp_height)
+  if (width > 0 && width < tmp_width || height > 0 && height < tmp_height)
+      sapwood_crop_pixmap (tmp, 0, 0, width, height,
+			   self->width, self->height);
+  else if (width != tmp_width || height != tmp_height)
     {
       cairo_scale (cr, (double)width / (double)tmp_width,
 		       (double)height / (double)tmp_height);

More information about the maemo-commits mailing list