1 #include "svg/stringstream.h"
2 #include "svg/strip-trailing-zeros.h"
3 #include "preferences.h"
4 #include <2geom/point.h>
6 Inkscape::SVGOStringStream::SVGOStringStream()
7 {
8 /* These two are probably unnecessary now that we provide our own operator<< for float and
9 * double. */
10 ostr.imbue(std::locale::classic());
11 ostr.setf(std::ios::showpoint);
13 /* This one is (currently) needed though, as we currently use ostr.precision as a sort of
14 variable for storing the desired precision: see our two precision methods and our operator<<
15 methods for float and double. */
16 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
17 ostr.precision(prefs->getInt("/options/svgoutput/numericprecision", 8));
18 }
20 Inkscape::SVGOStringStream &
21 operator<<(Inkscape::SVGOStringStream &os, float d)
22 {
23 /* Try as integer first. */
24 {
25 int const n = int(d);
26 if (d == n) {
27 os << n;
28 return os;
29 }
30 }
32 std::ostringstream s;
33 s.imbue(std::locale::classic());
34 s.flags(os.setf(std::ios::showpoint));
35 s.precision(os.precision());
36 s << d;
37 os << strip_trailing_zeros(s.str());
38 return os;
39 }
41 Inkscape::SVGOStringStream &
42 operator<<(Inkscape::SVGOStringStream &os, double d)
43 {
44 /* Try as integer first. */
45 {
46 int const n = int(d);
47 if (d == n) {
48 os << n;
49 return os;
50 }
51 }
53 std::ostringstream s;
54 s.imbue(std::locale::classic());
55 s.flags(os.setf(std::ios::showpoint));
56 s.precision(os.precision());
57 s << d;
58 os << strip_trailing_zeros(s.str());
59 return os;
60 }
62 Inkscape::SVGOStringStream &
63 operator<<(Inkscape::SVGOStringStream &os, Geom::Point const & p)
64 {
65 os << p[0] << ',' << p[1];
66 return os;
67 }
69 /*
70 Local Variables:
71 mode:c++
72 c-file-style:"stroustrup"
73 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74 indent-tabs-mode:nil
75 fill-column:99
76 End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :