summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-03-06 01:00:39 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-03-06 01:00:39 +0000
commit940e63b3a27e3dc7a30f5c72c445b4323f570e1a (patch)
treeb61df6ac899a94ec53535b003e064dcde2f100c0
parentFix ACLs (diff)
downloadinkscape-940e63b3a27e3dc7a30f5c72c445b4323f570e1a.tar.gz
inkscape-940e63b3a27e3dc7a30f5c72c445b4323f570e1a.zip
EMF/WFM export: Fix crash when selecting "Convert gradients to colored polygon series"
The problem where calls of "sprintf()" to format SVG path data. Unfortunately depending on the locale set at this point via "setlocale()" the output could contain commas (,) instead of dots (.) as decimal spearator resulting in invalid path data. Fixed bugs: - https://launchpad.net/bugs/1549015 (bzr r15568)
-rw-r--r--src/extension/internal/metafile-print.cpp34
-rw-r--r--src/extension/internal/metafile-print.h1
2 files changed, 29 insertions, 6 deletions
diff --git a/src/extension/internal/metafile-print.cpp b/src/extension/internal/metafile-print.cpp
index 061eb634d..11567ceb3 100644
--- a/src/extension/internal/metafile-print.cpp
+++ b/src/extension/internal/metafile-print.cpp
@@ -355,6 +355,27 @@ int PrintMetafile::hold_gradient(void *gr, int mode)
return 1;
}
+/* behaves like snprintf() but makes sure decimal separators are formatted as dots
+ otherwise invalid strings can be produced depending on the set locale
+*/
+int PrintMetafile::snprintf_dots(char * s, size_t n, const char * format, ...)
+{
+ int nChars;
+
+ char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL));
+ setlocale(LC_NUMERIC, "C");
+
+ va_list argptr;
+ va_start(argptr, format);
+ nChars = vsnprintf(s, n, format, argptr);
+ va_end(argptr);
+
+ setlocale(LC_NUMERIC, oldlocale);
+ g_free(oldlocale);
+
+ return nChars;
+}
+
/* convert from center ellipse to SVGEllipticalArc ellipse
From:
@@ -390,7 +411,8 @@ Geom::PathVector PrintMetafile::center_ellipse_as_SVG_PathV(Geom::Point ctr, dou
y2 = ctr[Y] + sin(F) * rx * cos(M_PI) + cos(F) * ry * sin(M_PI);
char text[256];
- sprintf(text, " M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z", x1, y1, rx, ry, F * 360. / (2.*M_PI), x2, y2, rx, ry, F * 360. / (2.*M_PI), x1, y1);
+ snprintf_dots(text, 256, " M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z",
+ x1, y1, rx, ry, F * 360. / (2.*M_PI), x2, y2, rx, ry, F * 360. / (2.*M_PI), x1, y1);
Geom::PathVector outres = Geom::parse_svg_path(text);
return outres;
}
@@ -418,9 +440,9 @@ Geom::PathVector PrintMetafile::center_elliptical_ring_as_SVG_PathV(Geom::Point
y22 = ctr[Y] + sin(F) * rx2 * cos(M_PI) + cos(F) * ry2 * sin(M_PI);
char text[512];
- sprintf(text, " M %f,%f A %f %f %f 0 1 %f %f A %f %f %f 0 1 %f %f z M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z",
- x11, y11, rx1, ry1, degrot, x12, y12, rx1, ry1, degrot, x11, y11,
- x21, y21, rx2, ry2, degrot, x22, y22, rx2, ry2, degrot, x21, y21);
+ snprintf_dots(text, 512, " M %f,%f A %f %f %f 0 1 %f %f A %f %f %f 0 1 %f %f z M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z",
+ x11, y11, rx1, ry1, degrot, x12, y12, rx1, ry1, degrot, x11, y11,
+ x21, y21, rx2, ry2, degrot, x22, y22, rx2, ry2, degrot, x21, y21);
Geom::PathVector outres = Geom::parse_svg_path(text);
return outres;
@@ -440,8 +462,8 @@ Geom::PathVector PrintMetafile::center_elliptical_hole_as_SVG_PathV(Geom::Point
y2 = ctr[Y] + sin(F) * rx * cos(M_PI) + cos(F) * ry * sin(M_PI);
char text[256];
- sprintf(text, " M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z M 50000,50000 50000,-50000 -50000,-50000 -50000,50000 z",
- x1, y1, rx, ry, F * 360. / (2.*M_PI), x2, y2, rx, ry, F * 360. / (2.*M_PI), x1, y1);
+ snprintf_dots(text, 256, " M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z M 50000,50000 50000,-50000 -50000,-50000 -50000,50000 z",
+ x1, y1, rx, ry, F * 360. / (2.*M_PI), x2, y2, rx, ry, F * 360. / (2.*M_PI), x1, y1);
Geom::PathVector outres = Geom::parse_svg_path(text);
return outres;
}
diff --git a/src/extension/internal/metafile-print.h b/src/extension/internal/metafile-print.h
index d184b72b7..9903cbb98 100644
--- a/src/extension/internal/metafile-print.h
+++ b/src/extension/internal/metafile-print.h
@@ -101,6 +101,7 @@ protected:
static void swapRBinRGBA(char *px, int pixels);
int hold_gradient(void *gr, int mode);
+ static int snprintf_dots(char * s, size_t n, const char * format, ...);
static Geom::PathVector center_ellipse_as_SVG_PathV(Geom::Point ctr, double rx, double ry, double F);
static Geom::PathVector center_elliptical_ring_as_SVG_PathV(Geom::Point ctr, double rx1, double ry1, double rx2, double ry2, double F);
static Geom::PathVector center_elliptical_hole_as_SVG_PathV(Geom::Point ctr, double rx, double ry, double F);