diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-04-06 22:16:21 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-04-06 22:16:21 +0000 |
| commit | 03139d14786d177512f8d4ed953bf493f1bc2524 (patch) | |
| tree | 6acc7b35a5e68787924649ed32c5b7a5e62d5ef9 /src | |
| parent | Fix compilation with old libvisio (diff) | |
| download | inkscape-03139d14786d177512f8d4ed953bf493f1bc2524.tar.gz inkscape-03139d14786d177512f8d4ed953bf493f1bc2524.zip | |
EMF/WMF: Hopefully resolve locale issues with decimal separator for good
This unconditionally sets "LC_NUMERIC" to "C" to use dots (.) in all scanf/printf-like functions to prevent parsing issues with locales that would use a comma (,) instead.
Fixed bugs:
- https://launchpad.net/bugs/1549015
- https://launchpad.net/bugs/1675755
- https://launchpad.net/bugs/1335660
- https://launchpad.net/bugs/1089857
- https://launchpad.net/bugs/1599763
(bzr r15617)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/internal/emf-inout.cpp | 16 | ||||
| -rw-r--r-- | src/extension/internal/emf-print.cpp | 4 | ||||
| -rw-r--r-- | src/extension/internal/metafile-print.cpp | 27 | ||||
| -rw-r--r-- | src/extension/internal/wmf-inout.cpp | 16 |
4 files changed, 35 insertions, 28 deletions
diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 12751c5ec..92deb2e19 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -165,8 +165,16 @@ Emf::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena ext->set_param_bool("FixImageRot",new_FixImageRot); ext->set_param_bool("textToPath", new_val); + // ensure usage of dot as decimal separator in scanf/printf functions (indepentendly of current locale) + char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + print_document_to_file(doc, filename); + // restore decimal separator used in scanf/printf functions to initial value + setlocale(LC_NUMERIC, oldlocale); + g_free(oldlocale); + return; } @@ -3524,6 +3532,10 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) return NULL; } + // ensure usage of dot as decimal separator in scanf/printf functions (indepentendly of current locale) + char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + EMF_CALLBACK_DATA d; d.n_obj = 0; //these might not be set otherwise if the input file is corrupt @@ -3588,6 +3600,10 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) // in earlier versions no viewbox was generated and a call to setViewBoxIfMissing() was needed here. + // restore decimal separator used in scanf/printf functions to initial value + setlocale(LC_NUMERIC, oldlocale); + g_free(oldlocale); + return doc; } diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 826176bc0..147324b4f 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -251,11 +251,7 @@ unsigned int PrintEmf::begin(Inkscape::Extension::Print *mod, SPDocument *doc) g_error("Fatal programming error in PrintEmf::begin at textcomment_set 1"); } - char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "C"); snprintf(buff, sizeof(buff) - 1, "Drawing=%.1fx%.1fpx, %.1fx%.1fmm", _width, _height, Inkscape::Util::Quantity::convert(dwInchesX, "in", "mm"), Inkscape::Util::Quantity::convert(dwInchesY, "in", "mm")); - setlocale(LC_NUMERIC, oldlocale); - g_free(oldlocale); rec = textcomment_set(buff); if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { g_error("Fatal programming error in PrintEmf::begin at textcomment_set 1"); diff --git a/src/extension/internal/metafile-print.cpp b/src/extension/internal/metafile-print.cpp index 11567ceb3..68a425d85 100644 --- a/src/extension/internal/metafile-print.cpp +++ b/src/extension/internal/metafile-print.cpp @@ -355,27 +355,6 @@ 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: @@ -411,7 +390,7 @@ 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]; - snprintf_dots(text, 256, " M %f,%f A %f %f %f 0 0 %f %f A %f %f %f 0 0 %f %f z", + snprintf(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; @@ -440,7 +419,7 @@ 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]; - 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", + snprintf(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); @@ -462,7 +441,7 @@ 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]; - 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", + snprintf(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/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 8e602652a..e2d1433e4 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -161,8 +161,16 @@ Wmf::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena ext->set_param_bool("FixPPTPatternAsHatch",new_FixPPTPatternAsHatch); ext->set_param_bool("textToPath", new_val); + // ensure usage of dot as decimal separator in scanf/printf functions (indepentendly of current locale) + char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + print_document_to_file(doc, filename); + // restore decimal separator used in scanf/printf functions to initial value + setlocale(LC_NUMERIC, oldlocale); + g_free(oldlocale); + return; } @@ -3097,6 +3105,10 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) return NULL; } + // ensure usage of dot as decimal separator in scanf/printf functions (indepentendly of current locale) + char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + WMF_CALLBACK_DATA d; d.n_obj = 0; //these might not be set otherwise if the input file is corrupt @@ -3177,6 +3189,10 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) // in earlier versions no viewbox was generated and a call to setViewBoxIfMissing() was needed here. + // restore decimal separator used in scanf/printf functions to initial value + setlocale(LC_NUMERIC, oldlocale); + g_free(oldlocale); + return doc; } |
