Commit 56e9bcabe984acd4479ff7fef9a2a0ca669abc76
1 parent
89061d5b
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.
Showing
2 changed files
with
21 additions
and
0 deletions
include/qpdf/QPDFObject.hh
| @@ -133,7 +133,25 @@ class QPDFObject | @@ -133,7 +133,25 @@ class QPDFObject | ||
| 133 | auto v = value; | 133 | auto v = value; |
| 134 | value = o->value; | 134 | value = o->value; |
| 135 | o->value = v; | 135 | o->value = v; |
| 136 | + auto og = value->og; | ||
| 137 | + value->og = o->value->og; | ||
| 138 | + o->value->og = og; | ||
| 136 | } | 139 | } |
| 140 | + | ||
| 141 | + // The following two methods are for use by class QPDF only | ||
| 142 | + void | ||
| 143 | + setObjGen(QPDF* qpdf, QPDFObjGen const& og) | ||
| 144 | + { | ||
| 145 | + value->qpdf = qpdf; | ||
| 146 | + value->og = og; | ||
| 147 | + } | ||
| 148 | + void | ||
| 149 | + resetObjGen() | ||
| 150 | + { | ||
| 151 | + value->qpdf = nullptr; | ||
| 152 | + value->og = QPDFObjGen(); | ||
| 153 | + } | ||
| 154 | + | ||
| 137 | bool | 155 | bool |
| 138 | isUnresolved() | 156 | isUnresolved() |
| 139 | { | 157 | { |
libqpdf/QPDF.cc
| @@ -2109,6 +2109,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -2109,6 +2109,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 2109 | QPDFObjectHandle | 2109 | QPDFObjectHandle |
| 2110 | QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj) | 2110 | QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj) |
| 2111 | { | 2111 | { |
| 2112 | + obj->setObjGen(this, og); | ||
| 2112 | if (!obj->hasDescription()) { | 2113 | if (!obj->hasDescription()) { |
| 2113 | obj->setDescription(this, "object " + og.unparse(' ')); | 2114 | obj->setDescription(this, "object " + og.unparse(' ')); |
| 2114 | } | 2115 | } |
| @@ -2122,8 +2123,10 @@ QPDF::updateCache( | @@ -2122,8 +2123,10 @@ QPDF::updateCache( | ||
| 2122 | qpdf_offset_t end_before_space, | 2123 | qpdf_offset_t end_before_space, |
| 2123 | qpdf_offset_t end_after_space) | 2124 | qpdf_offset_t end_after_space) |
| 2124 | { | 2125 | { |
| 2126 | + object->setObjGen(this, og); | ||
| 2125 | if (isCached(og)) { | 2127 | if (isCached(og)) { |
| 2126 | auto& cache = m->obj_cache[og]; | 2128 | auto& cache = m->obj_cache[og]; |
| 2129 | + cache.object->resetObjGen(); | ||
| 2127 | cache.object->assign(object); | 2130 | cache.object->assign(object); |
| 2128 | cache.end_before_space = end_before_space; | 2131 | cache.end_before_space = end_before_space; |
| 2129 | cache.end_after_space = end_after_space; | 2132 | cache.end_after_space = end_after_space; |