Exemplo n.º 1
0
static void
gnm_soi_draw_cairo (SheetObject const *so, cairo_t *cr,
		    double width, double height)
{
	GdkPixbuf *pixbuf;
	GOImage *img;
	int w, h;
	SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so);

	if (soi->image) {
		w = go_image_get_width (soi->image);
		h = go_image_get_height (soi->image);
		w -= soi->crop_left - soi->crop_right;
		h -= soi->crop_top - soi->crop_bottom;
		if (w <= 0 || h <= 0)
			return;
		cairo_save (cr);
		cairo_rectangle (cr, 0, 0, width, height);
		cairo_clip (cr);
		cairo_scale (cr, width / w, height / h);
		cairo_translate (cr, -soi->crop_left, -soi->crop_top);
		go_image_draw (soi->image, cr);
		cairo_restore (cr);
	} else {
		pixbuf = go_image_get_pixbuf (soi->image);
		if (!pixbuf || width == 0. || height == 0.)
			return;
		cairo_save (cr);
		img = go_pixbuf_new_from_pixbuf (pixbuf);

		w = gdk_pixbuf_get_width  (pixbuf);
		h = gdk_pixbuf_get_height (pixbuf);
		cairo_scale (cr, width / w, height / h);
		go_image_draw (img, cr);
		/*
		 * We need to unset the source before we destroy the pattern.
		 * cairo_restore will do that.  See #632439.
		 */
		cairo_restore (cr);
		g_object_unref (img);
		g_object_unref (pixbuf);
	}
}
Exemplo n.º 2
0
static void
goc_image_draw (GocItem const *item, cairo_t *cr)
{
	GocImage *image = GOC_IMAGE (item);
	double height, width;
	double scalex = 1., scaley = 1.;
	int x;

	if (image->image == NULL || image->width == 0. || image->height == 0.)
		return;

	if (image->width < 0.)
		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) / (1 - image->crop_left -image->crop_right);
	}
	if (image->height < 0.)
		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) / (1 - image->crop_top -image->crop_bottom);
	}
	cairo_save (cr);
	_goc_item_transform (item, cr, TRUE);
	x = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)?
		image->x + image->width: image->x;
	goc_group_cairo_transform (item->parent, cr, x, (int) image->y);
	cairo_rotate (cr, image->rotation);
	cairo_rectangle (cr, 0, 0, image->width, image->height);
	cairo_clip (cr);
	if (scalex != 1. || scaley != 1.)
		cairo_scale (cr, scalex, scaley);
	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);
}
Exemplo n.º 3
0
static void
gnm_soi_draw_cairo (SheetObject const *so, cairo_t *cr,
		    double width, double height)
{
	SheetObjectImage *soi = GNM_SO_IMAGE (so);

	if (soi->image) {
		int w = go_image_get_width (soi->image);
		int h = go_image_get_height (soi->image);
		w -= soi->crop_left - soi->crop_right;
		h -= soi->crop_top - soi->crop_bottom;
		if (w <= 0 || h <= 0)
			return;
		cairo_save (cr);
		cairo_rectangle (cr, 0, 0, width, height);
		cairo_clip (cr);
		cairo_scale (cr, width / w, height / h);
		cairo_translate (cr, -soi->crop_left, -soi->crop_top);
		go_image_draw (soi->image, cr);
		cairo_restore (cr);
	}
}