[dia] SVG import fixes



commit 6d717afaf0731e43bb032d15977c74325e351ca5
Author: Hans Breuer <hans breuer org>
Date:   Sun May 20 20:06:41 2012 +0200

    SVG import fixes
    
     - _parse_color(): the last else branch was not using the separated
       color string leading to Pango not parsing the color correctly
     - a SVG path with only a move-to at the start is supposed to create
       implicit line-to [SVG11 8.3.2]
     - introduce dia_svg_parse_color() for later use

 lib/dia_svg.c  |   21 ++++++++++++++++++++-
 lib/dia_svg.h  |    1 +
 lib/libdia.def |    1 +
 3 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index 7e7aa7a..b7f1a04 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -127,7 +127,7 @@ _parse_color(gint32 *color, const char *str)
 	return FALSE;
     } else {
       gchar* sz = g_strndup (str, se - str);
-      gboolean ret = pango_color_parse (&pc, str);
+      gboolean ret = pango_color_parse (&pc, sz);
 
       if (ret)
 	*color = ((0xFF<<24) & 0xFF000000) | ((pc.red >> 8) << 16) | ((pc.green >> 8) << 8) | (pc.blue >> 8);
@@ -138,6 +138,21 @@ _parse_color(gint32 *color, const char *str)
   return TRUE;
 }
 
+gboolean
+dia_svg_parse_color (const gchar *str, Color *color)
+{
+  gint32 c;
+  gboolean ret = _parse_color (&c, str);
+
+  if (ret) {
+    color->red   = ((c & 0xff0000) >> 16) / 255.0;
+    color->green = ((c & 0x00ff00) >> 8) / 255.0;
+    color->blue  =  (c & 0x0000ff) / 255.0;
+    color->alpha = 1.0;
+  }
+  return ret;
+}
+
 enum
 {
   FONT_NAME_LENGTH_MAX = 40
@@ -773,6 +788,10 @@ dia_svg_parse_path(const gchar *path_str, gchar **unparsed, gboolean *closed, Po
       else
 #endif
         g_array_append_val(points, bez);
+      /* [SVG11 8.3.2] If a moveto is followed by multiple pairs of coordinates, 
+       * the subsequent pairs are treated as implicit lineto commands 
+       */
+      last_type = PATH_LINE;
       break;
     case PATH_LINE:
       bez.type = BEZ_LINE_TO;
diff --git a/lib/dia_svg.h b/lib/dia_svg.h
index 0240f4d..b421c42 100644
--- a/lib/dia_svg.h
+++ b/lib/dia_svg.h
@@ -59,6 +59,7 @@ struct _DiaSvgStyle {
 
 void dia_svg_style_init (DiaSvgStyle *gs, DiaSvgStyle *parent_style);
 void dia_svg_style_copy (DiaSvgStyle *dest, DiaSvgStyle *src);
+gboolean dia_svg_parse_color(const gchar *str, Color *color);
 void dia_svg_parse_style(xmlNodePtr node, DiaSvgStyle *s, real user_scale);
 /* parse the svg sub format for pathes int an array of BezPoint */
 GArray *dia_svg_parse_path(const gchar *path_str, gchar **unparsed, gboolean *closed, Point *current_point);
diff --git a/lib/libdia.def b/lib/libdia.def
index 9db86cb..663d196 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -352,6 +352,7 @@ EXPORTS
 
  dia_svg_style_init
  dia_svg_style_copy
+ dia_svg_parse_color
  dia_svg_parse_style
  dia_svg_parse_path
  dia_svg_parse_transform



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