[goffice] Fixed cropped images rendering.



commit d8763c8b6f8142f95cd07bb8a763a12a68d98bb8
Author: Jean Brefort <jean brefort normalesup org>
Date:   Mon Mar 26 14:23:27 2012 +0200

    Fixed cropped images rendering.

 ChangeLog                  |    5 +++++
 goffice/canvas/goc-image.c |   23 +++++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d266860..2a6696c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2012-03-26  Jean Brefort  <jean brefort normalesup org>
 
+	* goffice/canvas/goc-image.c (goc_image_draw),
+	(goc_image_class_init): fixed cropped images rendering.
+
+2012-03-26  Jean Brefort  <jean brefort normalesup org>
+
 	* goffice/utils/go-pixbuf.c (go_pixbuf_save): fix pixbuf saving when cairo
 	data has not been generated. [see #672716]
 
diff --git a/goffice/canvas/goc-image.c b/goffice/canvas/goc-image.c
index 927258e..2812f6e 100644
--- a/goffice/canvas/goc-image.c
+++ b/goffice/canvas/goc-image.c
@@ -222,16 +222,16 @@ goc_image_draw (GocItem const *item, cairo_t *cr)
 		return;
 
 	if (image->width < 0.)
-		width = go_image_get_width (image->image);
+		width = go_image_get_width (image->image) * (1 - image->crop_left -image->crop_right);
 	else {
 		width = image->width;
-		scalex = width / go_image_get_width (image->image);
+		scalex = width / go_image_get_width (image->image) / (1 - image->crop_left -image->crop_right);
 	}
 	if (image->height < 0.)
-		height = go_image_get_height (image->image);
+		height = go_image_get_height (image->image) * (1 - image->crop_top -image->crop_bottom);
 	else {
 		height = image->height;
-		scaley = height / go_image_get_height (image->image);
+		scaley = height / go_image_get_height (image->image) / (1 - image->crop_top -image->crop_bottom);
 	}
 	cairo_save (cr);
 	x = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)?
@@ -240,11 +240,10 @@ goc_image_draw (GocItem const *item, cairo_t *cr)
 	cairo_rotate (cr, image->rotation);
 	if (scalex != 1. || scaley != 1.)
 		cairo_scale (cr, scalex, scaley);
-	cairo_translate (cr, -image->crop_left, -image->crop_top);
-	cairo_rectangle (cr, 0, 0,
-	                 go_image_get_width (image->image) - image->crop_left -  image->crop_right,
-	                 go_image_get_height (image->image) - image->crop_top -  image->crop_bottom);
+	cairo_rectangle (cr, 0, 0, image->width, image->height);
 	cairo_clip (cr);
+	cairo_translate (cr, -go_image_get_width (image->image) * image->crop_left,
+	                 -go_image_get_height (image->image) * image->crop_top);
 	cairo_move_to (cr, 0, 0);
 	go_image_draw (image->image, cr);
 	cairo_restore (cr);
@@ -296,22 +295,22 @@ goc_image_class_init (GocItemClass *item_klass)
 			GSF_PARAM_STATIC | G_PARAM_READWRITE));
 	g_object_class_install_property (obj_klass, IMAGE_PROP_CROP_BOTTOM,
 	        g_param_spec_double ("crop-bottom", _("Cropped bottom"),
-	                _("The cropped area at the image bottom"),
+	                _("The cropped area at the image bottom as a fraction of the image height"),
 	                0., G_MAXDOUBLE, 0.,
 			GSF_PARAM_STATIC | G_PARAM_READWRITE));
 	g_object_class_install_property (obj_klass, IMAGE_PROP_CROP_LEFT,
 	        g_param_spec_double ("crop-left", _("Cropped left"),
-	                _("The cropped area at the image left"),
+	                _("The cropped area at the image left of the image width"),
 	                0., G_MAXDOUBLE, 0.,
 			GSF_PARAM_STATIC | G_PARAM_READWRITE));
 	g_object_class_install_property (obj_klass, IMAGE_PROP_CROP_RIGHT,
 	        g_param_spec_double ("crop-right", _("Cropped right"),
-	                _("The cropped area at the image right"),
+	                _("The cropped area at the image right of the image width"),
 	                0., G_MAXDOUBLE, 0.,
 			GSF_PARAM_STATIC | G_PARAM_READWRITE));
 	g_object_class_install_property (obj_klass, IMAGE_PROP_CROP_TOP,
 	        g_param_spec_double ("crop-top", _("Cropped top"),
-	                _("The cropped area at the image top"),
+	                _("The cropped area at the image top as a fraction of the image height"),
 	                0., G_MAXDOUBLE, 0.,
 			GSF_PARAM_STATIC | G_PARAM_READWRITE));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]