dia r4265 - in trunk: . lib plug-ins/svg
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4265 - in trunk: . lib plug-ins/svg
- Date: Sat, 7 Feb 2009 13:31:36 +0000 (UTC)
Author: hans
Date: Sat Feb 7 13:31:35 2009
New Revision: 4265
URL: http://svn.gnome.org/viewvc/dia?rev=4265&view=rev
Log:
2009-02-07 Hans Breuer <hans breuer org>
* lib/dia_image.c : turn DiaImage into a GObject, plugs memory leak
fixing bug #570850
* plug-ins/svg/svg-import.c : actually implement read_image_svg(),
part of bug #570863 (strange this was not reporeted before)
Modified:
trunk/ChangeLog
trunk/lib/dia_image.c
trunk/plug-ins/svg/svg-import.c
Modified: trunk/lib/dia_image.c
==============================================================================
--- trunk/lib/dia_image.c (original)
+++ trunk/lib/dia_image.c Sat Feb 7 13:31:35 2009
@@ -29,7 +29,18 @@
#define SCALING_CACHE
+GType dia_image_get_type (void);
+#define DIA_TYPE_IMAGE (dia_image_get_type())
+#define DIA_IMAGE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), DIA_TYPE_IMAGE, DiaImage))
+#define DIA_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_IMAGE, DiaImageClass))
+
+typedef struct _DiaImageClass DiaImageClass;
+struct _DiaImageClass {
+ GObjectClass parent_class;
+};
+
struct _DiaImage {
+ GObject parent_instance;
GdkPixbuf *image;
gchar *filename;
#ifdef SCALING_CACHE
@@ -38,6 +49,61 @@
#endif
};
+static void dia_image_class_init(DiaImageClass* class);
+static void dia_image_finalize(GObject* object);
+static void dia_image_init_instance(DiaImage*);
+
+GType
+dia_image_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (!object_type) {
+ static const GTypeInfo object_info =
+ {
+ sizeof (DiaImageClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) dia_image_class_init, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (DiaImage),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc)dia_image_init_instance
+ };
+ object_type = g_type_register_static (G_TYPE_OBJECT,
+ "DiaImage",
+ &object_info, 0);
+ }
+ return object_type;
+}
+
+static gpointer parent_class;
+
+static void
+dia_image_class_init(DiaImageClass* klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+ object_class->finalize = dia_image_finalize;
+}
+
+static void
+dia_image_init_instance(DiaImage *image)
+{
+ /* GObject *gobject = G_OBJECT(image); */
+ /* zero intialization should be good for us */
+}
+
+static void
+dia_image_finalize(GObject* object)
+{
+ DiaImage *image = DIA_IMAGE(object);
+ if (image->image)
+ gdk_pixbuf_unref (image->image);
+ image->image = NULL;
+}
+
gboolean _dia_image_initialized = FALSE;
/** Perform required initialization to handle images with GDK.
@@ -61,7 +127,7 @@
static DiaImage *broken = NULL;
if (broken == NULL) {
- broken = g_new(struct _DiaImage, 1);
+ broken = DIA_IMAGE(g_object_new(DIA_TYPE_IMAGE, NULL));
broken->image = gdk_pixbuf_new_from_inline(-1, dia_broken_icon, FALSE, NULL);
} else {
gdk_pixbuf_ref(broken->image);
@@ -98,7 +164,7 @@
return NULL;
}
- dia_img = g_new(DiaImage, 1);
+ dia_img = DIA_IMAGE(g_object_new(DIA_TYPE_IMAGE, NULL));
dia_img->image = image;
/* We have a leak here, unless we add our own refcount */
dia_img->filename = g_strdup(filename);
@@ -114,7 +180,7 @@
void
dia_image_add_ref(DiaImage *image)
{
- gdk_pixbuf_ref(image->image);
+ g_object_ref(image);
}
/** Release a reference to an image.
@@ -123,7 +189,7 @@
void
dia_image_unref(DiaImage *image)
{
- gdk_pixbuf_unref(image->image);
+ g_object_unref(image);
}
/** Render an image unto a window.
Modified: trunk/plug-ins/svg/svg-import.c
==============================================================================
--- trunk/plug-ins/svg/svg-import.c (original)
+++ trunk/plug-ins/svg/svg-import.c Sat Feb 7 13:31:35 2009
@@ -665,6 +665,50 @@
return list;
}
+static GList *
+read_image_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
+{
+ xmlChar *str;
+ real x = 0, y = 0, width = 0, height = 0;
+ DiaObject *new_obj;
+ gchar *filename = NULL;
+
+ str = xmlGetProp(node, (const xmlChar *)"x");
+ if (str) {
+ x = get_value_as_cm((char *) str, NULL);
+ xmlFree(str);
+ }
+ str = xmlGetProp(node, (const xmlChar *)"y");
+ if (str) {
+ y = get_value_as_cm((char *) str, NULL);
+ xmlFree(str);
+ }
+ str = xmlGetProp(node, (const xmlChar *)"width");
+ if (str) {
+ width = get_value_as_cm((char *) str, NULL);
+ xmlFree(str);
+ }
+ str = xmlGetProp(node, (const xmlChar *)"height");
+ if (str) {
+ height = get_value_as_cm((char *) str, NULL);
+ xmlFree(str);
+ }
+ /* TODO: aspect ratio? */
+
+ str = xmlGetProp(node, (const xmlChar *)"xlink:href");
+ if (!str) /* this doesn't look right but it appears to work w/o namespace --hb */
+ str = xmlGetProp(node, (const xmlChar *)"href");
+ if (str) {
+ filename = g_filename_from_uri((gchar *) str, NULL, NULL);
+ xmlFree(str);
+ }
+ new_obj = create_standard_image(x, y, width, height, filename);
+ g_free(filename);
+
+ return g_list_append (list, new_obj);
+}
+
+
/*!
* Fill a GList* with objects which is to be put in a
* diagram or a group by the caller.
@@ -715,6 +759,8 @@
items = read_text_svg(node, parent_gs, items);
} else if(!xmlStrcmp(node->name, (const xmlChar *)"path")) {
items = read_path_svg(node, parent_gs, items);
+ } else if(!xmlStrcmp(node->name, (const xmlChar *)"image")) {
+ items = read_image_svg(node, parent_gs, items);
} else {
/* everything else is treated like a group _without grouping_, i.e. we dive into unknown stuff */
/* this allows to import stuff generated by 'dot' with links for the nodes */
@@ -836,3 +882,4 @@
extensions,
import_svg
};
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]