Code

Fixes calligraphy tool so drawing now uses the the correct opacity.
[inkscape.git] / src / svg / css-ostringstream.cpp
1 #include "svg/css-ostringstream.h"
2 #include "svg/strip-trailing-zeros.h"
3 #include <glib/gmessages.h>
4 #include <glib/gstrfuncs.h>
6 Inkscape::CSSOStringStream::CSSOStringStream()
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     ostr.precision(8);
17 }
19 static void
20 write_num(Inkscape::CSSOStringStream &os, unsigned const prec, double const d)
21 {
22     char buf[32];  // haven't thought about how much is really required.
23     if (prec != 8) {
24         static bool warned;
25         if (!warned) {
26             g_warning("Using precision of 8 instead of the requested %u.  Won't re-warn.", prec);
27             warned = true;
28         }
29     }
30     g_ascii_formatd(buf, sizeof(buf), "%.8f", d);
31     os << strip_trailing_zeros(buf);
32 }
34 Inkscape::CSSOStringStream &
35 operator<<(Inkscape::CSSOStringStream &os, float const d)
36 {
37     /* Try as integer first. */
38     {
39         long const n = long(d);
40         if (d == n) {
41             os << n;
42             return os;
43         }
44     }
46     write_num(os, os.precision(), d);
47     return os;
48 }
50 Inkscape::CSSOStringStream &
51 operator<<(Inkscape::CSSOStringStream &os, double const d)
52 {
53     /* Try as integer first. */
54     {
55         long const n = long(d);
56         if (d == n) {
57             os << n;
58             return os;
59         }
60     }
62     write_num(os, os.precision(), d);
63     return os;
64 }
67 /*
68   Local Variables:
69   mode:c++
70   c-file-style:"stroustrup"
71   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
72   indent-tabs-mode:nil
73   fill-column:99
74   End:
75 */
76 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :