~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/svg/stringstream.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "svg/stringstream.h"
 
2
#include "svg/strip-trailing-zeros.h"
 
3
#include "preferences.h"
 
4
#include <2geom/point.h>
 
5
 
 
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);
 
12
 
 
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
}
 
19
 
 
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
    }
 
31
 
 
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
}
 
40
 
 
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
    }
 
52
 
 
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
}
 
61
 
 
62
Inkscape::SVGOStringStream &
 
63
operator<<(Inkscape::SVGOStringStream &os, Geom::Point const & p)
 
64
{
 
65
    os << p[0] << ',' << p[1];
 
66
    return os;
 
67
}
 
68
 
 
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 :