diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp
index 102d7b74c93c6f21d13e891208b0ceb1cbe887e4..3b13e3d89018bbf4889e695f46cb0d8edb8258a3 100644 (file)
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
}
/* Determine the actual number of fractional digits */
- fprec = MAX(fprec, tprec - idigits);
+ fprec = MAX(fprec, tprec - idigits - 1);
/* Round value */
val += 0.5 * pow(10.0, - ((double) fprec));
/* Extract integral and fractional parts */
@@ -127,17 +127,21 @@ static unsigned sp_svg_number_write_d(gchar *buf, double val, unsigned int tprec
return end_i;
}
-unsigned int sp_svg_number_write_de(gchar *buf, double val, unsigned int tprec, unsigned int padf)
+unsigned int sp_svg_number_write_de(gchar *buf, double val, unsigned int tprec, int min_exp, unsigned int padf)
{
if (val == 0.0 || (fabs(val) >= 0.1 && fabs(val) < 10000000)) {
return sp_svg_number_write_d(buf, val, tprec, 0, padf);
} else {
double eval = floor(log10(fabs(val)));
- val = val / pow(10.0, eval);
- int p = sp_svg_number_write_d(buf, val, tprec, 0, padf);
- buf[p++] = 'e';
- p += sp_svg_number_write_i(buf + p, (int) eval);
- return p;
+ if ((int) eval < min_exp) {
+ return sp_svg_number_write_d(buf, 0, tprec, 0, padf);
+ } else {
+ val = val / pow(10.0, eval);
+ int p = sp_svg_number_write_d(buf, val, tprec, 0, padf);
+ buf[p++] = 'e';
+ p += sp_svg_number_write_i(buf + p, (int) eval);
+ return p;
+ }
}
}