[dia] svg: warn about a closed path with just two points



commit 1bd7d96ed8662cd40dd28c57a6145670b5fe09ea
Author: Hans Breuer <hans breuer org>
Date:   Mon Dec 16 13:21:58 2013 +0100

    svg: warn about a closed path with just two points
    
    Dia's Beziergon wants at least three points, but some SVG only
    have pathes with just two points. Turn these into a BezierLine
    and throw a g_warning(), because I'm uncertain if these shouldn't
    be handle differently.

 plug-ins/svg/svg-import.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 0d20c52..7641f54 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -583,20 +583,27 @@ read_path_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GHashTable *style_ht,
          use_stdpath = (move_tos > 1);
        }
         if (g_array_index(bezpoints, BezPoint, 0).type != BEZ_MOVE_TO) {
-          dia_context_add_message(ctx, _("Invalid path data.\n"
+         dia_context_add_message(ctx, _("Invalid path data.\n"
                                         "svg:path data must start with moveto."));
          break;
        } else if (use_stdpath) {
          otype = object_get_type("Standard - Path");
-        } else if (!closed)
+       } else if (!closed) {
          otype = object_get_type("Standard - BezierLine");
-        else
+       } else if (bezpoints->len < 3) { /* error path: invalid input or parsing error? */
+         /* Our beziergon can not handle less than three points
+          * Not sure if turning it into a line is such a good idea ...
+          */
+         g_warning ("Not closing a path with two points.");
+         otype = object_get_type("Standard - BezierLine");
+         closed = FALSE;
+       } else {
          otype = object_get_type("Standard - Beziergon");
-
+       }
        if (otype == NULL){
          dia_context_add_message(ctx, _("Can't find standard object"));
          break;
-        }
+       }
        bcd = g_new(BezierCreateData, 1);
        bcd->num_points = bezpoints->len;
        bcd->points = &(g_array_index(bezpoints, BezPoint, 0));
@@ -618,7 +625,7 @@ read_path_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GHashTable *style_ht,
        apply_style(new_obj, node, parent_style, style_ht, TRUE);
        list = g_list_append (list, new_obj);
 
-        g_array_set_size (bezpoints, 0);
+       g_array_set_size (bezpoints, 0);
       }
       pathdata = unparsed;
       unparsed = NULL;


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