mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-23 07:08:30 +00:00
Change type of QPDFValue::object_description to std::shared_ptr<std::variant>
Also, name the type QPDFValue::Description.
This commit is contained in:
parent
d58ec90310
commit
32907fc14c
@ -2176,7 +2176,8 @@ QPDFObjectHandle::setObjectDescription(
|
|||||||
// This is called during parsing on newly created direct objects,
|
// This is called during parsing on newly created direct objects,
|
||||||
// so we can't call dereference() here.
|
// so we can't call dereference() here.
|
||||||
if (isInitialized() && obj.get()) {
|
if (isInitialized() && obj.get()) {
|
||||||
auto descr = std::make_shared<std::string>(object_description);
|
auto descr =
|
||||||
|
std::make_shared<QPDFValue::Description>(object_description);
|
||||||
obj->setDescription(owning_qpdf, descr);
|
obj->setDescription(owning_qpdf, descr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,28 @@ QPDFValue::do_create(QPDFValue* object)
|
|||||||
std::string
|
std::string
|
||||||
QPDFValue::getDescription()
|
QPDFValue::getDescription()
|
||||||
{
|
{
|
||||||
auto description = object_description ? *object_description : "";
|
if (object_description) {
|
||||||
if (auto pos = description.find("$OG"); pos != std::string::npos) {
|
switch (object_description->index()) {
|
||||||
description.replace(pos, 3, og.unparse(' '));
|
case 0:
|
||||||
}
|
{
|
||||||
if (auto pos = description.find("$PO"); pos != std::string::npos) {
|
auto description = std::get<0>(*object_description);
|
||||||
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));
|
if (auto pos = description.find("$OG");
|
||||||
|
pos != std::string::npos) {
|
||||||
|
description.replace(pos, 3, og.unparse(' '));
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return description;
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ QPDF_Stream::QPDF_Stream(
|
|||||||
throw std::logic_error("stream object instantiated with non-dictionary "
|
throw std::logic_error("stream object instantiated with non-dictionary "
|
||||||
"object for dictionary");
|
"object for dictionary");
|
||||||
}
|
}
|
||||||
auto descr = std::make_shared<std::string>(
|
auto descr = std::make_shared<QPDFValue::Description>(
|
||||||
qpdf->getFilename() + ", stream object " + og.unparse(' '));
|
qpdf->getFilename() + ", stream object " + og.unparse(' '));
|
||||||
setDescription(qpdf, descr, offset);
|
setDescription(qpdf, descr, offset);
|
||||||
}
|
}
|
||||||
@ -283,7 +283,9 @@ QPDF_Stream::getStreamJSON(
|
|||||||
|
|
||||||
void
|
void
|
||||||
QPDF_Stream::setDescription(
|
QPDF_Stream::setDescription(
|
||||||
QPDF* qpdf, std::shared_ptr<std::string>& description, qpdf_offset_t offset)
|
QPDF* qpdf,
|
||||||
|
std::shared_ptr<QPDFValue::Description>& description,
|
||||||
|
qpdf_offset_t offset)
|
||||||
{
|
{
|
||||||
this->QPDFValue::setDescription(qpdf, description, offset);
|
this->QPDFValue::setDescription(qpdf, description, offset);
|
||||||
setDictDescription();
|
setDictDescription();
|
||||||
|
@ -71,7 +71,7 @@ class QPDFObject
|
|||||||
void
|
void
|
||||||
setDescription(
|
setDescription(
|
||||||
QPDF* qpdf,
|
QPDF* qpdf,
|
||||||
std::shared_ptr<std::string>& description,
|
std::shared_ptr<QPDFValue::Description>& description,
|
||||||
qpdf_offset_t offset = -1)
|
qpdf_offset_t offset = -1)
|
||||||
{
|
{
|
||||||
return value->setDescription(qpdf, description, offset);
|
return value->setDescription(qpdf, description, offset);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define QPDFPARSER_HH
|
#define QPDFPARSER_HH
|
||||||
|
|
||||||
#include <qpdf/QPDFObjectHandle.hh>
|
#include <qpdf/QPDFObjectHandle.hh>
|
||||||
|
#include <qpdf/QPDFValue.hh>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,8 +22,8 @@ class QPDFParser
|
|||||||
tokenizer(tokenizer),
|
tokenizer(tokenizer),
|
||||||
decrypter(decrypter),
|
decrypter(decrypter),
|
||||||
context(context),
|
context(context),
|
||||||
description(std::make_shared<std::string>(
|
description(std::make_shared<QPDFValue::Description>(std::string(
|
||||||
input->getName() + ", " + object_description + " at offset $PO"))
|
input->getName() + ", " + object_description + " at offset $PO")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual ~QPDFParser() = default;
|
virtual ~QPDFParser() = default;
|
||||||
@ -49,7 +50,7 @@ class QPDFParser
|
|||||||
QPDFTokenizer& tokenizer;
|
QPDFTokenizer& tokenizer;
|
||||||
QPDFObjectHandle::StringDecrypter* decrypter;
|
QPDFObjectHandle::StringDecrypter* decrypter;
|
||||||
QPDF* context;
|
QPDF* context;
|
||||||
std::shared_ptr<std::string> description;
|
std::shared_ptr<QPDFValue::Description> description;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QPDFPARSER_HH
|
#endif // QPDFPARSER_HH
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <qpdf/Types.h>
|
#include <qpdf/Types.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
class QPDF;
|
class QPDF;
|
||||||
class QPDFObjectHandle;
|
class QPDFObjectHandle;
|
||||||
@ -23,10 +24,13 @@ class QPDFValue
|
|||||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false) = 0;
|
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false) = 0;
|
||||||
virtual std::string unparse() = 0;
|
virtual std::string unparse() = 0;
|
||||||
virtual JSON getJSON(int json_version) = 0;
|
virtual JSON getJSON(int json_version) = 0;
|
||||||
|
|
||||||
|
using Description = std::variant<std::string>;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
setDescription(
|
setDescription(
|
||||||
QPDF* qpdf_p,
|
QPDF* qpdf_p,
|
||||||
std::shared_ptr<std::string>& description,
|
std::shared_ptr<Description>& description,
|
||||||
qpdf_offset_t offset)
|
qpdf_offset_t offset)
|
||||||
{
|
{
|
||||||
qpdf = qpdf_p;
|
qpdf = qpdf_p;
|
||||||
@ -37,7 +41,7 @@ class QPDFValue
|
|||||||
setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og)
|
setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og)
|
||||||
{
|
{
|
||||||
static auto default_description{
|
static auto default_description{
|
||||||
std::make_shared<std::string>("object $OG")};
|
std::make_shared<Description>("object $OG")};
|
||||||
if (!object_description) {
|
if (!object_description) {
|
||||||
object_description = default_description;
|
object_description = default_description;
|
||||||
}
|
}
|
||||||
@ -49,7 +53,7 @@ class QPDFValue
|
|||||||
hasDescription()
|
hasDescription()
|
||||||
{
|
{
|
||||||
return qpdf != nullptr && object_description &&
|
return qpdf != nullptr && object_description &&
|
||||||
!object_description->empty();
|
!getDescription().empty();
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
setParsedOffset(qpdf_offset_t offset)
|
setParsedOffset(qpdf_offset_t offset)
|
||||||
@ -108,7 +112,7 @@ class QPDFValue
|
|||||||
private:
|
private:
|
||||||
QPDFValue(QPDFValue const&) = delete;
|
QPDFValue(QPDFValue const&) = delete;
|
||||||
QPDFValue& operator=(QPDFValue const&) = delete;
|
QPDFValue& operator=(QPDFValue const&) = delete;
|
||||||
std::shared_ptr<std::string> object_description;
|
std::shared_ptr<Description> object_description;
|
||||||
|
|
||||||
const qpdf_object_type_e type_code{::ot_uninitialized};
|
const qpdf_object_type_e type_code{::ot_uninitialized};
|
||||||
char const* type_name{"uninitialized"};
|
char const* type_name{"uninitialized"};
|
||||||
|
@ -27,7 +27,9 @@ class QPDF_Stream: public QPDFValue
|
|||||||
virtual std::string unparse();
|
virtual std::string unparse();
|
||||||
virtual JSON getJSON(int json_version);
|
virtual JSON getJSON(int json_version);
|
||||||
virtual void setDescription(
|
virtual void setDescription(
|
||||||
QPDF*, std::shared_ptr<std::string>& description, qpdf_offset_t offset);
|
QPDF*,
|
||||||
|
std::shared_ptr<QPDFValue::Description>& description,
|
||||||
|
qpdf_offset_t offset);
|
||||||
virtual void disconnect();
|
virtual void disconnect();
|
||||||
QPDFObjectHandle getDict() const;
|
QPDFObjectHandle getDict() const;
|
||||||
bool isDataModified() const;
|
bool isDataModified() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user