Пример #1
0
static void
gnm_soi_default_size (SheetObject const *so, double *w, double *h)
{
	SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so);
	if (soi->image) {
		*w = go_image_get_width (soi->image);
		*h = go_image_get_height (soi->image);
	} else {
		GdkPixbuf *buf = go_image_get_pixbuf (soi->image);

		if (!buf) {
			*w = *h = 5;
			return;
		}

		*w = gdk_pixbuf_get_width  (buf);
		*h = gdk_pixbuf_get_height (buf);

		/* In case buf is invalid with size 0,0 or if the image is just too
		 * small to be useful default to something slightly larger
		 * http://bugzilla.gnome.org/show_bug.cgi?id=462787
		 **/
		if ((*w * *h) < 25.) {
			if (*w < 5) *w = 25;
			if (*h < 5) *h = 25;
		}
		g_object_unref (buf);
	}
}
Пример #2
0
static void
gnm_soi_default_size (SheetObject const *so, double *w, double *h)
{
	SheetObjectImage *soi = GNM_SO_IMAGE (so);
	if (soi->image) {
		*w = go_image_get_width (soi->image);
		*h = go_image_get_height (soi->image);
	} else {
		*w = *h = 5;
	}
}
Пример #3
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);
}
Пример #4
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);
	}
}
Пример #5
0
static void
goc_image_update_bounds (GocItem *item)
{
	GocImage *image = GOC_IMAGE (item);
	double w, h;
	if (!image->image)
		return;
	/* FIXME: take rotation into account */
	w = go_image_get_width (image->image) - image->crop_left - image->crop_right;
	h = go_image_get_height (image->image) - image->crop_top - image->crop_bottom;
	if (w <= 0 || h <= 0) {
		/* nothing visible, put it at origin */
		item->x0 = item->x1 = image->x;
		item->y0 = item->y1 = image->y;
	}
	item->x0 = floor (image->x);
	item->y0 = floor (image->y);
	item->x1 = ceil (image->x + ((image->width > 0.)? image->width: w));
	item->y1 = ceil (image->y + ((image->height > 0.)? image->height: h));
}
Пример #6
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);
	}
}