[dia] embedded image support for shapes



commit 50960b3cdcc1a329ef4db9374c1bb815f81b2d9f
Author: Hans Breuer <hans breuer org>
Date:   Tue Jul 26 22:20:20 2011 +0200

    embedded image support for shapes

 doc/custom-shapes           |    2 ++
 doc/en/custom-shapes.xml    |    2 ++
 objects/custom/shape_info.c |   29 +++++++++++++++++++++--------
 3 files changed, 25 insertions(+), 8 deletions(-)
---
diff --git a/doc/custom-shapes b/doc/custom-shapes
index 324c518..9edf286 100644
--- a/doc/custom-shapes
+++ b/doc/custom-shapes
@@ -191,6 +191,8 @@ The recognised drawing elements are:
   independent. The filename is relative to the shape file placement. In the
   above example PNG and shape need to be in the same directory.
 
+  Inlined image data is also supported with xlink:href="data:image/png;base64,..."
+
 <svg:circle cx="..." cy="..." r="..."/>
   This is a circle with centre (cx,cy) and radius r.
 
diff --git a/doc/en/custom-shapes.xml b/doc/en/custom-shapes.xml
index 41ae2c3..06d6081 100644
--- a/doc/en/custom-shapes.xml
+++ b/doc/en/custom-shapes.xml
@@ -377,6 +377,8 @@
             preferred because it is installation
             independent. The filename is relative to the shape file placement. In the
             above example PNG and shape need to be in the same directory.
+	    
+	    Inlined image data is also supported with xlink:href="data:image/png;base64,..."
           </para>
         </listitem>
         <listitem>
diff --git a/objects/custom/shape_info.c b/objects/custom/shape_info.c
index e17005c..f4e457e 100644
--- a/objects/custom/shape_info.c
+++ b/objects/custom/shape_info.c
@@ -34,6 +34,7 @@
 #include "custom_util.h"
 #include "custom_object.h"
 #include "dia_image.h"
+#include "prop_pixbuf.h" /* pixbuf_decode_base64() */
 #include "message.h"
 #include "intl.h"
 #include "prefs.h"
@@ -438,16 +439,28 @@ parse_svg_node(ShapeInfo *info, xmlNodePtr node, xmlNsPtr svg_ns,
       if (!str) /* this doesn't look right but it appears to work w/o namespace --hb */
         str = xmlGetProp(node, (const xmlChar *)"href");
       if (str) {
-        gchar *imgfn = g_filename_from_uri((gchar *) str, NULL, NULL);
+        gchar *imgfn = NULL;
+        const char* data = strchr((char *)str, ',');
 
-        if (!imgfn)
-	  /* despite it's name it ensures an absolute filename */
-          imgfn = custom_get_relative_filename(filename, (gchar *) str);
+	/* first check for inlined data */
+	if (data) {
+	  GdkPixbuf *pixbuf = pixbuf_decode_base64 (data+1);
 
-        image->image = dia_image_load(imgfn);
+	  if (pixbuf) {
+	    image->image = dia_image_new_from_pixbuf (pixbuf);
+	    g_object_unref (pixbuf);
+	  }
+	} else {
+	  gchar *imgfn = g_filename_from_uri((gchar *) str, NULL, NULL);
+          if (!imgfn)
+	    /* despite it's name it ensures an absolute filename */
+            imgfn = custom_get_relative_filename(filename, (gchar *) str);
+
+          image->image = dia_image_load(imgfn);
+	}
         /* w/o the image we would crash later */
         if (!image->image) {
-          g_warning("failed to load image file %s", imgfn ? imgfn : "(NULL)");
+          g_warning("failed to load image file %s", imgfn ? imgfn : "(data:)");
           image->image = dia_image_get_broken();
         }
         g_free(imgfn);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]