static void go_image_get_property (GObject *obj, guint param_id, GValue *value, GParamSpec *pspec) { GOImage *image = GO_IMAGE (obj); switch (param_id) { case IMAGE_PROP_WIDTH: g_value_set_uint (value, image->width); break; case IMAGE_PROP_HEIGHT: g_value_set_uint (value, image->height); break; #ifdef GOFFICE_WITH_GTK case IMAGE_PROP_PIXBUF: if (image->target_cairo && image->pixbuf) { cairo_to_pixbuf (image); image->target_cairo = FALSE; } g_value_set_object (value, image->pixbuf); break; #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec); return; /* NOTE : RETURN */ } }
GOImage * go_spectre_new_from_file (char const *filename, GError **error) { GOSpectre *spectre = g_object_new (GO_TYPE_SPECTRE, NULL); guint8 *data; GsfInput *input = gsf_input_stdio_new (filename, error); #ifdef GOFFICE_WITH_EPS int width, height; #endif GOImage *image; if (!input) return NULL; image = GO_IMAGE (spectre); image->data_length = gsf_input_size (input); data = g_malloc (image->data_length); if (!data || !gsf_input_read (input, image->data_length, data)) { g_object_unref (spectre); g_free (data); return NULL; } image->data = data; #ifdef GOFFICE_WITH_EPS spectre->doc = spectre_document_new (); if (spectre->doc == NULL) { g_object_unref (spectre); return NULL; } spectre_document_load (spectre->doc, filename); if (spectre_document_status (spectre->doc) != SPECTRE_STATUS_SUCCESS) { g_object_unref (spectre); return NULL; } spectre_document_get_page_size (spectre->doc, &width, &height); image->width = width; image->height = height; #else { GsfInput *input = gsf_input_memory_new (image->data, image->data_length, FALSE); GsfInputTextline *text = GSF_INPUT_TEXTLINE (gsf_input_textline_new (input)); guint8 *line; while ((line = gsf_input_textline_ascii_gets (text))) if (!strncmp (line, "%%BoundingBox: ", 15)) { unsigned x0, x1, y0, y1; if (sscanf (line + 15, "%u %u %u %u", &x0, &y0, &x1, &y1) == 4) { image->width = x1 - x0; image->height = y1 - y0; } else { image->width = 100; image->height = 100; } break; } g_object_unref (text); g_object_unref (input); } #endif return image; }
static void go_image_finalize (GObject *obj) { GOImage *image = GO_IMAGE (obj); if (image->data != NULL) g_free (image->data); #ifdef GOFFICE_WITH_GTK if (image->pixbuf) g_object_unref (image->pixbuf); #endif (parent_klass->finalize) (obj); }
static void goc_image_set_property (GObject *gobject, guint param_id, GValue const *value, GParamSpec *pspec) { GocImage *image = GOC_IMAGE (gobject); switch (param_id) { case IMAGE_PROP_X: image->x = g_value_get_double (value); break; case IMAGE_PROP_Y: image->y = g_value_get_double (value); break; case IMAGE_PROP_W: image->width = g_value_get_double (value); break; case IMAGE_PROP_H: image->height = g_value_get_double (value); break; case IMAGE_PROP_ROTATION: image->rotation = g_value_get_double (value); break; case IMAGE_PROP_IMAGE: if (image->image) g_object_unref (image); image->image = GO_IMAGE (g_object_ref (g_value_get_object (value))); break; case IMAGE_PROP_CROP_BOTTOM: image->crop_bottom = g_value_get_double (value); break; case IMAGE_PROP_CROP_LEFT: image->crop_left = g_value_get_double (value); break; case IMAGE_PROP_CROP_RIGHT: image->crop_right = g_value_get_double (value); break; case IMAGE_PROP_CROP_TOP: image->crop_top = g_value_get_double (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec); return; /* NOTE : RETURN */ } goc_item_bounds_changed (GOC_ITEM (gobject)); }
static void go_image_set_property (GObject *obj, guint param_id, GValue const *value, GParamSpec *pspec) { GOImage *image = GO_IMAGE (obj); gboolean size_changed = FALSE; guint n; switch (param_id) { case IMAGE_PROP_WIDTH: n = g_value_get_uint (value); if (n != image->width) { image->width = n; size_changed = TRUE; } break; case IMAGE_PROP_HEIGHT: n = g_value_get_uint (value); if (n != image->height) { image->height = n; size_changed = TRUE; } break; #ifdef GOFFICE_WITH_GTK case IMAGE_PROP_PIXBUF: { GdkPixbuf *pixbuf = GDK_PIXBUF (g_value_get_object (value)); if (!GDK_IS_PIXBUF (pixbuf)) break; if (!gdk_pixbuf_get_has_alpha (pixbuf)) pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0); else g_object_ref (pixbuf); if (image->pixbuf) g_object_unref (image->pixbuf); image->pixbuf = pixbuf; if (image->data != NULL) { g_free (image->data); image->data = NULL; } image->width = gdk_pixbuf_get_width (pixbuf); image->height = gdk_pixbuf_get_height (pixbuf); image->rowstride = gdk_pixbuf_get_rowstride (pixbuf); image->target_cairo = FALSE; } break; #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec); return; /* NOTE : RETURN */ } if (size_changed) { if (image->pixbuf) { g_object_unref (image->pixbuf); image->pixbuf = NULL; } if (image->data != NULL) g_free (image->data); /* GOImage only supports pixbuf with alpha values at the moment */ image->rowstride = image->width * 4; image->data = g_new0 (guint8, image->height * image->rowstride); image->target_cairo = TRUE; } }