dia r4188 - in trunk: . plug-ins/svg



Author: hans
Date: Sun Jan 11 20:02:20 2009
New Revision: 4188
URL: http://svn.gnome.org/viewvc/dia?rev=4188&view=rev

Log:
2009-01-11  Hans Breuer  <hans breuer org>

	* lib/dia_svg.c(read_text_svg) : support for text alignment, less warnings
	and text colors corrected even for DIA_SVG_COLOUR_NONE
	(read_items) : switched from if-continue to a more common if-else-if
	* plug-ins/svg/svg-import.c : use DIA_SVG_COLOUR_NONE instead of (-1)




Modified:
   trunk/ChangeLog
   trunk/plug-ins/svg/svg-import.c

Modified: trunk/plug-ins/svg/svg-import.c
==============================================================================
--- trunk/plug-ins/svg/svg-import.c	(original)
+++ trunk/plug-ins/svg/svg-import.c	Sun Jan 11 20:02:20 2009
@@ -310,15 +310,26 @@
       xmlFree(str);
     }
 
-    if (node->children && xmlStrcmp (node->children->name, "tspan") == 0) {
+    str = xmlGetProp(node, (const xmlChar *)"text-anchor");
+    if (str) {
+      if (xmlStrcmp(str, (const xmlChar*)"middle") == 0)
+        gs->alignment = ALIGN_CENTER;
+      else if (xmlStrcmp(str, (const xmlChar*)"end") == 0)
+        gs->alignment = ALIGN_RIGHT;
+      else if (xmlStrcmp(str, (const xmlChar*)"start") == 0)
+        gs->alignment = ALIGN_LEFT;
+      xmlFree(str);
+    }
+
+    if (node->children && xmlStrcmp (node->children->name, (const xmlChar*)"tspan") == 0) {
       xmlNode *tspan = node->children;
       GString *paragraph = g_string_sized_new(512);
 
       do {
         xmlChar *line = xmlNodeGetContent(tspan);
 	if (line) {
-	  g_string_append(paragraph, line);
-	  if (tspan->next && xmlStrcmp (tspan->next->name, "tspan") == 0)
+	  g_string_append(paragraph, (gchar*)line);
+	  if (tspan->next && xmlStrcmp (tspan->next->name, (const xmlChar*)"tspan") == 0)
 	    g_string_append(paragraph, "\n");
 	  xmlFree(line);
 	}
@@ -357,13 +368,15 @@
       /* when operating with default values foreground and background are intentionally swapped
        * to avoid getting white text by default */
       switch (gs->fill) {
+      case DIA_SVG_COLOUR_NONE :
+        /* don't use -1 which would be almost white */
       case DIA_SVG_COLOUR_TEXT :
-      case DIA_SVG_COLOUR_FOREGROUND :
-        prop->attr.color = attributes_get_background();
-	break;
       case DIA_SVG_COLOUR_BACKGROUND :
         prop->attr.color = attributes_get_foreground();
 	break;
+      case DIA_SVG_COLOUR_FOREGROUND :
+        prop->attr.color = attributes_get_background();
+	break;
       default :
         prop->attr.color = get_colour (gs->fill);
 	break;
@@ -438,7 +451,7 @@
   DiaObject *new_obj;
   Handle *h1, *h2;
   GPtrArray *props;
-  Point start;
+  Point start = {0, 0};
   
   str = xmlGetProp(node, (const xmlChar *)"cx");
   if (str) {
@@ -472,8 +485,10 @@
     width = height = get_value_as_cm((char *) str, NULL)*2;
     xmlFree(str);
   }
-  if (width <= 0.0 || height <= 0.0)
+  if (width <= 0.0 || height <= 0.0) {
+    g_debug ("Ellipse too small %gx%g", width, height);
     return list;
+  }
   new_obj = otype->ops->create(&start, otype->default_user_data,
 				 &h1, &h2);
   apply_style(new_obj, node, parent_style);			
@@ -660,38 +675,32 @@
       if (group_gs->font)
         dia_font_unref (group_gs->font);
       g_free (group_gs);
-      continue;
-    }
-    if (!xmlStrcmp(node->name, (const xmlChar *)"rect")) {
+    } else if (!xmlStrcmp(node->name, (const xmlChar *)"rect")) {
       items = read_rect_svg(node, parent_gs, items);
-      continue;
-    }
-    if (!xmlStrcmp(node->name, (const xmlChar *)"line")) {
+    } else if (!xmlStrcmp(node->name, (const xmlChar *)"line")) {
       items = read_line_svg(node, parent_gs, items);
-      continue;
-    }
-    if (!xmlStrcmp(node->name, (const xmlChar *)"ellipse") || !xmlStrcmp(node->name, (const xmlChar *)"circle")) {
+    } else if (!xmlStrcmp(node->name, (const xmlChar *)"ellipse") || !xmlStrcmp(node->name, (const xmlChar *)"circle")) {
       items = read_ellipse_svg(node, parent_gs, items);
-      continue;
-    }
-    if (!xmlStrcmp(node->name, (const xmlChar *)"polyline")) {
+    } else if (!xmlStrcmp(node->name, (const xmlChar *)"polyline")) {
       /* Uh, oh, no : apparently a fill="" in a group above make this a polygon */
       items = read_poly_svg(node, parent_gs, items, parent_gs && parent_gs->fill >= 0 ?
                             "Standard - Polygon" : "Standard - PolyLine");
-      continue;
-    }
-    if (!xmlStrcmp(node->name, (const xmlChar *)"polygon")) {
+    } else if (!xmlStrcmp(node->name, (const xmlChar *)"polygon")) {
       items = read_poly_svg(node, parent_gs, items, "Standard - Polygon");
-      continue;
-    }
-    if(!xmlStrcmp(node->name, (const xmlChar *)"text")) {
+    } else if(!xmlStrcmp(node->name, (const xmlChar *)"text")) {
       items = read_text_svg(node, parent_gs, items);
-      continue;
-    }
-    if(!xmlStrcmp(node->name, (const xmlChar *)"path")) {
+    } else if(!xmlStrcmp(node->name, (const xmlChar *)"path")) {
       items = read_path_svg(node, parent_gs, items);
-      continue;
-    }
+    } else {
+      /* everything else is treated like a group _without grouping_, i.e. we dive into unknown stuff */
+      /* this allows to import stuff generated by 'dot' with links for the nodes */
+      GList *moreitems;
+
+      moreitems = read_items (node->xmlChildrenNode, parent_gs);
+      if (moreitems) {
+        items = g_list_concat (items, moreitems);
+      }
+   }
   }
   return items;
 }



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