Commit 9064542b5f23bde3e7d6826b5b5e8b0a6f356434
1 parent
7fa5d177
Add private methods for reserving specific objects
Showing
4 changed files
with
26 additions
and
2 deletions
include/qpdf/QPDF.hh
| ... | ... | @@ -1079,6 +1079,7 @@ class QPDF |
| 1079 | 1079 | std::shared_ptr<QPDFObject> resolve(int objid, int generation); |
| 1080 | 1080 | void resolveObjectsInStream(int obj_stream_number); |
| 1081 | 1081 | void stopOnError(std::string const& message); |
| 1082 | + QPDFObjectHandle reserveObjectIfNotExists(int objid, int gen); | |
| 1082 | 1083 | |
| 1083 | 1084 | // Calls finish() on the pipeline when done but does not delete it |
| 1084 | 1085 | bool pipeStreamData( | ... | ... |
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -1444,6 +1444,12 @@ class QPDFObjectHandle |
| 1444 | 1444 | return QPDFObjectHandle::newStream( |
| 1445 | 1445 | qpdf, objid, generation, stream_dict, offset, length); |
| 1446 | 1446 | } |
| 1447 | + // Reserve an object with a specific ID | |
| 1448 | + static QPDFObjectHandle | |
| 1449 | + makeReserved() | |
| 1450 | + { | |
| 1451 | + return QPDFObjectHandle::makeReserved(); | |
| 1452 | + } | |
| 1447 | 1453 | }; |
| 1448 | 1454 | friend class Factory; |
| 1449 | 1455 | |
| ... | ... | @@ -1561,6 +1567,7 @@ class QPDFObjectHandle |
| 1561 | 1567 | QPDFObjectHandle stream_dict, |
| 1562 | 1568 | qpdf_offset_t offset, |
| 1563 | 1569 | size_t length); |
| 1570 | + static QPDFObjectHandle makeReserved(); | |
| 1564 | 1571 | |
| 1565 | 1572 | void typeWarning(char const* expected_type, std::string const& warning); |
| 1566 | 1573 | void objectWarning(std::string const& warning); | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -2156,6 +2156,17 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh) |
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | QPDFObjectHandle |
| 2159 | +QPDF::reserveObjectIfNotExists(int objid, int gen) | |
| 2160 | +{ | |
| 2161 | + QPDFObjGen og(objid, gen); | |
| 2162 | + if ((!this->m->obj_cache.count(og)) && (!this->m->xref_table.count(og))) { | |
| 2163 | + resolve(objid, gen); | |
| 2164 | + replaceObject(objid, gen, QPDFObjectHandle::Factory::makeReserved()); | |
| 2165 | + } | |
| 2166 | + return getObjectByID(objid, gen); | |
| 2167 | +} | |
| 2168 | + | |
| 2169 | +QPDFObjectHandle | |
| 2159 | 2170 | QPDF::getObjectByObjGen(QPDFObjGen const& og) |
| 2160 | 2171 | { |
| 2161 | 2172 | return getObjectByID(og.getObj(), og.getGen()); | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2775,14 +2775,19 @@ QPDFObjectHandle::newReserved(QPDF* qpdf) |
| 2775 | 2775 | { |
| 2776 | 2776 | // Reserve a spot for this object by assigning it an object |
| 2777 | 2777 | // number, but then return an unresolved handle to the object. |
| 2778 | - QPDFObjectHandle reserved = | |
| 2779 | - qpdf->makeIndirectObject(QPDFObjectHandle(new QPDF_Reserved())); | |
| 2778 | + QPDFObjectHandle reserved = qpdf->makeIndirectObject(makeReserved()); | |
| 2780 | 2779 | QPDFObjectHandle result = |
| 2781 | 2780 | newIndirect(qpdf, reserved.objid, reserved.generation); |
| 2782 | 2781 | result.reserved = true; |
| 2783 | 2782 | return result; |
| 2784 | 2783 | } |
| 2785 | 2784 | |
| 2785 | +QPDFObjectHandle | |
| 2786 | +QPDFObjectHandle::makeReserved() | |
| 2787 | +{ | |
| 2788 | + return QPDFObjectHandle(new QPDF_Reserved()); | |
| 2789 | +} | |
| 2790 | + | |
| 2786 | 2791 | void |
| 2787 | 2792 | QPDFObjectHandle::setObjectDescription( |
| 2788 | 2793 | QPDF* owning_qpdf, std::string const& object_description) | ... | ... |