2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QPDF_Real.hh>
|
|
|
|
|
2024-02-09 13:09:08 +00:00
|
|
|
#include <qpdf/JSON_writer.hh>
|
2012-06-27 03:34:15 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
QPDF_Real::QPDF_Real(std::string const& val) :
|
2022-08-02 21:57:33 +00:00
|
|
|
QPDFValue(::ot_real, "real"),
|
2008-04-29 12:55:25 +00:00
|
|
|
val(val)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-21 17:35:09 +00:00
|
|
|
QPDF_Real::QPDF_Real(double value, int decimal_places, bool trim_trailing_zeroes) :
|
2022-08-02 21:57:33 +00:00
|
|
|
QPDFValue(::ot_real, "real"),
|
2021-02-12 08:44:12 +00:00
|
|
|
val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes))
|
2012-06-27 03:34:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
std::shared_ptr<QPDFObject>
|
2022-06-16 16:45:04 +00:00
|
|
|
QPDF_Real::create(std::string const& val)
|
|
|
|
{
|
|
|
|
return do_create(new QPDF_Real(val));
|
|
|
|
}
|
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
std::shared_ptr<QPDFObject>
|
2022-06-16 16:45:04 +00:00
|
|
|
QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes)
|
|
|
|
{
|
2023-05-21 17:35:09 +00:00
|
|
|
return do_create(new QPDF_Real(value, decimal_places, trim_trailing_zeroes));
|
2022-06-16 16:45:04 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
std::shared_ptr<QPDFObject>
|
2022-11-14 17:54:12 +00:00
|
|
|
QPDF_Real::copy(bool shallow)
|
2022-06-16 16:45:04 +00:00
|
|
|
{
|
|
|
|
return create(val);
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string
|
|
|
|
QPDF_Real::unparse()
|
|
|
|
{
|
|
|
|
return this->val;
|
|
|
|
}
|
|
|
|
|
2024-02-09 13:09:08 +00:00
|
|
|
void
|
|
|
|
QPDF_Real::writeJSON(int json_version, JSON::Writer& p)
|
|
|
|
{
|
|
|
|
if (this->val.length() == 0) {
|
|
|
|
// Can't really happen...
|
|
|
|
p << "0";
|
|
|
|
} else if (this->val.at(0) == '.') {
|
|
|
|
p << "0" << this->val;
|
|
|
|
} else if (this->val.length() >= 2 && this->val.at(0) == '-' && this->val.at(1) == '.') {
|
|
|
|
p << "-0." << this->val.substr(2);
|
|
|
|
} else {
|
|
|
|
p << this->val;
|
|
|
|
}
|
|
|
|
}
|