Code

Filters. Custom predefined filters update and new ABC filters.
[inkscape.git] / src / svg / stringstream.cpp
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 Inkscape::SVGIStringStream::SVGIStringStream():std::istringstream()
70 {
71     this->imbue(std::locale::classic());
72     this->setf(std::ios::showpoint);
74     /* This one is (currently) needed though, as we currently use ostr.precision as a sort of
75        variable for storing the desired precision: see our two precision methods and our operator<<
76        methods for float and double. */
77     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
78     this->precision(prefs->getInt("/options/svgoutput/numericprecision", 8));
79 }
81 Inkscape::SVGIStringStream::SVGIStringStream(const std::string& str):std::istringstream(str)
82 {
83     this->imbue(std::locale::classic());
84     this->setf(std::ios::showpoint);
86     /* This one is (currently) needed though, as we currently use ostr.precision as a sort of
87        variable for storing the desired precision: see our two precision methods and our operator<<
88        methods for float and double. */
89     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
90     this->precision(prefs->getInt("/options/svgoutput/numericprecision", 8));
91 }
94 /*
95   Local Variables:
96   mode:c++
97   c-file-style:"stroustrup"
98   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
99   indent-tabs-mode:nil
100   fill-column:99
101   End:
102 */
103 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :