2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QPDF_Real.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) :
|
|
|
|
val(val)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-27 03:34:15 +00:00
|
|
|
QPDF_Real::QPDF_Real(double value, int decimal_places) :
|
|
|
|
val(QUtil::double_to_string(value, decimal_places))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
QPDF_Real::~QPDF_Real()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDF_Real::unparse()
|
|
|
|
{
|
|
|
|
return this->val;
|
|
|
|
}
|
|
|
|
|
2018-12-17 22:40:29 +00:00
|
|
|
JSON
|
|
|
|
QPDF_Real::getJSON()
|
|
|
|
{
|
2019-03-11 20:21:27 +00:00
|
|
|
// While PDF allows .x or -.x, JSON does not. Rather than
|
2019-04-21 17:07:28 +00:00
|
|
|
// converting from string to double and back, just handle this as a
|
2019-03-11 20:21:27 +00:00
|
|
|
// special case for JSON.
|
|
|
|
std::string result;
|
|
|
|
if (this->val.length() == 0)
|
|
|
|
{
|
|
|
|
// Can't really happen...
|
|
|
|
result = "0";
|
|
|
|
}
|
|
|
|
else if (this->val.at(0) == '.')
|
|
|
|
{
|
|
|
|
result = "0" + this->val;
|
|
|
|
}
|
|
|
|
else if ((this->val.length() >= 2) &&
|
|
|
|
(this->val.at(0) == '-') &&
|
|
|
|
(this->val.at(1) == '.'))
|
|
|
|
{
|
|
|
|
result = "-0." + this->val.substr(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = this->val;
|
|
|
|
}
|
|
|
|
return JSON::makeNumber(result);
|
2018-12-17 22:40:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 14:57:07 +00:00
|
|
|
QPDFObject::object_type_e
|
|
|
|
QPDF_Real::getTypeCode() const
|
|
|
|
{
|
|
|
|
return QPDFObject::ot_real;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const*
|
|
|
|
QPDF_Real::getTypeName() const
|
|
|
|
{
|
|
|
|
return "real";
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string
|
|
|
|
QPDF_Real::getVal()
|
|
|
|
{
|
|
|
|
return this->val;
|
|
|
|
}
|