2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Modify newIndirect to set QPDFObjectHandle::obj

This commit is contained in:
m-holger 2022-08-02 16:20:24 +01:00
parent 16841bec32
commit 2a2eebcaea
4 changed files with 39 additions and 19 deletions

View File

@ -1180,6 +1180,8 @@ class QPDF
void stopOnError(std::string const& message);
QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og);
QPDFObjectHandle reserveStream(QPDFObjGen const& og);
QPDFObjectHandle
newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
// Calls finish() on the pipeline when done but does not delete it
bool pipeStreamData(

View File

@ -1443,9 +1443,12 @@ class QPDFObjectHandle
private:
static QPDFObjectHandle
newIndirect(QPDF* qpdf, QPDFObjGen const& og)
newIndirect(
QPDF* qpdf,
QPDFObjGen const& og,
std::shared_ptr<QPDFObject> const& obj)
{
return QPDFObjectHandle::newIndirect(qpdf, og);
return QPDFObjectHandle(qpdf, og, obj);
}
static QPDFObjectHandle
newStream(
@ -1557,7 +1560,16 @@ class QPDFObjectHandle
bool isImage(bool exclude_imagemask = true);
private:
QPDFObjectHandle(QPDF*, QPDFObjGen const& og);
QPDFObjectHandle(
QPDF* qpdf,
QPDFObjGen const& og,
std::shared_ptr<QPDFObject> const& obj) :
initialized(true),
qpdf(qpdf),
og(og),
obj(obj)
{
}
QPDFObjectHandle(std::shared_ptr<QPDFObject> const&);
// Private object factory methods

View File

@ -1463,8 +1463,7 @@ QPDF::getAllObjects()
fixDanglingReferences(true);
std::vector<QPDFObjectHandle> result;
for (auto const& iter: this->m->obj_cache) {
QPDFObjGen const& og = iter.first;
result.push_back(getObjectByObjGen(og));
result.push_back(newIndirect(iter.first, iter.second.object));
}
return result;
}
@ -2128,6 +2127,15 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
}
}
QPDFObjectHandle
QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj)
{
if (!obj->hasDescription()) {
obj->setDescription(this, "object " + og.unparse(' '));
}
return QPDFObjectHandle::Factory::newIndirect(this, og, obj);
}
QPDFObjectHandle
QPDF::makeIndirectObject(QPDFObjectHandle oh)
{
@ -2137,9 +2145,9 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh)
"max object id is too high to create new objects");
}
QPDFObjGen next(max_objid + 1, 0);
this->m->obj_cache[next] =
m->obj_cache[next] =
ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
return QPDFObjectHandle::Factory::newIndirect(this, next);
return newIndirect(next, m->obj_cache[next].object);
}
QPDFObjectHandle
@ -2148,8 +2156,10 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
if ((!m->obj_cache.count(og)) && (!m->xref_table.count(og))) {
resolve(og);
m->obj_cache[og].object = QPDF_Reserved::create();
return newIndirect(og, m->obj_cache[og].object);
} else {
return getObject(og);
}
return getObject(og);
}
QPDFObjectHandle
@ -2162,7 +2172,8 @@ QPDF::reserveStream(QPDFObjGen const& og)
QPDFObjectHandle
QPDF::getObject(QPDFObjGen const& og)
{
return QPDFObjectHandle::Factory::newIndirect(this, og);
auto obj = (og.getObj() != 0) ? resolve(og) : QPDF_Null::create();
return newIndirect(og, obj);
}
QPDFObjectHandle

View File

@ -21,6 +21,7 @@
#include <qpdf/QPDF_Reserved.hh>
#include <qpdf/QPDF_Stream.hh>
#include <qpdf/QPDF_String.hh>
#include <qpdf/QPDF_Unresolved.hh>
#include <qpdf/SparseOHArray.hh>
#include <qpdf/QIntC.hh>
@ -240,13 +241,6 @@ QPDFObjectHandle::QPDFObjectHandle() :
{
}
QPDFObjectHandle::QPDFObjectHandle(QPDF* qpdf, QPDFObjGen const& og) :
initialized(true),
qpdf(qpdf),
og(og)
{
}
QPDFObjectHandle::QPDFObjectHandle(std::shared_ptr<QPDFObject> const& data) :
initialized(true),
qpdf(nullptr),
@ -1953,7 +1947,7 @@ QPDFObjectHandle::newIndirect(QPDF* qpdf, QPDFObjGen const& og)
return newNull();
}
return QPDFObjectHandle(qpdf, og);
return QPDFObjectHandle(qpdf, og, QPDF_Unresolved::create());
}
QPDFObjectHandle
@ -2553,10 +2547,11 @@ QPDFObjectHandle::dereference()
if (!this->initialized) {
return false;
}
if (this->obj() == nullptr ||
if ((this->obj->getTypeCode() == QPDFObject::ot_unresolved) ||
(getObjectID() &&
QPDF::Resolver::objectChanged(this->qpdf, getObjGen(), this->obj))) {
obj = QPDF::Resolver::resolve(this->qpdf, getObjGen());
this->obj = QPDF::Resolver::resolve(this->qpdf, getObjGen());
}
return true;
}