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

SVG export changes



Hi,

I started using dia yesterday for converting DXF to SVG. There are some
bugs in the SVG export plugin :
- arcs are not converted correctly
- fill: none seems to be required
- text alignment is incorrect.

I have fixed (and tested the fixes) those bugs on a copy of 0.88.1, and
then updated the diff to apply to the CVS version. However, I have not
tested the CVS version since I cannot get it to compile here.
(first attached diff is to 0.88.1, second diff is to CVS)

regards,

Frank Gevaerts                                 frank.gevaerts@fks.be
fks bvba - Formal and Knowledge Systems        http://www.fks.be/
Luikersteenweg 65                              Tel:  ++32-(0)11-21 49 11
B-3500 HASSELT                                 Fax:  ++32-(0)11-22 04 19
--- render_svg.c.orig	Sat Jan 19 11:01:13 2002
+++ render_svg.c	Thu Jan 24 17:07:02 2002
@@ -401,7 +401,7 @@
   if (!str) str = g_string_new(NULL);
   g_string_truncate(str, 0);
 
-  g_string_sprintf(str, "stroke-width: %g", renderer->linewidth);
+  g_string_sprintf(str, "fill: none; stroke-width: %g", renderer->linewidth);
   if (strcmp(renderer->linecap, "butt"))
     g_string_sprintfa(str, "; stroke-linecap: %s", renderer->linecap);
   if (strcmp(renderer->linejoin, "miter"))
@@ -558,6 +558,19 @@
   xmlSetProp(node, "height", buf);
 }
 
+static int sweep(real x1,real y1,real x2,real y2,real x3,real y3)
+{
+  real X2=x2-x1;
+  real Y2=y2-y1;
+  real X3=x3-x1;
+  real Y3=y3-y1;
+  real L=sqrt(X2*X2+Y2*Y2);
+  real cost=X2/L;
+  real sint=Y2/L;
+  real res=-X3*sint+Y3*cost;
+  return res>0;
+}
+
 static void
 draw_arc(RendererSVG *renderer, 
 	 Point *center,
@@ -568,16 +581,22 @@
   xmlNodePtr node;
   char buf[512];
   real rx = width / 2, ry = height / 2;
+  real x1=center->x + rx*cos(angle1*M_PI/180);
+  real y1=center->y - ry*sin(angle1*M_PI/180);
+  real x2=center->x + rx*cos(angle2*M_PI/180);
+  real y2=center->y - ry*sin(angle2*M_PI/180);
+  int swp = sweep(x1,y1,x2,y2,center->x,center->y);
+  int l_arc = (angle2 - angle1) > 180;
 
   node = xmlNewChild(renderer->root, NULL, "path", NULL);
   
   xmlSetProp(node, "style", get_draw_style(renderer, colour));
 
   /* this path might be incorrect ... */
-  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d 1 %g,%g",
-	     center->x + rx*cos(angle1), center->y + ry * sin(angle1),
-	     rx, ry, (angle2 - angle1 > 0),
-	     center->x + rx*cos(angle2), center->y + ry * sin(angle2));
+  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d %d %g,%g",
+	     x1, y1,
+	     rx, ry,l_arc ,swp ,
+	     x2, y2);
 
   xmlSetProp(node, "d", buf);
 }
@@ -592,16 +611,22 @@
   xmlNodePtr node;
   char buf[512];
   real rx = width / 2, ry = height / 2;
+  real x1=center->x + rx*cos(angle1*M_PI/180);
+  real y1=center->y - ry*sin(angle1*M_PI/180);
+  real x2=center->x + rx*cos(angle2*M_PI/180);
+  real y2=center->y - ry*sin(angle2*M_PI/180);
+  int swp = sweep(x1,y1,x2,y2,center->x,center->y);
+  int l_arc = (angle2 - angle1) > 180;
 
   node = xmlNewChild(renderer->root, NULL, "path", NULL);
   
   xmlSetProp(node, "style", get_fill_style(renderer, colour));
 
   /* this path might be incorrect ... */
-  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d 1 %g,%g L %g,%g z",
-	     center->x + rx*cos(angle1), center->y + ry * sin(angle1),
-	     rx, ry, (angle2 - angle1 > 0),
-	     center->x + rx*cos(angle2), center->y + ry * sin(angle2),
+  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d %d %g,%g L %g,%g z",
+	     x1, y1,
+	     rx, ry,l_arc ,swp ,
+	     x2, y2,
 	     center->x, center->y);
 
   xmlSetProp(node, "d", buf);
@@ -768,13 +793,13 @@
   renderer->linewidth = saved_width;
   switch (alignment) {
   case ALIGN_LEFT:
-    style = g_strconcat(style, "; text-anchor: left", NULL);
+    style = g_strconcat(style, "; text-anchor: start", NULL);
     break;
   case ALIGN_CENTER:
-    style = g_strconcat(style, "; text-anchor: middle", NULL);
+    style = g_strconcat(style, "; text-anchor: center", NULL);
     break;
   case ALIGN_RIGHT:
-    style = g_strconcat(style, "; text-anchor: right", NULL);
+    style = g_strconcat(style, "; text-anchor: end", NULL);
     break;
   }
   tmp = g_strdup_printf("%s; font-size: %g", style, renderer->fontsize);
--- dia-0.88.1.orig/plug-ins/svg/render_svg.c	Sat May 19 06:58:28 2001
+++ dia-0.88.1/plug-ins/svg/render_svg.c	Thu Jan 24 16:43:16 2002
@@ -400,7 +400,7 @@
   if (!str) str = g_string_new(NULL);
   g_string_truncate(str, 0);
 
-  g_string_sprintf(str, "stroke-width: %g", renderer->linewidth);
+  g_string_sprintf(str, "fill: none; stroke-width: %g", renderer->linewidth);
   if (strcmp(renderer->linecap, "butt"))
     g_string_sprintfa(str, "; stroke-linecap: %s", renderer->linecap);
   if (strcmp(renderer->linejoin, "miter"))
@@ -557,6 +557,19 @@
   xmlSetProp(node, "height", buf);
 }
 
+static int sweep(real x1,real y1,real x2,real y2,real x3,real y3)
+{
+  real X2=x2-x1;
+  real Y2=y2-y1;
+  real X3=x3-x1;
+  real Y3=y3-y1;
+  real L=sqrt(X2*X2+Y2*Y2);
+  real cost=X2/L;
+  real sint=Y2/L;
+  real res=-X3*sint+Y3*cost;
+  return res>0;
+}
+
 static void
 draw_arc(RendererSVG *renderer, 
 	 Point *center,
@@ -567,16 +580,22 @@
   xmlNodePtr node;
   char buf[512];
   real rx = width / 2, ry = height / 2;
+  real x1=center->x + rx*cos(angle1*M_PI/180);
+  real y1=center->y - ry*sin(angle1*M_PI/180);
+  real x2=center->x + rx*cos(angle2*M_PI/180);
+  real y2=center->y - ry*sin(angle2*M_PI/180);
+  int swp = sweep(x1,y1,x2,y2,center->x,center->y);
+  int l_arc = (angle2 - angle1) > 180;
 
   node = xmlNewChild(renderer->root, NULL, "path", NULL);
   
   xmlSetProp(node, "style", get_draw_style(renderer, colour));
 
   /* this path might be incorrect ... */
-  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d 1 %g,%g",
-	     center->x + rx*cos(angle1), center->y + ry * sin(angle1),
-	     rx, ry, (angle2 - angle1 > 0),
-	     center->x + rx*cos(angle2), center->y + ry * sin(angle2));
+  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d %d %g,%g",
+	     x1, y1,
+	     rx, ry,l_arc ,swp ,
+	     x2, y2);
 
   xmlSetProp(node, "d", buf);
 }
@@ -591,16 +610,22 @@
   xmlNodePtr node;
   char buf[512];
   real rx = width / 2, ry = height / 2;
+  real x1=center->x + rx*cos(angle1*M_PI/180);
+  real y1=center->y - ry*sin(angle1*M_PI/180);
+  real x2=center->x + rx*cos(angle2*M_PI/180);
+  real y2=center->y - ry*sin(angle2*M_PI/180);
+  int swp = sweep(x1,y1,x2,y2,center->x,center->y);
+  int l_arc = (angle2 - angle1) > 180;
 
   node = xmlNewChild(renderer->root, NULL, "path", NULL);
   
   xmlSetProp(node, "style", get_fill_style(renderer, colour));
 
   /* this path might be incorrect ... */
-  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d 1 %g,%g L %g,%g z",
-	     center->x + rx*cos(angle1), center->y + ry * sin(angle1),
-	     rx, ry, (angle2 - angle1 > 0),
-	     center->x + rx*cos(angle2), center->y + ry * sin(angle2),
+  g_snprintf(buf, sizeof(buf), "M %g,%g A %g,%g 0 %d %d %g,%g L %g,%g z",
+	     x1, y1,
+	     rx, ry,l_arc ,swp ,
+	     x2, y2,
 	     center->x, center->y);
 
   xmlSetProp(node, "d", buf);
@@ -758,13 +783,13 @@
   renderer->linewidth = saved_width;
   switch (alignment) {
   case ALIGN_LEFT:
-    style = g_strconcat(style, "; text-align: left", NULL);
+    style = g_strconcat(style, "; text-anchor: start", NULL);
     break;
   case ALIGN_CENTER:
-    style = g_strconcat(style, "; text-align: center", NULL);
+    style = g_strconcat(style, "; text-anchor: middle", NULL);
     break;
   case ALIGN_RIGHT:
-    style = g_strconcat(style, "; text-align: right", NULL);
+    style = g_strconcat(style, "; text-anchor: end", NULL);
     break;
   }
   tmp = g_strdup_printf("%s; font-size: %g", style, renderer->fontsize);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK