diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /src/svg/stringstream.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-upstream.tar.xz inkscape-upstream.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/svg/stringstream.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/svg/stringstream.cpp b/src/svg/stringstream.cpp new file mode 100644 index 0000000..59f84a2 --- /dev/null +++ b/src/svg/stringstream.cpp @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * TODO: insert short description here + *//* + * Authors: see git history + * + * Copyright (C) 2018 Authors + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ +#include "svg/stringstream.h" +#include "svg/strip-trailing-zeros.h" +#include "preferences.h" +#include <2geom/point.h> + +Inkscape::SVGOStringStream::SVGOStringStream() +{ + /* These two are probably unnecessary now that we provide our own operator<< for float and + * double. */ + ostr.imbue(std::locale::classic()); + ostr.setf(std::ios::showpoint); + + /* 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. */ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + ostr.precision(prefs->getInt("/options/svgoutput/numericprecision", 8)); +} + +Inkscape::SVGOStringStream & +Inkscape::SVGOStringStream::operator<<(double d) +{ + auto &os = *this; + + /* Try as integer first. */ + { + int const n = int(d); + if (d == n) { + os << n; + return os; + } + } + + std::ostringstream s; + s.imbue(std::locale::classic()); + s.flags(os.setf(std::ios::showpoint)); + s.precision(os.precision()); + s << d; + os << strip_trailing_zeros(s.str()); + return os; +} + +Inkscape::SVGOStringStream & +Inkscape::SVGOStringStream::operator<<(Geom::Point const & p) +{ + auto &os = *this; + os << p[0] << ',' << p[1]; + return os; +} + +Inkscape::SVGIStringStream::SVGIStringStream():std::istringstream() +{ + this->imbue(std::locale::classic()); + this->setf(std::ios::showpoint); + + /* 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. */ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + this->precision(prefs->getInt("/options/svgoutput/numericprecision", 8)); +} + +Inkscape::SVGIStringStream::SVGIStringStream(const std::string& str):std::istringstream(str) +{ + this->imbue(std::locale::classic()); + this->setf(std::ios::showpoint); + + /* 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. */ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + this->precision(prefs->getInt("/options/svgoutput/numericprecision", 8)); +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |