[dia] svg: export images inline if there is no filename
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] svg: export images inline if there is no filename
- Date: Sun, 26 Jun 2011 14:34:10 +0000 (UTC)
commit 50108da4e2b25a33fb6a28be0d3e7a42a9cb785a
Author: Hans Breuer <hans breuer org>
Date: Sun Jun 26 16:32:20 2011 +0200
svg: export images inline if there is no filename
For the embedded image case there is no valid filename.
Detect that case (as well as DiaImage coming from
DiagramAsElement and inline the data than.
lib/diasvgrenderer.c | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/lib/diasvgrenderer.c b/lib/diasvgrenderer.c
index 9046265..8caaedb 100644
--- a/lib/diasvgrenderer.c
+++ b/lib/diasvgrenderer.c
@@ -48,6 +48,7 @@
#include "diasvgrenderer.h"
#include "textline.h"
+#include "prop_pixbuf.h" /* pixbuf_encode_base64() */
#define DTOSTR_BUF_SIZE G_ASCII_DTOSTR_BUF_SIZE
#define dia_svg_dtostr(buf,d) \
@@ -749,8 +750,18 @@ draw_image(DiaRenderer *self,
xmlSetProp(node, (const xmlChar *)"height", (xmlChar *) d_buf);
/* if the image file location is relative to the SVG file's store
- * a relative path */
- if ((uri = dia_relativize_filename (renderer->filename, dia_image_filename(image))) != NULL)
+ * a relative path - if it does not have a path: inline it */
+ if (strcmp (dia_image_filename(image), "(null)") == 0) {
+ gchar *b64 = pixbuf_encode_base64 (dia_image_pixbuf (image));
+ gchar *uri;
+
+ if (b64)
+ uri = g_strdup_printf ("data:image/png;base64,%s", b64);
+ else
+ uri = g_strdup ("(null)");
+ xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) uri);
+ g_free (b64);
+ } else if ((uri = dia_relativize_filename (renderer->filename, dia_image_filename(image))) != NULL)
xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) uri);
else if ((uri = g_filename_to_uri(dia_image_filename(image), NULL, NULL)) != NULL)
xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) uri);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]