2022-08-02 20:35:04 +00:00
|
|
|
#ifndef QPDFVALUE_HH
|
|
|
|
#define QPDFVALUE_HH
|
|
|
|
|
|
|
|
#include <qpdf/Constants.h>
|
|
|
|
#include <qpdf/DLL.h>
|
|
|
|
#include <qpdf/JSON.hh>
|
2022-08-12 14:14:11 +00:00
|
|
|
#include <qpdf/QPDFObjGen.hh>
|
2022-08-02 20:35:04 +00:00
|
|
|
#include <qpdf/Types.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class QPDF;
|
|
|
|
class QPDFObjectHandle;
|
2022-09-08 15:29:23 +00:00
|
|
|
class QPDFObject;
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
class QPDFValue
|
|
|
|
{
|
2022-09-08 15:29:23 +00:00
|
|
|
friend class QPDFObject;
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~QPDFValue() = default;
|
|
|
|
|
2022-11-14 17:54:12 +00:00
|
|
|
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false) = 0;
|
2022-08-02 20:35:04 +00:00
|
|
|
virtual std::string unparse() = 0;
|
|
|
|
virtual JSON getJSON(int json_version) = 0;
|
|
|
|
virtual void
|
2022-12-15 09:56:46 +00:00
|
|
|
setDescription(
|
2022-12-16 14:53:47 +00:00
|
|
|
QPDF* qpdf_p,
|
|
|
|
std::shared_ptr<std::string>& description,
|
|
|
|
qpdf_offset_t offset)
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
2022-09-07 18:11:24 +00:00
|
|
|
qpdf = qpdf_p;
|
2022-08-02 20:35:04 +00:00
|
|
|
object_description = description;
|
2022-12-15 09:56:46 +00:00
|
|
|
setParsedOffset(offset);
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
2022-12-16 16:19:15 +00:00
|
|
|
void
|
|
|
|
setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og)
|
|
|
|
{
|
2022-12-16 17:48:34 +00:00
|
|
|
static auto default_description{
|
|
|
|
std::make_shared<std::string>("object $OG")};
|
2022-12-16 14:53:47 +00:00
|
|
|
if (!object_description) {
|
2022-12-16 17:48:34 +00:00
|
|
|
object_description = default_description;
|
2022-12-16 16:19:15 +00:00
|
|
|
}
|
|
|
|
qpdf = a_qpdf;
|
|
|
|
og = a_og;
|
|
|
|
}
|
2022-12-31 12:13:32 +00:00
|
|
|
std::string
|
|
|
|
getDescription()
|
2022-08-02 20:35:04 +00:00
|
|
|
{
|
2022-12-31 12:13:32 +00:00
|
|
|
auto description = object_description ? *object_description : "";
|
2022-12-16 17:48:34 +00:00
|
|
|
if (auto pos = description.find("$OG"); pos != std::string::npos) {
|
|
|
|
description.replace(pos, 3, og.unparse(' '));
|
|
|
|
}
|
2022-12-16 18:08:56 +00:00
|
|
|
if (auto pos = description.find("$PO"); pos != std::string::npos) {
|
|
|
|
qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2
|
|
|
|
: (type_code == ::ot_array) ? 1
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
description.replace(pos, 3, std::to_string(parsed_offset + shift));
|
|
|
|
}
|
2022-12-31 12:13:32 +00:00
|
|
|
return description;
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
bool
|
|
|
|
hasDescription()
|
|
|
|
{
|
2022-12-16 14:53:47 +00:00
|
|
|
return qpdf != nullptr && object_description &&
|
|
|
|
!object_description->empty();
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
setParsedOffset(qpdf_offset_t offset)
|
|
|
|
{
|
2022-08-10 12:16:06 +00:00
|
|
|
if (parsed_offset < 0) {
|
|
|
|
parsed_offset = offset;
|
|
|
|
}
|
2022-08-02 20:35:04 +00:00
|
|
|
}
|
|
|
|
qpdf_offset_t
|
|
|
|
getParsedOffset()
|
|
|
|
{
|
|
|
|
return parsed_offset;
|
|
|
|
}
|
2022-08-12 14:14:11 +00:00
|
|
|
QPDF*
|
|
|
|
getQPDF()
|
|
|
|
{
|
|
|
|
return qpdf;
|
|
|
|
}
|
|
|
|
QPDFObjGen
|
|
|
|
getObjGen()
|
|
|
|
{
|
|
|
|
return og;
|
|
|
|
}
|
2022-09-07 20:49:31 +00:00
|
|
|
virtual void
|
2022-09-08 15:06:15 +00:00
|
|
|
disconnect()
|
2022-09-07 20:49:31 +00:00
|
|
|
{
|
|
|
|
}
|
2022-12-21 13:14:05 +00:00
|
|
|
virtual std::string
|
|
|
|
getStringValue() const
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
protected:
|
2022-09-27 11:40:39 +00:00
|
|
|
QPDFValue() = default;
|
|
|
|
|
2022-08-02 21:57:33 +00:00
|
|
|
QPDFValue(qpdf_object_type_e type_code, char const* type_name) :
|
|
|
|
type_code(type_code),
|
|
|
|
type_name(type_name)
|
|
|
|
{
|
|
|
|
}
|
2022-08-12 14:14:11 +00:00
|
|
|
QPDFValue(
|
|
|
|
qpdf_object_type_e type_code,
|
|
|
|
char const* type_name,
|
|
|
|
QPDF* qpdf,
|
|
|
|
QPDFObjGen const& og) :
|
|
|
|
type_code(type_code),
|
|
|
|
type_name(type_name),
|
|
|
|
qpdf(qpdf),
|
|
|
|
og(og)
|
|
|
|
{
|
|
|
|
}
|
2022-09-03 23:58:53 +00:00
|
|
|
|
2022-09-08 15:29:23 +00:00
|
|
|
static std::shared_ptr<QPDFObject> do_create(QPDFValue*);
|
2022-08-02 20:35:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QPDFValue(QPDFValue const&) = delete;
|
|
|
|
QPDFValue& operator=(QPDFValue const&) = delete;
|
2022-12-16 14:53:47 +00:00
|
|
|
std::shared_ptr<std::string> object_description;
|
2022-09-27 11:40:39 +00:00
|
|
|
|
|
|
|
const qpdf_object_type_e type_code{::ot_uninitialized};
|
|
|
|
char const* type_name{"uninitialized"};
|
2022-08-12 14:14:11 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QPDF* qpdf{nullptr};
|
2022-09-27 11:40:39 +00:00
|
|
|
QPDFObjGen og{};
|
|
|
|
qpdf_offset_t parsed_offset{-1};
|
2022-08-02 20:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QPDFVALUE_HH
|