2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-03 19:00:51 +00:00

Add method to get count of objects in QPDF

This commit is contained in:
Jay Berkenbilt 2018-06-22 14:52:03 -04:00
parent c81836076f
commit 2a82f6e1e0
3 changed files with 26 additions and 9 deletions

View File

@ -1,5 +1,8 @@
2018-06-22 Jay Berkenbilt <ejb@ql.org> 2018-06-22 Jay Berkenbilt <ejb@ql.org>
* Add new method QPDF::getObjectCount(). This gives an approximate
(upper bound) account of objects in the QPDF object.
* Don't leave files open when merging. This makes it possible * Don't leave files open when merging. This makes it possible
merge more files at once than the operating system's open file merge more files at once than the operating system's open file
limit. Fixes #154. limit. Fixes #154.

View File

@ -431,6 +431,12 @@ class QPDF
QPDF_DLL QPDF_DLL
void showXRefTable(); void showXRefTable();
// Return the approximate number of indirect objects. It is
// approximate because not all objects in the file are preserved
// in all cases.
QPDF_DLL
size_t getObjectCount();
// Returns a list of indirect objects for every object in the xref // Returns a list of indirect objects for every object in the xref
// table. Useful for discovering objects that are not otherwise // table. Useful for discovering objects that are not otherwise
// referenced. // referenced.

View File

@ -1218,6 +1218,22 @@ QPDF::showXRefTable()
} }
} }
size_t
QPDF::getObjectCount()
{
// This method returns the next available indirect object number.
// makeIndirectObject uses it for this purpose.
QPDFObjGen o1(0, 0);
if (! this->m->obj_cache.empty())
{
o1 = (*(this->m->obj_cache.rbegin())).first;
}
QPDFObjGen o2 = (*(this->m->xref_table.rbegin())).first;
QTC::TC("qpdf", "QPDF indirect last obj from xref",
(o2.getObj() > o1.getObj()) ? 1 : 0);
return std::max(o1.getObj(), o2.getObj());
}
std::vector<QPDFObjectHandle> std::vector<QPDFObjectHandle>
QPDF::getAllObjects() QPDF::getAllObjects()
{ {
@ -1904,15 +1920,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
QPDFObjectHandle QPDFObjectHandle
QPDF::makeIndirectObject(QPDFObjectHandle oh) QPDF::makeIndirectObject(QPDFObjectHandle oh)
{ {
QPDFObjGen o1(0, 0); int max_objid = getObjectCount();
if (! this->m->obj_cache.empty())
{
o1 = (*(this->m->obj_cache.rbegin())).first;
}
QPDFObjGen o2 = (*(this->m->xref_table.rbegin())).first;
QTC::TC("qpdf", "QPDF indirect last obj from xref",
(o2.getObj() > o1.getObj()) ? 1 : 0);
int max_objid = std::max(o1.getObj(), o2.getObj());
QPDFObjGen next(max_objid + 1, 0); QPDFObjGen next(max_objid + 1, 0);
this->m->obj_cache[next] = this->m->obj_cache[next] =
ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);