Commit 04bb7d17 authored by Jon K Hellan's avatar Jon K Hellan Committed by Jon Kåre Hellan

Declare typedef ObjectImage.

2002-02-25  Jon K Hellan  <hellan@acm.org>

	* src/sheet-object-image.h: Declare typedef ObjectImage.

	* src/sheet-object-image.c (struct _SheetObjectImage): Add
	cropping parameters.
	(sheet_object_image_new): Initialize cropping parameters.
	(sheet_object_image_set_crop): New function. Set cropping
	parameters.
	(soi_get_cropped_pixbuf): New function. Get the cropped image from
	pixbuf.
	(soi_get_pixbuf): Do cropping by calling soi_get_cropped_pixbuf.
	(sheet_object_image_init): Initialize cropping parameters.

2002-02-25  Jon K Hellan  <hellan@acm.org>

	* ms-excel-read.c (ms_sheet_create_image): New function. Factor
	image creation out of ms_sheet_create_obj and also handle cropping.
	(ms_sheet_create_obj): Call ms_sheet_create_image.
parent 6bc42b16
2002-02-25 Jon K Hellan <hellan@acm.org>
* src/sheet-object-image.h: Declare typedef ObjectImage.
* src/sheet-object-image.c (struct _SheetObjectImage): Add
cropping parameters.
(sheet_object_image_new): Initialize cropping parameters.
(sheet_object_image_set_crop): New function. Set cropping
parameters.
(soi_get_cropped_pixbuf): New function. Get the cropped image from
pixbuf.
(soi_get_pixbuf): Do cropping by calling soi_get_cropped_pixbuf.
(sheet_object_image_init): Initialize cropping parameters.
2002-02-24 Almer S. Tigelaar <almer@gnome.org>
http://bugzilla.gnome.org/show_bug.cgi?id=72416
......
2002-02-25 Jon K Hellan <hellan@acm.org>
* src/sheet-object-image.h: Declare typedef ObjectImage.
* src/sheet-object-image.c (struct _SheetObjectImage): Add
cropping parameters.
(sheet_object_image_new): Initialize cropping parameters.
(sheet_object_image_set_crop): New function. Set cropping
parameters.
(soi_get_cropped_pixbuf): New function. Get the cropped image from
pixbuf.
(soi_get_pixbuf): Do cropping by calling soi_get_cropped_pixbuf.
(sheet_object_image_init): Initialize cropping parameters.
2002-02-24 Almer S. Tigelaar <almer@gnome.org>
http://bugzilla.gnome.org/show_bug.cgi?id=72416
......
2002-02-25 Jon K Hellan <hellan@acm.org>
* src/sheet-object-image.h: Declare typedef ObjectImage.
* src/sheet-object-image.c (struct _SheetObjectImage): Add
cropping parameters.
(sheet_object_image_new): Initialize cropping parameters.
(sheet_object_image_set_crop): New function. Set cropping
parameters.
(soi_get_cropped_pixbuf): New function. Get the cropped image from
pixbuf.
(soi_get_pixbuf): Do cropping by calling soi_get_cropped_pixbuf.
(sheet_object_image_init): Initialize cropping parameters.
2002-02-24 Almer S. Tigelaar <almer@gnome.org>
http://bugzilla.gnome.org/show_bug.cgi?id=72416
......
2002-02-25 Jon K Hellan <hellan@acm.org>
* ms-excel-read.c (ms_sheet_create_image): New function. Factor
image creation out of ms_sheet_create_obj and also handle cropping.
(ms_sheet_create_obj): Call ms_sheet_create_image.
2002-02-23 Jon K Hellan <hellan@acm.org>
* plugin.xml.in: Recognize *.xlt extension.
......
......@@ -2089,6 +2089,44 @@ ms_sheet_map_color (ExcelSheet const *esheet, MSObj const *obj, MSObjAttrID id)
return style_color_new_i8 (r, g, b);
}
static SheetObject *
ms_sheet_create_image (MSObj *obj, MSEscherBlip *blip)
{
SheetObject *so;
MSObjAttr *crop_left_attr = ms_object_attr_bag_lookup
(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_LEFT);
MSObjAttr *crop_top_attr = ms_object_attr_bag_lookup
(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_TOP);
MSObjAttr *crop_right_attr = ms_object_attr_bag_lookup
(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_RIGHT);
MSObjAttr *crop_bottom_attr = ms_object_attr_bag_lookup
(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_BOTTOM);
double crop_left_val = 0.0;
double crop_top_val = 0.0;
double crop_right_val = 0.0;
double crop_bottom_val = 0.0;
so = sheet_object_image_new (blip->type, blip->data, blip->data_len,
!blip->needs_free);
if (!so)
return NULL;
if (crop_left_attr)
crop_left_val = (double) crop_left_attr->v.v_uint / 65536.;
if (crop_top_attr)
crop_top_val = (double) crop_top_attr->v.v_uint / 65536.;
if (crop_right_attr)
crop_right_val = (double) crop_right_attr->v.v_uint / 65536.;
if (crop_bottom_attr)
crop_bottom_val = (double) crop_bottom_attr->v.v_uint / 65536.;
sheet_object_image_set_crop (SHEET_OBJECT_IMAGE (so),
crop_left_val, crop_top_val,
crop_right_val, crop_bottom_val);
return so;
}
static GObject *
ms_sheet_create_obj (MSContainer *container, MSObj *obj)
{
......@@ -2150,8 +2188,7 @@ ms_sheet_create_obj (MSContainer *container, MSObj *obj)
MSEscherBlip *blip = ms_container_get_blip (container,
blip_id->v.v_uint - 1);
if (blip != NULL) {
so = sheet_object_image_new (blip->type,
blip->data, blip->data_len, !blip->needs_free);
so = ms_sheet_create_image (obj, blip);
blip->needs_free = FALSE; /* image took over managing data */
}
}
......
......@@ -19,7 +19,7 @@
#include <math.h>
typedef struct {
struct _SheetObjectImage {
SheetObject sheet_object;
char const *type;
......@@ -27,7 +27,11 @@ typedef struct {
guint32 data_len;
gboolean dumped;
} SheetObjectImage;
double crop_top;
double crop_bottom;
double crop_left;
double crop_right;
};
typedef struct {
SheetObjectClass parent_class;
......@@ -49,6 +53,8 @@ sheet_object_image_new (char const *type,
soi = g_object_new (SHEET_OBJECT_IMAGE_TYPE, NULL);
soi->type = type;
soi->data_len = data_len;
soi->crop_top = soi->crop_bottom = soi->crop_left = soi->crop_right
= 0.0;
if (copy_data) {
soi->data = g_malloc (data_len);
memcpy (soi->data, data, data_len);
......@@ -58,6 +64,19 @@ sheet_object_image_new (char const *type,
return SHEET_OBJECT (soi);
}
void
sheet_object_image_set_crop (SheetObjectImage *soi,
double crop_left, double crop_top,
double crop_right, double crop_bottom)
{
g_return_if_fail (IS_SHEET_OBJECT_IMAGE (soi));
soi->crop_left = crop_left;
soi->crop_top = crop_top;
soi->crop_right = crop_right;
soi->crop_bottom = crop_bottom;
}
static void
sheet_object_image_finalize (GObject *object)
{
......@@ -70,6 +89,26 @@ sheet_object_image_finalize (GObject *object)
G_OBJECT_CLASS (sheet_object_image_parent_class)->finalize (object);
}
static GdkPixbuf *
soi_get_cropped_pixbuf (SheetObjectImage *soi, GdkPixbuf *pixbuf)
{
int width = gdk_pixbuf_get_width (pixbuf);
int height = gdk_pixbuf_get_height (pixbuf);
int sub_x = rint (soi->crop_left * width);
int sub_y = rint (soi->crop_top * height);
int sub_width = rint (width *
(1. - soi->crop_left - soi->crop_right));
int sub_height = rint (height *
(1. - soi->crop_top - soi->crop_bottom));
GdkPixbuf *sub = gdk_pixbuf_new_subpixbuf (pixbuf, sub_x, sub_y,
sub_width, sub_height);
if (sub) {
g_object_unref (G_OBJECT (pixbuf));
pixbuf = sub;
}
return pixbuf;
}
/**
* be sure to unref the result if it is non-NULL
*
......@@ -116,7 +155,10 @@ soi_get_pixbuf (SheetObjectImage *soi, double scale)
} else {
res = gdk_pixbuf_loader_get_pixbuf (loader),
g_object_ref (G_OBJECT (res));
/* TODO : use gdk_pixbuf_new_subpixbuf to implement clipping */
if (soi->crop_top != 0.0 || soi->crop_bottom != 0.0 ||
soi->crop_left != 0.0 || soi->crop_right != 0.0) {
res = soi_get_cropped_pixbuf (soi, res);
}
}
gdk_pixbuf_loader_close (loader, &err);
......@@ -293,6 +335,8 @@ sheet_object_image_init (GObject *obj)
soi = SHEET_OBJECT_IMAGE (obj);
soi->dumped = FALSE;
soi->crop_top = soi->crop_bottom = soi->crop_left = soi->crop_right
= 0.0;
so = SHEET_OBJECT (obj);
so->anchor.direction = SO_DIR_NONE_MASK;
......
......@@ -4,11 +4,18 @@
#include "sheet-object.h"
#define SHEET_OBJECT_IMAGE_TYPE (sheet_object_image_get_type ())
#define SHEET_OBJECT_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SHEET_OBJECT_IMAGE_TYPE, SheetObjectImage))
#define IS_SHEET_OBJECT_IMAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SHEET_OBJECT_IMAGE_TYPE))
typedef struct _SheetObjectImage SheetObjectImage;
GType sheet_object_image_get_type (void);
SheetObject *sheet_object_image_new (char const *type,
guint8 *data,
guint32 data_len,
gboolean copy_data);
void sheet_object_image_set_crop (SheetObjectImage *soi,
double crop_left, double crop_top,
double crop_right, double crop_bottom);
#endif /* GNUMERIC_SHEET_OBJECT_IMAGE_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment