[dia] svg: support linejoin and linecap style and attribute



commit c1e14681f7f15839bc03be223aa292aed9722322
Author: Hans Breuer <hans breuer org>
Date:   Sat Aug 3 18:22:37 2013 +0200

    svg: support linejoin and linecap style and attribute
    
    Tested with unmodified files from
    REC-SVG11-20110816/images/painting/linecap.svg
    REC-SVG11-20110816/images/painting/linejoin.svg

 lib/dia_svg.c             |   54 +++++++++++++++++++++++++++++++-------------
 plug-ins/svg/svg-import.c |   21 +++++++++++++++-
 2 files changed, 57 insertions(+), 18 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index 2e73b42..9cb5621 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -308,6 +308,31 @@ _parse_dasharray (DiaSvgStyle *s, real user_scale, gchar *str, gchar **end)
     *end = ptr;
 }
 
+static void
+_parse_linejoin (DiaSvgStyle *s, const char *val)
+{
+  if (!strncmp(val, "miter", 5))
+    s->linejoin = LINEJOIN_MITER;
+  else if (!strncmp(val, "round", 5))
+    s->linejoin = LINEJOIN_ROUND;
+  else if (!strncmp(val, "bevel", 5))
+    s->linejoin = LINEJOIN_BEVEL;
+  else if (!strncmp(val, "default", 7))
+    s->linejoin = DIA_SVG_LINEJOIN_DEFAULT;
+}
+static void
+_parse_linecap (DiaSvgStyle *s, const char *val)
+{
+  if (!strncmp(val, "butt", 4))
+    s->linecap = LINECAPS_BUTT;
+  else if (!strncmp(val, "round", 5))
+    s->linecap = LINECAPS_ROUND;
+  else if (!strncmp(val, "square", 6) || !strncmp(val, "projecting", 10))
+    s->linecap = LINECAPS_PROJECTING;
+  else if (!strncmp(val, "default", 7))
+    s->linecap = DIA_SVG_LINECAPS_DEFAULT;
+}
+
 /*
  * \brief Parse SVG/CSS style string
  *
@@ -445,27 +470,13 @@ dia_svg_parse_style_string (DiaSvgStyle *s, real user_scale, const gchar *str)
       while (ptr[0] != '\0' && g_ascii_isspace(ptr[0])) ptr++;
       if (ptr[0] == '\0') break;
 
-      if (!strncmp(ptr, "butt", 4))
-       s->linecap = LINECAPS_BUTT;
-      else if (!strncmp(ptr, "round", 5))
-       s->linecap = LINECAPS_ROUND;
-      else if (!strncmp(ptr, "square", 6) || !strncmp(ptr, "projecting", 10))
-       s->linecap = LINECAPS_PROJECTING;
-      else if (!strncmp(ptr, "default", 7))
-       s->linecap = DIA_SVG_LINECAPS_DEFAULT;
+      _parse_linecap (s, ptr);
     } else if (!strncmp("stroke-linejoin:", ptr, 16)) {
       ptr += 16;
       while (ptr[0] != '\0' && g_ascii_isspace(ptr[0])) ptr++;
       if (ptr[0] == '\0') break;
 
-      if (!strncmp(ptr, "miter", 5))
-       s->linejoin = LINEJOIN_MITER;
-      else if (!strncmp(ptr, "round", 5))
-       s->linejoin = LINEJOIN_ROUND;
-      else if (!strncmp(ptr, "bevel", 5))
-       s->linejoin = LINEJOIN_BEVEL;
-      else if (!strncmp(ptr, "default", 7))
-       s->linejoin = DIA_SVG_LINEJOIN_DEFAULT;
+      _parse_linejoin (s, ptr);
     } else if (!strncmp("stroke-pattern:", ptr, 15)) {
       ptr += 15;
       while (ptr[0] != '\0' && g_ascii_isspace(ptr[0])) ptr++;
@@ -629,6 +640,17 @@ dia_svg_parse_style(xmlNodePtr node, DiaSvgStyle *s, real user_scale)
     _parse_dasharray (s, user_scale, (gchar *)str, NULL);
     xmlFree(str);
   }
+  str = xmlGetProp(node, (const xmlChar *)"stroke-linejoin");
+  if (str) {
+    _parse_linejoin (s, (gchar *)str);
+    xmlFree(str);
+  }
+  str = xmlGetProp(node, (const xmlChar *)"stroke-linecap");
+  if (str) {
+    _parse_linecap (s, (gchar *)str);
+    xmlFree(str);
+  }
+  
   /* text-props, again ;( */
   str = xmlGetProp(node, (const xmlChar *)"font-size");
   if (str) {
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index b10bbf9..0b64f66 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -123,6 +123,8 @@ static PropDescription svg_style_prop_descs[] = {
     { "line_style", PROP_TYPE_LINESTYLE},
     { "fill_colour", PROP_TYPE_COLOUR },
     { "show_background", PROP_TYPE_BOOL },
+    { "line_join", PROP_TYPE_ENUM },
+    { "line_caps", PROP_TYPE_ENUM },
     PROP_DESC_END};
 
 static PropDescription svg_element_prop_descs[] = {
@@ -357,6 +359,7 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
       ColorProperty *cprop;
       RealProperty *rprop;
       BoolProperty *bprop;
+      EnumProperty *eprop;
       real scale = 1.0;
 
       xmlChar *str = xmlGetProp(node, (const xmlChar *)"transform");
@@ -387,7 +390,7 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
 
       dia_svg_parse_style(node, gs, user_scale);
       props = prop_list_from_descs(svg_style_prop_descs, pdtpp_true);
-      g_assert(props->len == 5);
+      g_assert(props->len == 7);
   
       cprop = g_ptr_array_index(props,0);
       if (gs->stroke == DIA_SVG_COLOUR_DEFAULT) {
@@ -438,6 +441,18 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
        bprop->bool_data = TRUE;
       }
 
+      eprop = g_ptr_array_index(props,5);
+      if (gs->linejoin != DIA_SVG_LINEJOIN_DEFAULT)
+       eprop->enum_data = gs->linejoin;
+      else
+       eprop->common.experience |= PXP_NOTSET;
+
+      eprop = g_ptr_array_index(props,6);
+      if (gs->linecap != DIA_SVG_LINECAPS_DEFAULT)
+        eprop->enum_data = gs->linecap;
+      else
+       eprop->common.experience |= PXP_NOTSET;
+
       obj->ops->set_props(obj, props);
       
       if (gs->font)
@@ -1317,7 +1332,9 @@ read_items (xmlNodePtr   startnode,
          /* pass ownership of name and object */
          g_hash_table_insert (defs_ht, id, otemp);
        } else if (IS_GROUP (otemp)) {
-         /* defs in groups, I don't get the benefit */
+         /* defs in _unnamed_ groups, I don't get the
+          * benefit but must have seen it in the wild.
+          */
          GList *moredefs = group_objects (otemp);
 
          g_list_foreach (moredefs, add_def, defs_ht);


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