Commit a3037ca440e2a7cf9b5d377c932f2d322f31dace
Committed by
GitHub
Merge pull request #739 from m-holger/getobject
Add QPDF::getObject to replace getObjectByObjGen and getObjectByID
Showing
6 changed files
with
34 additions
and
18 deletions
include/qpdf/QPDF.hh
| @@ -385,6 +385,10 @@ class QPDF | @@ -385,6 +385,10 @@ class QPDF | ||
| 385 | // Retrieve an object by object ID and generation. Returns an | 385 | // Retrieve an object by object ID and generation. Returns an |
| 386 | // indirect reference to it. | 386 | // indirect reference to it. |
| 387 | QPDF_DLL | 387 | QPDF_DLL |
| 388 | + QPDFObjectHandle getObject(QPDFObjGen const&); | ||
| 389 | + QPDF_DLL | ||
| 390 | + QPDFObjectHandle getObject(int objid, int generation); | ||
| 391 | + QPDF_DLL | ||
| 388 | QPDFObjectHandle getObjectByObjGen(QPDFObjGen const&); | 392 | QPDFObjectHandle getObjectByObjGen(QPDFObjGen const&); |
| 389 | QPDF_DLL | 393 | QPDF_DLL |
| 390 | QPDFObjectHandle getObjectByID(int objid, int generation); | 394 | QPDFObjectHandle getObjectByID(int objid, int generation); |
libqpdf/QPDF.cc
| @@ -2148,7 +2148,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og) | @@ -2148,7 +2148,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og) | ||
| 2148 | resolve(og); | 2148 | resolve(og); |
| 2149 | replaceObject(og, QPDFObjectHandle::Factory::makeReserved()); | 2149 | replaceObject(og, QPDFObjectHandle::Factory::makeReserved()); |
| 2150 | } | 2150 | } |
| 2151 | - return getObjectByObjGen(og); | 2151 | + return getObject(og); |
| 2152 | } | 2152 | } |
| 2153 | 2153 | ||
| 2154 | QPDFObjectHandle | 2154 | QPDFObjectHandle |
| @@ -2159,15 +2159,27 @@ QPDF::reserveStream(QPDFObjGen const& og) | @@ -2159,15 +2159,27 @@ QPDF::reserveStream(QPDFObjGen const& og) | ||
| 2159 | } | 2159 | } |
| 2160 | 2160 | ||
| 2161 | QPDFObjectHandle | 2161 | QPDFObjectHandle |
| 2162 | -QPDF::getObjectByObjGen(QPDFObjGen const& og) | 2162 | +QPDF::getObject(QPDFObjGen const& og) |
| 2163 | { | 2163 | { |
| 2164 | return QPDFObjectHandle::Factory::newIndirect(this, og); | 2164 | return QPDFObjectHandle::Factory::newIndirect(this, og); |
| 2165 | } | 2165 | } |
| 2166 | 2166 | ||
| 2167 | QPDFObjectHandle | 2167 | QPDFObjectHandle |
| 2168 | +QPDF::getObject(int objid, int generation) | ||
| 2169 | +{ | ||
| 2170 | + return getObject(QPDFObjGen(objid, generation)); | ||
| 2171 | +} | ||
| 2172 | + | ||
| 2173 | +QPDFObjectHandle | ||
| 2174 | +QPDF::getObjectByObjGen(QPDFObjGen const& og) | ||
| 2175 | +{ | ||
| 2176 | + return getObject(og); | ||
| 2177 | +} | ||
| 2178 | + | ||
| 2179 | +QPDFObjectHandle | ||
| 2168 | QPDF::getObjectByID(int objid, int generation) | 2180 | QPDF::getObjectByID(int objid, int generation) |
| 2169 | { | 2181 | { |
| 2170 | - return getObjectByObjGen(QPDFObjGen(objid, generation)); | 2182 | + return getObject(QPDFObjGen(objid, generation)); |
| 2171 | } | 2183 | } |
| 2172 | 2184 | ||
| 2173 | void | 2185 | void |
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -183,7 +183,7 @@ QPDFAcroFormDocumentHelper::getFormFields() | @@ -183,7 +183,7 @@ QPDFAcroFormDocumentHelper::getFormFields() | ||
| 183 | analyze(); | 183 | analyze(); |
| 184 | std::vector<QPDFFormFieldObjectHelper> result; | 184 | std::vector<QPDFFormFieldObjectHelper> result; |
| 185 | for (auto const& iter: this->m->field_to_annotations) { | 185 | for (auto const& iter: this->m->field_to_annotations) { |
| 186 | - result.push_back(this->qpdf.getObjectByObjGen(iter.first)); | 186 | + result.push_back(this->qpdf.getObject(iter.first)); |
| 187 | } | 187 | } |
| 188 | return result; | 188 | return result; |
| 189 | } | 189 | } |
libqpdf/QPDFWriter.cc
| @@ -1897,7 +1897,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1897,7 +1897,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1897 | // pass 1. | 1897 | // pass 1. |
| 1898 | indicateProgress(true, false); | 1898 | indicateProgress(true, false); |
| 1899 | } | 1899 | } |
| 1900 | - QPDFObjectHandle obj_to_write = this->m->pdf.getObjectByObjGen(obj); | 1900 | + QPDFObjectHandle obj_to_write = this->m->pdf.getObject(obj); |
| 1901 | if (obj_to_write.isStream()) { | 1901 | if (obj_to_write.isStream()) { |
| 1902 | // This condition occurred in a fuzz input. Ideally we | 1902 | // This condition occurred in a fuzz input. Ideally we |
| 1903 | // should block it at at parse time, but it's not | 1903 | // should block it at at parse time, but it's not |
libqpdf/QPDF_json.cc
| @@ -394,7 +394,7 @@ QPDF::JSONReactor::replaceObject( | @@ -394,7 +394,7 @@ QPDF::JSONReactor::replaceObject( | ||
| 394 | auto og = to_replace.getObjGen(); | 394 | auto og = to_replace.getObjGen(); |
| 395 | this->reserved.erase(og); | 395 | this->reserved.erase(og); |
| 396 | this->pdf.replaceObject(og, replacement); | 396 | this->pdf.replaceObject(og, replacement); |
| 397 | - auto oh = pdf.getObjectByObjGen(og); | 397 | + auto oh = pdf.getObject(og); |
| 398 | setObjectDescription(oh, value); | 398 | setObjectDescription(oh, value); |
| 399 | } | 399 | } |
| 400 | 400 |
libqpdf/QPDF_linearization.cc
| @@ -706,7 +706,7 @@ QPDF::getUncompressedObject( | @@ -706,7 +706,7 @@ QPDF::getUncompressedObject( | ||
| 706 | return obj; | 706 | return obj; |
| 707 | } else { | 707 | } else { |
| 708 | int repl = (*(object_stream_data.find(obj.getObjectID()))).second; | 708 | int repl = (*(object_stream_data.find(obj.getObjectID()))).second; |
| 709 | - return getObjectByObjGen(QPDFObjGen(repl, 0)); | 709 | + return getObject(repl, 0); |
| 710 | } | 710 | } |
| 711 | } | 711 | } |
| 712 | 712 | ||
| @@ -1381,9 +1381,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1381,9 +1381,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1381 | stopOnError("found other than one root while" | 1381 | stopOnError("found other than one root while" |
| 1382 | " calculating linearization data"); | 1382 | " calculating linearization data"); |
| 1383 | } | 1383 | } |
| 1384 | - this->m->part4.push_back(getObjectByObjGen(*(lc_root.begin()))); | 1384 | + this->m->part4.push_back(getObject(*(lc_root.begin()))); |
| 1385 | for (auto const& og: lc_open_document) { | 1385 | for (auto const& og: lc_open_document) { |
| 1386 | - this->m->part4.push_back(getObjectByObjGen(og)); | 1386 | + this->m->part4.push_back(getObject(og)); |
| 1387 | } | 1387 | } |
| 1388 | 1388 | ||
| 1389 | // Part 6: first page objects. Note: implementation note 124 | 1389 | // Part 6: first page objects. Note: implementation note 124 |
| @@ -1412,11 +1412,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1412,11 +1412,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1412 | // hint tables. | 1412 | // hint tables. |
| 1413 | 1413 | ||
| 1414 | for (auto const& og: lc_first_page_private) { | 1414 | for (auto const& og: lc_first_page_private) { |
| 1415 | - this->m->part6.push_back(getObjectByObjGen(og)); | 1415 | + this->m->part6.push_back(getObject(og)); |
| 1416 | } | 1416 | } |
| 1417 | 1417 | ||
| 1418 | for (auto const& og: lc_first_page_shared) { | 1418 | for (auto const& og: lc_first_page_shared) { |
| 1419 | - this->m->part6.push_back(getObjectByObjGen(og)); | 1419 | + this->m->part6.push_back(getObject(og)); |
| 1420 | } | 1420 | } |
| 1421 | 1421 | ||
| 1422 | // Place the outline dictionary if it goes in the first page section. | 1422 | // Place the outline dictionary if it goes in the first page section. |
| @@ -1462,7 +1462,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1462,7 +1462,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1462 | for (auto const& og: this->m->obj_user_to_objects[ou]) { | 1462 | for (auto const& og: this->m->obj_user_to_objects[ou]) { |
| 1463 | if (lc_other_page_private.count(og)) { | 1463 | if (lc_other_page_private.count(og)) { |
| 1464 | lc_other_page_private.erase(og); | 1464 | lc_other_page_private.erase(og); |
| 1465 | - this->m->part7.push_back(getObjectByObjGen(og)); | 1465 | + this->m->part7.push_back(getObject(og)); |
| 1466 | ++this->m->c_page_offset_data.entries.at(i).nobjects; | 1466 | ++this->m->c_page_offset_data.entries.at(i).nobjects; |
| 1467 | } | 1467 | } |
| 1468 | } | 1468 | } |
| @@ -1479,7 +1479,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1479,7 +1479,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1479 | 1479 | ||
| 1480 | // Order is unimportant. | 1480 | // Order is unimportant. |
| 1481 | for (auto const& og: lc_other_page_shared) { | 1481 | for (auto const& og: lc_other_page_shared) { |
| 1482 | - this->m->part8.push_back(getObjectByObjGen(og)); | 1482 | + this->m->part8.push_back(getObject(og)); |
| 1483 | } | 1483 | } |
| 1484 | 1484 | ||
| 1485 | // Part 9: other objects | 1485 | // Part 9: other objects |
| @@ -1501,7 +1501,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1501,7 +1501,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1501 | for (auto const& og: pages_ogs) { | 1501 | for (auto const& og: pages_ogs) { |
| 1502 | if (lc_other.count(og)) { | 1502 | if (lc_other.count(og)) { |
| 1503 | lc_other.erase(og); | 1503 | lc_other.erase(og); |
| 1504 | - this->m->part9.push_back(getObjectByObjGen(og)); | 1504 | + this->m->part9.push_back(getObject(og)); |
| 1505 | } | 1505 | } |
| 1506 | } | 1506 | } |
| 1507 | 1507 | ||
| @@ -1531,7 +1531,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1531,7 +1531,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1531 | for (auto const& og: ogs) { | 1531 | for (auto const& og: ogs) { |
| 1532 | if (lc_thumbnail_private.count(og)) { | 1532 | if (lc_thumbnail_private.count(og)) { |
| 1533 | lc_thumbnail_private.erase(og); | 1533 | lc_thumbnail_private.erase(og); |
| 1534 | - this->m->part9.push_back(getObjectByObjGen(og)); | 1534 | + this->m->part9.push_back(getObject(og)); |
| 1535 | } | 1535 | } |
| 1536 | } | 1536 | } |
| 1537 | } | 1537 | } |
| @@ -1544,7 +1544,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1544,7 +1544,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1544 | 1544 | ||
| 1545 | // Place shared thumbnail objects | 1545 | // Place shared thumbnail objects |
| 1546 | for (auto const& og: lc_thumbnail_shared) { | 1546 | for (auto const& og: lc_thumbnail_shared) { |
| 1547 | - this->m->part9.push_back(getObjectByObjGen(og)); | 1547 | + this->m->part9.push_back(getObject(og)); |
| 1548 | } | 1548 | } |
| 1549 | 1549 | ||
| 1550 | // Place outlines unless in first page | 1550 | // Place outlines unless in first page |
| @@ -1554,7 +1554,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1554,7 +1554,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1554 | 1554 | ||
| 1555 | // Place all remaining objects | 1555 | // Place all remaining objects |
| 1556 | for (auto const& og: lc_other) { | 1556 | for (auto const& og: lc_other) { |
| 1557 | - this->m->part9.push_back(getObjectByObjGen(og)); | 1557 | + this->m->part9.push_back(getObject(og)); |
| 1558 | } | 1558 | } |
| 1559 | 1559 | ||
| 1560 | // Make sure we got everything exactly once. | 1560 | // Make sure we got everything exactly once. |
| @@ -1656,7 +1656,7 @@ QPDF::pushOutlinesToPart( | @@ -1656,7 +1656,7 @@ QPDF::pushOutlinesToPart( | ||
| 1656 | lc_outlines.erase(outlines_og); | 1656 | lc_outlines.erase(outlines_og); |
| 1657 | part.push_back(outlines); | 1657 | part.push_back(outlines); |
| 1658 | for (auto const& og: lc_outlines) { | 1658 | for (auto const& og: lc_outlines) { |
| 1659 | - part.push_back(getObjectByObjGen(og)); | 1659 | + part.push_back(getObject(og)); |
| 1660 | ++this->m->c_outline_data.nobjects; | 1660 | ++this->m->c_outline_data.nobjects; |
| 1661 | } | 1661 | } |
| 1662 | } | 1662 | } |