2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-05 08:02:11 +00:00

Add private methods for reserving specific objects

This commit is contained in:
Jay Berkenbilt 2022-05-15 13:10:10 -04:00
parent 7fa5d1773b
commit 9064542b5f
4 changed files with 26 additions and 2 deletions

View File

@ -1079,6 +1079,7 @@ class QPDF
std::shared_ptr<QPDFObject> resolve(int objid, int generation); std::shared_ptr<QPDFObject> resolve(int objid, int generation);
void resolveObjectsInStream(int obj_stream_number); void resolveObjectsInStream(int obj_stream_number);
void stopOnError(std::string const& message); void stopOnError(std::string const& message);
QPDFObjectHandle reserveObjectIfNotExists(int objid, int gen);
// Calls finish() on the pipeline when done but does not delete it // Calls finish() on the pipeline when done but does not delete it
bool pipeStreamData( bool pipeStreamData(

View File

@ -1444,6 +1444,12 @@ class QPDFObjectHandle
return QPDFObjectHandle::newStream( return QPDFObjectHandle::newStream(
qpdf, objid, generation, stream_dict, offset, length); qpdf, objid, generation, stream_dict, offset, length);
} }
// Reserve an object with a specific ID
static QPDFObjectHandle
makeReserved()
{
return QPDFObjectHandle::makeReserved();
}
}; };
friend class Factory; friend class Factory;
@ -1561,6 +1567,7 @@ class QPDFObjectHandle
QPDFObjectHandle stream_dict, QPDFObjectHandle stream_dict,
qpdf_offset_t offset, qpdf_offset_t offset,
size_t length); size_t length);
static QPDFObjectHandle makeReserved();
void typeWarning(char const* expected_type, std::string const& warning); void typeWarning(char const* expected_type, std::string const& warning);
void objectWarning(std::string const& warning); void objectWarning(std::string const& warning);

View File

@ -2155,6 +2155,17 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh)
this, next.getObj(), next.getGen()); this, next.getObj(), next.getGen());
} }
QPDFObjectHandle
QPDF::reserveObjectIfNotExists(int objid, int gen)
{
QPDFObjGen og(objid, gen);
if ((!this->m->obj_cache.count(og)) && (!this->m->xref_table.count(og))) {
resolve(objid, gen);
replaceObject(objid, gen, QPDFObjectHandle::Factory::makeReserved());
}
return getObjectByID(objid, gen);
}
QPDFObjectHandle QPDFObjectHandle
QPDF::getObjectByObjGen(QPDFObjGen const& og) QPDF::getObjectByObjGen(QPDFObjGen const& og)
{ {

View File

@ -2775,14 +2775,19 @@ QPDFObjectHandle::newReserved(QPDF* qpdf)
{ {
// Reserve a spot for this object by assigning it an object // Reserve a spot for this object by assigning it an object
// number, but then return an unresolved handle to the object. // number, but then return an unresolved handle to the object.
QPDFObjectHandle reserved = QPDFObjectHandle reserved = qpdf->makeIndirectObject(makeReserved());
qpdf->makeIndirectObject(QPDFObjectHandle(new QPDF_Reserved()));
QPDFObjectHandle result = QPDFObjectHandle result =
newIndirect(qpdf, reserved.objid, reserved.generation); newIndirect(qpdf, reserved.objid, reserved.generation);
result.reserved = true; result.reserved = true;
return result; return result;
} }
QPDFObjectHandle
QPDFObjectHandle::makeReserved()
{
return QPDFObjectHandle(new QPDF_Reserved());
}
void void
QPDFObjectHandle::setObjectDescription( QPDFObjectHandle::setObjectDescription(
QPDF* owning_qpdf, std::string const& object_description) QPDF* owning_qpdf, std::string const& object_description)