Code

Corrected initialization order.
[inkscape.git] / src / svg / css-ostringstream.cpp
index 91b1cfcfb06378a7903c3a2791ce11856f40edb7..a6eb2783e3c3e834354d2185686df5066ee178f2 100644 (file)
@@ -1,5 +1,6 @@
 #include "svg/css-ostringstream.h"
 #include "svg/strip-trailing-zeros.h"
+#include "preferences.h"
 #include <glib/gmessages.h>
 #include <glib/gstrfuncs.h>
 
@@ -13,21 +14,27 @@ Inkscape::CSSOStringStream::CSSOStringStream()
     /* This one is (currently) needed though, as we currently use ostr.precision as a sort of
        variable for storing the desired precision: see our two precision methods and our operator<<
        methods for float and double. */
-    ostr.precision(8);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    ostr.precision(prefs->getInt("/options/svgoutput/numericprecision", 8));
 }
 
 static void
 write_num(Inkscape::CSSOStringStream &os, unsigned const prec, double const d)
 {
     char buf[32];  // haven't thought about how much is really required.
-    if (prec != 8) {
-        static bool warned;
-        if (!warned) {
-            g_warning("Using precision of 8 instead of the requested %u.  Won't re-warn.", prec);
-            warned = true;
-        }
+    switch (prec) {
+        case 9: g_ascii_formatd(buf, sizeof(buf), "%.9f", d); break;
+        case 8: g_ascii_formatd(buf, sizeof(buf), "%.8f", d); break;
+        case 7: g_ascii_formatd(buf, sizeof(buf), "%.7f", d); break;
+        case 6: g_ascii_formatd(buf, sizeof(buf), "%.6f", d); break;
+        case 5: g_ascii_formatd(buf, sizeof(buf), "%.5f", d); break;
+        case 4: g_ascii_formatd(buf, sizeof(buf), "%.4f", d); break;
+        case 3: g_ascii_formatd(buf, sizeof(buf), "%.3f", d); break;
+        case 2: g_ascii_formatd(buf, sizeof(buf), "%.2f", d); break;
+        case 1: g_ascii_formatd(buf, sizeof(buf), "%.1f", d); break;
+        case 0: g_ascii_formatd(buf, sizeof(buf), "%.0f", d); break;
+        case 10: default: g_ascii_formatd(buf, sizeof(buf), "%.10f", d); break;
     }
-    g_ascii_formatd(buf, sizeof(buf), "%.8f", d);
     os << strip_trailing_zeros(buf);
 }