[dia] svg: adjust coloring order for <use/>



commit 04928770a8c547ea73e412b5a3d2d094ee8f93d9
Author: Hans Breuer <hans breuer org>
Date:   Sun Jul 21 00:16:17 2013 +0200

    svg: adjust coloring order for <use/>
    
    The template color should not be overwritten by later fill:none.
    I'm uncertain if it is supposed to be overwritten at all, but
    currently Dia's implementations does it. For reference see:
    http://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#UseElement
    An example of the easy case now working:
    http://openclipart.org/people/h0us3s/h0us3s_Signs_Hazard_Warning.svg

 lib/dia_svg.c             |    5 ++++-
 lib/dia_svg.h             |    3 ++-
 plug-ins/svg/svg-import.c |   30 +++++++++++++++++++-----------
 3 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index f19c4af..9a70d0e 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -58,7 +58,10 @@ dia_svg_style_init(DiaSvgStyle *gs, DiaSvgStyle *parent_style)
   gs->line_width = parent_style ? parent_style->line_width : 0.0;
   gs->linestyle = parent_style ? parent_style->linestyle : LINESTYLE_SOLID;
   gs->dashlength = parent_style ? parent_style->dashlength : 1;
-  gs->fill = parent_style ? parent_style->fill : DIA_SVG_COLOUR_NONE;
+  /* http://www.w3.org/TR/SVG/painting.html#FillProperty - default black
+   * but we still have to see the difference
+   */ 
+  gs->fill = parent_style ? parent_style->fill : DIA_SVG_COLOUR_DEFAULT_FILL;
   gs->fill_opacity = parent_style ? parent_style->fill_opacity : 1.0;
   gs->linecap = parent_style ? parent_style->linecap : DIA_SVG_LINECAPS_DEFAULT;
   gs->linejoin = parent_style ? parent_style->linejoin : DIA_SVG_LINEJOIN_DEFAULT;
diff --git a/lib/dia_svg.h b/lib/dia_svg.h
index f872b18..fa89d6e 100644
--- a/lib/dia_svg.h
+++ b/lib/dia_svg.h
@@ -28,7 +28,8 @@ enum DiaSvgColours
   DIA_SVG_COLOUR_NONE = -1,
   DIA_SVG_COLOUR_FOREGROUND = -2,
   DIA_SVG_COLOUR_BACKGROUND = -3,
-  DIA_SVG_COLOUR_TEXT = -4
+  DIA_SVG_COLOUR_TEXT = -4,
+  DIA_SVG_COLOUR_DEFAULT_FILL = -5
 };
 
 /* these should be changed if they ever cause a conflict */
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 68bad3f..a239d7a 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -284,7 +284,7 @@ use_position (DiaObject *obj, xmlNodePtr node)
 
 /* apply SVG style to object */
 static void
-apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style) 
+apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style, gboolean init_fill)
 {
       DiaSvgStyle *gs;
       GPtrArray *props;
@@ -329,7 +329,12 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style)
       lsprop->dash = gs->dashlength * scale;
 
       cprop = g_ptr_array_index(props,3);
-      if(gs->fill == DIA_SVG_COLOUR_NONE) /* transparent */
+      if (gs->fill == DIA_SVG_COLOUR_DEFAULT_FILL) {
+       if (init_fill)
+         cprop->color_data = get_colour(0x000000, 1.0); /* black */
+       else
+         cprop->common.experience |= PXP_NOTSET; /* no overwrite */
+      } else if (gs->fill == DIA_SVG_COLOUR_NONE) /* transparent */
        cprop->color_data = get_colour(0x000000, 0.0);
       else if (gs->fill == DIA_SVG_COLOUR_FOREGROUND)
        cprop->color_data = attributes_get_foreground();
@@ -451,7 +456,7 @@ read_path_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list, DiaContex
        if (!closed)
          reset_arrows (new_obj);
        g_free(bcd);
-       apply_style(new_obj, node, parent_style);
+       apply_style(new_obj, node, parent_style, TRUE);
        list = g_list_append (list, new_obj);
 
         g_array_set_size (bezpoints, 0);
@@ -598,6 +603,9 @@ read_text_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
       case DIA_SVG_COLOUR_BACKGROUND :
         prop->attr.color = attributes_get_foreground();
        break;
+      case DIA_SVG_COLOUR_DEFAULT_FILL: /* black */
+       prop->attr.color = get_colour(0x000000, 1.0);
+       break;
       case DIA_SVG_COLOUR_FOREGROUND :
         prop->attr.color = attributes_get_background();
        break;
@@ -670,7 +678,7 @@ read_poly_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list, char *obj
     new_obj = otype->ops->create(NULL, pcd,
                                 &h1, &h2);
     reset_arrows (new_obj);
-    apply_style(new_obj, node, parent_style);
+    apply_style(new_obj, node, parent_style, TRUE);
     list = g_list_append (list, new_obj);
     g_free(points);
     g_free(pcd);
@@ -737,8 +745,8 @@ read_ellipse_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
     return list;
   new_obj = otype->ops->create(&start, otype->default_user_data,
                                 &h1, &h2);
-  apply_style(new_obj, node, parent_style);                    
-        
+  apply_style(new_obj, node, parent_style, TRUE);
+
   props = make_element_props(start.x-(width/2), start.y-(height/2),
                              width, height);
   new_obj->ops->set_props(new_obj, props);
@@ -813,8 +821,8 @@ read_line_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
 
   prop_list_free(props);
 
-  apply_style(new_obj, node, parent_style);
-  
+  apply_style(new_obj, node, parent_style, TRUE);
+
   return g_list_append (list, new_obj);
 }
 
@@ -911,8 +919,8 @@ read_rect_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
   prop_list_free(props);
   props = make_element_props(start.x,start.y,width,height);
   new_obj->ops->set_props(new_obj, props);
-  
-  apply_style(new_obj, node, parent_style);
+
+  apply_style(new_obj, node, parent_style, TRUE);
   prop_list_free(props);
 
   return list;
@@ -1185,7 +1193,7 @@ read_items (xmlNodePtr   startnode,
          DiaObject *onew = otemp->ops->copy (otemp);
 
          use_position (onew, node);
-         apply_style (onew, node, parent_gs);
+         apply_style (onew, node, parent_gs, FALSE);
          items = g_list_append (items, onew);
        }
        xmlFree (key);


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