Add new method ObjTable::getObject

This commit is contained in:
m-holger 2024-01-12 16:03:49 +00:00
parent c7f33b6b76
commit ffc82f6bfd
3 changed files with 36 additions and 18 deletions

View File

@ -583,7 +583,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
if (entry.getType() != 1) {
continue;
}
auto oh = getObjectByObjGen(iter.first);
QPDFObjectHandle oh = m->obj_cache.getObject(iter.first);
try {
if (!oh.isStreamOfType("/XRef")) {
continue;
@ -1909,7 +1909,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
if (m->xref_table.count(og) == 0) {
return m->obj_cache.insert({og, QPDF_Reserved::create()})->second.object;
} else {
return getObject(og);
return m->obj_cache.getObject(og);
}
}
@ -1923,25 +1923,25 @@ QPDFObjectHandle
QPDF::getObject(QPDFObjGen const& og)
{
// This method is called by the parser and therefore must not resolve any objects.
return m->obj_cache.insert({og, {QPDF_Unresolved::create(this, og)}})->second.object;
return {m->obj_cache.getObject(og.getObj(), og.getGen())};
}
QPDFObjectHandle
QPDF::getObject(int objid, int generation)
{
return getObject(QPDFObjGen(objid, generation));
return {m->obj_cache.getObject(objid, generation)};
}
QPDFObjectHandle
QPDF::getObjectByObjGen(QPDFObjGen const& og)
{
return getObject(og);
return {m->obj_cache.getObject(og.getObj(), og.getGen())};
}
QPDFObjectHandle
QPDF::getObjectByID(int objid, int generation)
{
return getObject(QPDFObjGen(objid, generation));
return {m->obj_cache.getObject(objid, generation)};
}
void

View File

@ -582,7 +582,7 @@ QPDF::getUncompressedObject(QPDFObjectHandle& obj, std::map<int, int> const& obj
return obj;
} else {
int repl = (*(object_stream_data.find(obj.getObjectID()))).second;
return getObject(repl, 0);
return m->obj_cache.getObject(repl, 0);
}
}
@ -1178,9 +1178,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
stopOnError("found other than one root while"
" calculating linearization data");
}
m->part4.push_back(getObject(*(lc_root.begin())));
m->part4.push_back(m->obj_cache.getObject(*(lc_root.begin())));
for (auto const& og: lc_open_document) {
m->part4.push_back(getObject(og));
m->part4.push_back(m->obj_cache.getObject(og));
}
// Part 6: first page objects. Note: implementation note 124 states that Acrobat always treats
@ -1205,11 +1205,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// of hint tables.
for (auto const& og: lc_first_page_private) {
m->part6.push_back(getObject(og));
m->part6.push_back(m->obj_cache.getObject(og));
}
for (auto const& og: lc_first_page_shared) {
m->part6.push_back(getObject(og));
m->part6.push_back(m->obj_cache.getObject(og));
}
// Place the outline dictionary if it goes in the first page section.
@ -1252,7 +1252,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto const& og: m->obj_user_to_objects[ou]) {
if (lc_other_page_private.count(og)) {
lc_other_page_private.erase(og);
m->part7.push_back(getObject(og));
m->part7.push_back(m->obj_cache.getObject(og));
++m->c_page_offset_data.entries.at(i).nobjects;
}
}
@ -1268,7 +1268,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Order is unimportant.
for (auto const& og: lc_other_page_shared) {
m->part8.push_back(getObject(og));
m->part8.push_back(m->obj_cache.getObject(og));
}
// Part 9: other objects
@ -1288,7 +1288,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto const& og: pages_ogs) {
if (lc_other.count(og)) {
lc_other.erase(og);
m->part9.push_back(getObject(og));
m->part9.push_back(m->obj_cache.getObject(og));
}
}
@ -1313,7 +1313,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto const& og: ogs) {
if (lc_thumbnail_private.count(og)) {
lc_thumbnail_private.erase(og);
m->part9.push_back(getObject(og));
m->part9.push_back(m->obj_cache.getObject(og));
}
}
}
@ -1325,7 +1325,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Place shared thumbnail objects
for (auto const& og: lc_thumbnail_shared) {
m->part9.push_back(getObject(og));
m->part9.push_back(m->obj_cache.getObject(og));
}
// Place outlines unless in first page
@ -1335,7 +1335,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Place all remaining objects
for (auto const& og: lc_other) {
m->part9.push_back(getObject(og));
m->part9.push_back(m->obj_cache.getObject(og));
}
// Make sure we got everything exactly once.
@ -1428,7 +1428,7 @@ QPDF::pushOutlinesToPart(
lc_outlines.erase(outlines_og);
part.push_back(outlines);
for (auto const& og: lc_outlines) {
part.push_back(getObject(og));
part.push_back(m->obj_cache.getObject(og));
++m->c_outline_data.nobjects;
}
}

View File

@ -5,6 +5,7 @@
#include <qpdf/QPDFObject_private.hh>
#include <qpdf/QPDF_Null.hh>
#include <qpdf/QPDF_Unresolved.hh>
// The object table is a combination of the previous object cache and (, in future,) the xref_table
// (, as well as possibly other existing structures). It is a hybrid of a map and a vector indexed
@ -97,6 +98,23 @@ class QPDF::ObjTable
return entries.find(og);
}
std::shared_ptr<QPDFObject>
getObject(int id, int gen = 0)
{
// This method is called by the parser and therefore must not resolve any objects.
return getObject(QPDFObjGen(id, gen));
}
std::shared_ptr<QPDFObject>
getObject(QPDFObjGen og)
{
// This method is called by the parser and therefore must not resolve any objects.
if (auto it = entries.find(og); it != entries.end()) {
return it->second.object;
}
return entries.insert({og, {QPDF_Unresolved::create(&qpdf, og)}}).first->second.object;
}
iterator
insert(std::pair<QPDFObjGen const, Entry>&& pair)
{