[dia] diasvg.py: support inlined images and line style for draw_beziergon



commit 76c0e102331db619229540a8d845d1c12223135c
Author: Hans Breuer <hans breuer org>
Date:   Sat Apr 26 23:31:53 2014 +0200

    diasvg.py: support inlined images and line style for draw_beziergon
    
    and avoid:
    <type 'exceptions.RuntimeError'>RuntimeError("The pathname '(null)' is not an ab
    solute path",)Traceback (most recent call last):
      File "D:\Graph\dia2\python\diasvg.py", line 210, in draw_image
        % (point.x, point.y, width, height, image.uri))

 plug-ins/python/diasvg.py     |    4 ++--
 plug-ins/python/pydia-image.c |   11 ++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/python/diasvg.py b/plug-ins/python/diasvg.py
index 17df5c1..7d80d9e 100644
--- a/plug-ins/python/diasvg.py
+++ b/plug-ins/python/diasvg.py
@@ -190,8 +190,8 @@ class SvgRenderer :
                self._bezier (bezpoints)
                self.f.write('"/>\n')
        def draw_beziergon (self, bezpoints, fill, stroke) :
-               self.f.write('<path stroke="%s" fill="%s" stroke-width="%.3f" d="' \
-                                       % (self._rgb(stroke), self._rgb(fill), self.line_width))
+               self.f.write('<path stroke="%s" fill="%s" stroke-width="%.3f" %s d="' \
+                                       % (self._rgb(stroke), self._rgb(fill), self.line_width, 
self._stroke_style()))
                self._bezier (bezpoints)
                self.f.write('z"/>\n')
        def draw_string (self, text, pos, alignment, color) :
diff --git a/plug-ins/python/pydia-image.c b/plug-ins/python/pydia-image.c
index 6692b13..204f98b 100644
--- a/plug-ins/python/pydia-image.c
+++ b/plug-ins/python/pydia-image.c
@@ -21,6 +21,7 @@
 
 #include "pydia-object.h"
 #include "pydia-image.h"
+#include "prop_pixbuf.h" /* pixbuf_encode_base64 */
 
 #include <structmember.h> /* PyMemberDef */
 
@@ -88,7 +89,15 @@ PyDiaImage_GetAttr(PyDiaImage *self, gchar *attr)
   }
   else if (!strcmp(attr, "uri")) {
     GError* error = NULL;
-    char* s = g_filename_to_uri(dia_image_filename(self->image), NULL, &error);
+    const gchar *fname = dia_image_filename(self->image);
+    char* s;
+    if (g_path_is_absolute(fname)) {
+      s = g_filename_to_uri(fname, NULL, &error);
+    } else {
+      gchar *b64 = pixbuf_encode_base64 (dia_image_pixbuf (self->image));
+      s = g_strdup_printf ("data:image/png;base64,%s", b64);
+      g_free (b64);
+    }
     if (s) {
       PyObject* py_s = PyString_FromString(s);
       g_free(s);


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