2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Add methods QPDFObject::setObjGen and QPDFObject::resetObjGen

Also, modify QPDFObject::swapWith to update the ObjGens of the swapped
objects.

Modify QPDF::newIndirect and QPDF::updateCache to keep object ObjGens
up to date.
This commit is contained in:
m-holger 2022-08-14 01:05:32 +01:00
parent 89061d5b33
commit 56e9bcabe9
2 changed files with 21 additions and 0 deletions

View File

@ -133,7 +133,25 @@ class QPDFObject
auto v = value; auto v = value;
value = o->value; value = o->value;
o->value = v; o->value = v;
auto og = value->og;
value->og = o->value->og;
o->value->og = og;
} }
// The following two methods are for use by class QPDF only
void
setObjGen(QPDF* qpdf, QPDFObjGen const& og)
{
value->qpdf = qpdf;
value->og = og;
}
void
resetObjGen()
{
value->qpdf = nullptr;
value->og = QPDFObjGen();
}
bool bool
isUnresolved() isUnresolved()
{ {

View File

@ -2109,6 +2109,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
QPDFObjectHandle QPDFObjectHandle
QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj) QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj)
{ {
obj->setObjGen(this, og);
if (!obj->hasDescription()) { if (!obj->hasDescription()) {
obj->setDescription(this, "object " + og.unparse(' ')); obj->setDescription(this, "object " + og.unparse(' '));
} }
@ -2122,8 +2123,10 @@ QPDF::updateCache(
qpdf_offset_t end_before_space, qpdf_offset_t end_before_space,
qpdf_offset_t end_after_space) qpdf_offset_t end_after_space)
{ {
object->setObjGen(this, og);
if (isCached(og)) { if (isCached(og)) {
auto& cache = m->obj_cache[og]; auto& cache = m->obj_cache[og];
cache.object->resetObjGen();
cache.object->assign(object); cache.object->assign(object);
cache.end_before_space = end_before_space; cache.end_before_space = end_before_space;
cache.end_after_space = end_after_space; cache.end_after_space = end_after_space;