diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-11-02 23:12:39 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-11-03 14:43:17 +0100 |
commit | 33a47d5c3c4402d8d94b00ed9b3aa2c339203d2f (patch) | |
tree | 07d97e20673566493b4c237784d27a2aed588ec4 | |
parent | 42ca1f007ac18b2a1426093c02c6ff261b737eae (diff) | |
download | qpdf-33a47d5c3c4402d8d94b00ed9b3aa2c339203d2f.tar.zst |
Make QPDF::findPage public (fixes #516)
This was originally not public because I wanted to get rid fo the
pages cache, but I recently realized there were deep reasons not to do
that, and the author of pikepdf wanted this, so I decided to make it
public.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | include/qpdf/QPDF.hh | 11 | ||||
-rw-r--r-- | libqpdf/QPDF_pages.cc | 1 | ||||
-rw-r--r-- | qpdf/qpdf.testcov | 1 |
4 files changed, 15 insertions, 2 deletions
@@ -1,5 +1,9 @@ 2021-11-02 Jay Berkenbilt <ejb@ql.org> + * Add QPDF::findPage to the public API. This is primarily to help + improve the efficiency of code that wraps the qpdf library, such + as pikepdf. Fixes #516. + * zlib-flate: warn and exit with code 3 when there is corrupted input data even when decompression is possible. We do this in the zlib-flate CLI so that it can be more reliably used to test the diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 48b92137..941004cc 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -605,6 +605,15 @@ class QPDF QPDF_DLL std::vector<QPDFObjectHandle> const& getAllPages(); + // These methods, given a page object or its object/generation + // number, returns the 0-based index into the array returned by + // getAllPages() for that page. An exception is thrown if the page + // is not found. + QPDF_DLL + int findPage(QPDFObjGen const& og); + QPDF_DLL + int findPage(QPDFObjectHandle& page); + // This method synchronizes QPDF's cache of the page structure // with the actual /Pages tree. If you restrict changes to the // /Pages tree, including addition, removal, or replacement of @@ -990,8 +999,6 @@ class QPDF std::set<QPDFObjGen>& visited, std::set<QPDFObjGen>& seen); void insertPage(QPDFObjectHandle newpage, int pos); - int findPage(QPDFObjGen const& og); - int findPage(QPDFObjectHandle& page); void flattenPagesTree(); void insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_duplicate); diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc index 8b55e0ef..eeb13029 100644 --- a/libqpdf/QPDF_pages.cc +++ b/libqpdf/QPDF_pages.cc @@ -345,6 +345,7 @@ QPDF::findPage(QPDFObjGen const& og) this->m->pageobj_to_pages_pos.find(og); if (it == this->m->pageobj_to_pages_pos.end()) { + QTC::TC("qpdf", "QPDF_pages findPage not found"); setLastObjectDescription("page object", og.getObj(), og.getGen()); throw QPDFExc(qpdf_e_pages, this->m->file->getName(), this->m->last_object_description, 0, diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 331547cd..0cb56525 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -595,3 +595,4 @@ QPDF resolve duplicated page in insert 0 QPDFWriter preserve object streams 1 QPDFWriter exclude from object stream 0 check unclosed --pages 1 +QPDF_pages findPage not found 0 |