Skip to content

Commit b516ae0

Browse files
committed
Merge pull request matplotlib#369 from mdboom/svg_locale_fix
Fix SVG path data writing so it always uses '.' as a decimal point.
2 parents 2325aad + ff858b6 commit b516ae0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/_path.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -1524,8 +1524,10 @@ _path_module::convert_to_svg(const Py::Tuple& args)
15241524

15251525
int precision = Py::Int(args[4]);
15261526

1527+
#if PY_VERSION_HEX < 0x02070000
15271528
char format[64];
15281529
snprintf(format, 64, "%s.%dg", "%", precision);
1530+
#endif
15291531

15301532
typedef agg::conv_transform<PathIterator> transformed_path_t;
15311533
typedef PathNanRemover<transformed_path_t> nan_removal_t;
@@ -1568,9 +1570,23 @@ _path_module::convert_to_svg(const Py::Tuple& args)
15681570
*p++ = ' ';
15691571
}
15701572

1571-
p += snprintf(p, buffersize - (p - buffer), format, x);
1573+
#if PY_VERSION_HEX >= 0x02070000
1574+
char* str;
1575+
str = PyOS_double_to_string(x, 'g', precision, 0, NULL);
1576+
p += snprintf(p, buffersize - (p - buffer), str);
1577+
PyMem_Free(str);
15721578
*p++ = ' ';
1573-
p += snprintf(p, buffersize - (p - buffer), format, y);
1579+
str = PyOS_double_to_string(y, 'g', precision, 0, NULL);
1580+
p += snprintf(p, buffersize - (p - buffer), str);
1581+
PyMem_Free(str);
1582+
#else
1583+
char str[64];
1584+
PyOS_ascii_formatd(str, 64, format, x);
1585+
p += snprintf(p, buffersize - (p - buffer), str);
1586+
*p++ = ' ';
1587+
PyOS_ascii_formatd(str, 64, format, y);
1588+
p += snprintf(p, buffersize - (p - buffer), str);
1589+
#endif
15741590

15751591
--wait;
15761592
}

0 commit comments

Comments
 (0)