diff options
author | Jay Berkenbilt <ejb@ql.org> | 2011-08-10 18:42:48 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2011-08-10 18:42:48 +0200 |
commit | 7dc197ef88a3f19a830f38d19aba649175d53c5e (patch) | |
tree | a143dac62c1779d855120a6e616c84fc08e586be /libqpdf/QPDF.cc | |
parent | b1a5b7e5d4c05a505c009668efa4472b6d4953d5 (diff) | |
download | qpdf-7dc197ef88a3f19a830f38d19aba649175d53c5e.tar.zst |
implement replace and swap
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r-- | libqpdf/QPDF.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index c9eee703..9bdbbdb6 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1888,6 +1888,39 @@ QPDF::getObjectByID(int objid, int generation) } void +QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh) +{ + if (oh.isIndirect()) + { + QTC::TC("qpdf", "QPDF replaceObject called with indirect object"); + throw std::logic_error( + "QPDF::replaceObject called with indirect object handle"); + } + + // Force new object to appear in the cache + resolve(objid, generation); + + // Replace the object in the object cache + ObjGen og(objid, generation); + this->obj_cache[og] = + ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); +} + +void +QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2) +{ + // Force objects to be loaded into cache; then swap them in the + // cache. + resolve(objid1, generation1); + resolve(objid2, generation2); + ObjGen og1(objid1, generation1); + ObjGen og2(objid2, generation2); + ObjCache t = this->obj_cache[og1]; + this->obj_cache[og1] = this->obj_cache[og2]; + this->obj_cache[og2] = t; +} + +void QPDF::trimTrailerForWrite() { // Note that removing the encryption dictionary does not interfere |