mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
Add method to get count of objects in QPDF
This commit is contained in:
parent
c81836076f
commit
2a82f6e1e0
@ -1,5 +1,8 @@
|
||||
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
|
||||
merge more files at once than the operating system's open file
|
||||
limit. Fixes #154.
|
||||
|
@ -431,6 +431,12 @@ class QPDF
|
||||
QPDF_DLL
|
||||
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
|
||||
// table. Useful for discovering objects that are not otherwise
|
||||
// referenced.
|
||||
|
@ -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>
|
||||
QPDF::getAllObjects()
|
||||
{
|
||||
@ -1904,15 +1920,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
||||
QPDFObjectHandle
|
||||
QPDF::makeIndirectObject(QPDFObjectHandle oh)
|
||||
{
|
||||
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);
|
||||
int max_objid = std::max(o1.getObj(), o2.getObj());
|
||||
int max_objid = getObjectCount();
|
||||
QPDFObjGen next(max_objid + 1, 0);
|
||||
this->m->obj_cache[next] =
|
||||
ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
|
||||
|
Loading…
Reference in New Issue
Block a user