mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Change olist variable in QPDFParser::parse to vector<shared_ptr<QPDFObject>>
This commit is contained in:
parent
e91e642cf3
commit
9da50ca360
@ -1608,12 +1608,12 @@ class QPDFObjectHandle
|
|||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
bool isImage(bool exclude_imagemask = true);
|
bool isImage(bool exclude_imagemask = true);
|
||||||
|
|
||||||
private:
|
|
||||||
QPDFObjectHandle(std::shared_ptr<QPDFObject> const& obj) :
|
QPDFObjectHandle(std::shared_ptr<QPDFObject> const& obj) :
|
||||||
obj(obj)
|
obj(obj)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
QPDF_Array* asArray();
|
QPDF_Array* asArray();
|
||||||
QPDF_Bool* asBool();
|
QPDF_Bool* asBool();
|
||||||
QPDF_Dictionary* asDictionary();
|
QPDF_Dictionary* asDictionary();
|
||||||
|
@ -33,7 +33,7 @@ namespace
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QPDFObjectHandle> olist;
|
std::vector<std::shared_ptr<QPDFObject>> olist;
|
||||||
qpdf_offset_t offset;
|
qpdf_offset_t offset;
|
||||||
std::string contents_string;
|
std::string contents_string;
|
||||||
qpdf_offset_t contents_offset;
|
qpdf_offset_t contents_offset;
|
||||||
@ -67,7 +67,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
int good_count = 0;
|
int good_count = 0;
|
||||||
bool b_contents = false;
|
bool b_contents = false;
|
||||||
bool is_null = false;
|
bool is_null = false;
|
||||||
auto null_oh = QPDFObjectHandle::newNull();
|
auto null_oh = QPDF_Null::create();
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
bool bad = false;
|
bool bad = false;
|
||||||
@ -191,11 +191,13 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
if (content_stream) {
|
if (content_stream) {
|
||||||
object = QPDF_Operator::create(value);
|
object = QPDF_Operator::create(value);
|
||||||
} else if (
|
} else if (
|
||||||
(value == "R") && (state != st_top) && (size >= 2) &&
|
value == "R" && state != st_top && size >= 2 &&
|
||||||
(!olist.back().isIndirect()) &&
|
olist.back() &&
|
||||||
(olist.back().isInteger()) &&
|
olist.back()->getTypeCode() == ::ot_integer &&
|
||||||
(!olist.at(size - 2).isIndirect()) &&
|
!olist.back()->getObjGen().isIndirect() &&
|
||||||
(olist.at(size - 2).isInteger())) {
|
olist.at(size - 2) &&
|
||||||
|
olist.at(size - 2)->getTypeCode() == ::ot_integer &&
|
||||||
|
!olist.at(size - 2)->getObjGen().isIndirect()) {
|
||||||
if (context == nullptr) {
|
if (context == nullptr) {
|
||||||
QTC::TC("qpdf", "QPDFParser indirect without context");
|
QTC::TC("qpdf", "QPDFParser indirect without context");
|
||||||
throw std::logic_error(
|
throw std::logic_error(
|
||||||
@ -203,8 +205,8 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
" on an object with indirect references");
|
" on an object with indirect references");
|
||||||
}
|
}
|
||||||
auto ref_og = QPDFObjGen(
|
auto ref_og = QPDFObjGen(
|
||||||
olist.at(size - 2).getIntValueAsInt(),
|
QPDFObjectHandle(olist.at(size - 2)).getIntValueAsInt(),
|
||||||
olist.back().getIntValueAsInt());
|
QPDFObjectHandle(olist.back()).getIntValueAsInt());
|
||||||
if (ref_og.isIndirect()) {
|
if (ref_og.isIndirect()) {
|
||||||
// This action has the desirable side effect
|
// This action has the desirable side effect
|
||||||
// of causing dangling references (references
|
// of causing dangling references (references
|
||||||
@ -306,7 +308,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
setDescription(object, input->getLastOffset());
|
setDescription(object, input->getLastOffset());
|
||||||
}
|
}
|
||||||
set_offset = true;
|
set_offset = true;
|
||||||
olist.push_back(is_null ? null_oh : QPDFObjectHandle(object));
|
olist.push_back(is_null ? null_oh : object);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_top:
|
case st_top:
|
||||||
@ -325,7 +327,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
parser_state_e old_state = state_stack.back();
|
parser_state_e old_state = state_stack.back();
|
||||||
state_stack.pop_back();
|
state_stack.pop_back();
|
||||||
if (old_state == st_array) {
|
if (old_state == st_array) {
|
||||||
object = QPDF_Array::create(olist);
|
object = QPDF_Array::create(std::move(olist));
|
||||||
setDescription(object, offset - 1);
|
setDescription(object, offset - 1);
|
||||||
// The `offset` points to the next of "[". Set the rewind
|
// The `offset` points to the next of "[". Set the rewind
|
||||||
// offset to point to the beginning of "[". This has been
|
// offset to point to the beginning of "[". This has been
|
||||||
@ -412,8 +414,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
if (state_stack.back() == st_top) {
|
if (state_stack.back() == st_top) {
|
||||||
done = true;
|
done = true;
|
||||||
} else {
|
} else {
|
||||||
stack.back().olist.push_back(
|
stack.back().olist.push_back(is_null ? null_oh : object);
|
||||||
is_null ? null_oh : QPDFObjectHandle(object));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <qpdf/QPDF_Array.hh>
|
#include <qpdf/QPDF_Array.hh>
|
||||||
|
|
||||||
#include <qpdf/QIntC.hh>
|
#include <qpdf/QIntC.hh>
|
||||||
|
#include <qpdf/QPDFObject_private.hh>
|
||||||
#include <qpdf/QUtil.hh>
|
#include <qpdf/QUtil.hh>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@ -10,6 +11,12 @@ QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) :
|
|||||||
setFromVector(v);
|
setFromVector(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPDF_Array::QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& v) :
|
||||||
|
QPDFValue(::ot_array, "array")
|
||||||
|
{
|
||||||
|
setFromVector(std::move(v));
|
||||||
|
}
|
||||||
|
|
||||||
QPDF_Array::QPDF_Array(SparseOHArray const& items) :
|
QPDF_Array::QPDF_Array(SparseOHArray const& items) :
|
||||||
QPDFValue(::ot_array, "array"),
|
QPDFValue(::ot_array, "array"),
|
||||||
elements(items)
|
elements(items)
|
||||||
@ -22,6 +29,12 @@ QPDF_Array::create(std::vector<QPDFObjectHandle> const& items)
|
|||||||
return do_create(new QPDF_Array(items));
|
return do_create(new QPDF_Array(items));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<QPDFObject>
|
||||||
|
QPDF_Array::create(std::vector<std::shared_ptr<QPDFObject>>&& items)
|
||||||
|
{
|
||||||
|
return do_create(new QPDF_Array(std::move(items)));
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<QPDFObject>
|
std::shared_ptr<QPDFObject>
|
||||||
QPDF_Array::create(SparseOHArray const& items)
|
QPDF_Array::create(SparseOHArray const& items)
|
||||||
{
|
{
|
||||||
@ -106,6 +119,15 @@ QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDF_Array::setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& v)
|
||||||
|
{
|
||||||
|
this->elements = SparseOHArray();
|
||||||
|
for (auto&& iter: v) {
|
||||||
|
this->elements.append(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
|
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include <qpdf/SparseOHArray.hh>
|
#include <qpdf/SparseOHArray.hh>
|
||||||
|
|
||||||
|
#include <qpdf/QPDFObjectHandle.hh>
|
||||||
|
#include <qpdf/QPDFObject_private.hh>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
SparseOHArray::SparseOHArray() :
|
SparseOHArray::SparseOHArray() :
|
||||||
@ -22,6 +25,15 @@ SparseOHArray::append(QPDFObjectHandle oh)
|
|||||||
++this->n_elements;
|
++this->n_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SparseOHArray::append(std::shared_ptr<QPDFObject>&& obj)
|
||||||
|
{
|
||||||
|
if (obj->getTypeCode() != ::ot_null || !obj->getObjGen().isIndirect()) {
|
||||||
|
this->elements[this->n_elements] = std::move(obj);
|
||||||
|
}
|
||||||
|
++this->n_elements;
|
||||||
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
SparseOHArray::at(size_t idx) const
|
SparseOHArray::at(size_t idx) const
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,8 @@ class QPDF_Array: public QPDFValue
|
|||||||
virtual ~QPDF_Array() = default;
|
virtual ~QPDF_Array() = default;
|
||||||
static std::shared_ptr<QPDFObject>
|
static std::shared_ptr<QPDFObject>
|
||||||
create(std::vector<QPDFObjectHandle> const& items);
|
create(std::vector<QPDFObjectHandle> const& items);
|
||||||
|
static std::shared_ptr<QPDFObject>
|
||||||
|
create(std::vector<std::shared_ptr<QPDFObject>>&& items);
|
||||||
static std::shared_ptr<QPDFObject> create(SparseOHArray const& items);
|
static std::shared_ptr<QPDFObject> create(SparseOHArray const& items);
|
||||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
||||||
virtual std::string unparse();
|
virtual std::string unparse();
|
||||||
@ -25,6 +27,7 @@ class QPDF_Array: public QPDFValue
|
|||||||
|
|
||||||
void setItem(int, QPDFObjectHandle const&);
|
void setItem(int, QPDFObjectHandle const&);
|
||||||
void setFromVector(std::vector<QPDFObjectHandle> const& items);
|
void setFromVector(std::vector<QPDFObjectHandle> const& items);
|
||||||
|
void setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& items);
|
||||||
void insertItem(int at, QPDFObjectHandle const& item);
|
void insertItem(int at, QPDFObjectHandle const& item);
|
||||||
void appendItem(QPDFObjectHandle const& item);
|
void appendItem(QPDFObjectHandle const& item);
|
||||||
void eraseItem(int at);
|
void eraseItem(int at);
|
||||||
@ -36,6 +39,7 @@ class QPDF_Array: public QPDFValue
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QPDF_Array(std::vector<QPDFObjectHandle> const& items);
|
QPDF_Array(std::vector<QPDFObjectHandle> const& items);
|
||||||
|
QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& items);
|
||||||
QPDF_Array(SparseOHArray const& items);
|
QPDF_Array(SparseOHArray const& items);
|
||||||
SparseOHArray elements;
|
SparseOHArray elements;
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@ class SparseOHArray
|
|||||||
SparseOHArray();
|
SparseOHArray();
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
void append(QPDFObjectHandle oh);
|
void append(QPDFObjectHandle oh);
|
||||||
|
void append(std::shared_ptr<QPDFObject>&& obj);
|
||||||
QPDFObjectHandle at(size_t idx) const;
|
QPDFObjectHandle at(size_t idx) const;
|
||||||
void remove_last();
|
void remove_last();
|
||||||
void setAt(size_t idx, QPDFObjectHandle oh);
|
void setAt(size_t idx, QPDFObjectHandle oh);
|
||||||
|
Loading…
Reference in New Issue
Block a user