[dia] svg: support for external SVG in <image/>



commit d7f0c6a8c20303f6fe54da4f748c432ad038af74
Author: Hans Breuer <hans breuer org>
Date:   Thu Dec 19 21:43:54 2013 +0100

    svg: support for external SVG in <image/>
    
    Importing svg as "Misc - Diagram" should produce better results than
    GdkPixbuf rendering of SVGs, especially when there is no librsvg
    plug-in installed ;)

 objects/Misc/diagram_as_object.c |    1 +
 plug-ins/svg/svg-import.c        |   22 +++++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/objects/Misc/diagram_as_object.c b/objects/Misc/diagram_as_object.c
index e4efa58..17288b9 100644
--- a/objects/Misc/diagram_as_object.c
+++ b/objects/Misc/diagram_as_object.c
@@ -259,6 +259,7 @@ _dae_update_data(DiagramAsElement *dae)
 
       dia_context_set_filename (ctx, dae->filename);
       if (inf->import_func(dae->filename, dae->data, ctx, inf->user_data)) {
+        data_update_extents (dae->data); /* should already be called by importer? */
         dae->scale = dae->element.width / (dae->data->extents.right - dae->data->extents.left);
         dae->element.height = (dae->data->extents.bottom - dae->data->extents.top) * dae->scale;
         dae->mtime = statbuf.st_mtime;
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 7641f54..2674541 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -1115,7 +1115,27 @@ read_image_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GHashTable *style_ht,
         g_free (dir);
         filename = absfn;
       }
-      new_obj = create_standard_image(x, y, width, height, filename ? filename : "<broken>");
+      /* Importing svg as "Misc - Diagram" should produce better results than GdkPixbuf rendering */
+      if (filename && g_strrstr (filename, ".svg")) {
+       Handle *h1, *h2;
+       Point point = {x, y};
+       DiaObjectType *otype = object_get_type("Misc - Diagram");
+
+       if (otype) {
+         GPtrArray *props = g_ptr_array_new ();
+         new_obj = otype->ops->create (&point, otype->default_user_data, &h1, &h2);
+         prop_list_add_filename (props, "diagram_file", filename);
+         if (new_obj) {
+           new_obj->ops->set_props (new_obj, props);
+           point.x += width;
+           point.y += height;
+           new_obj->ops->move_handle (new_obj, h2, &point, NULL, HANDLE_MOVE_USER_FINAL, 0);
+         }
+         prop_list_free (props);
+       }
+      } else {
+       new_obj = create_standard_image(x, y, width, height, filename ? filename : "<broken>");
+      }
       g_free(filename);
     }
     xmlFree(str);


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