Commit 33a47d5c3c4402d8d94b00ed9b3aa2c339203d2f
1 parent
42ca1f00
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.
Showing
4 changed files
with
15 additions
and
2 deletions
ChangeLog
| 1 | 2021-11-02 Jay Berkenbilt <ejb@ql.org> | 1 | 2021-11-02 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * Add QPDF::findPage to the public API. This is primarily to help | ||
| 4 | + improve the efficiency of code that wraps the qpdf library, such | ||
| 5 | + as pikepdf. Fixes #516. | ||
| 6 | + | ||
| 3 | * zlib-flate: warn and exit with code 3 when there is corrupted | 7 | * zlib-flate: warn and exit with code 3 when there is corrupted |
| 4 | input data even when decompression is possible. We do this in the | 8 | input data even when decompression is possible. We do this in the |
| 5 | zlib-flate CLI so that it can be more reliably used to test the | 9 | zlib-flate CLI so that it can be more reliably used to test the |
include/qpdf/QPDF.hh
| @@ -605,6 +605,15 @@ class QPDF | @@ -605,6 +605,15 @@ class QPDF | ||
| 605 | QPDF_DLL | 605 | QPDF_DLL |
| 606 | std::vector<QPDFObjectHandle> const& getAllPages(); | 606 | std::vector<QPDFObjectHandle> const& getAllPages(); |
| 607 | 607 | ||
| 608 | + // These methods, given a page object or its object/generation | ||
| 609 | + // number, returns the 0-based index into the array returned by | ||
| 610 | + // getAllPages() for that page. An exception is thrown if the page | ||
| 611 | + // is not found. | ||
| 612 | + QPDF_DLL | ||
| 613 | + int findPage(QPDFObjGen const& og); | ||
| 614 | + QPDF_DLL | ||
| 615 | + int findPage(QPDFObjectHandle& page); | ||
| 616 | + | ||
| 608 | // This method synchronizes QPDF's cache of the page structure | 617 | // This method synchronizes QPDF's cache of the page structure |
| 609 | // with the actual /Pages tree. If you restrict changes to the | 618 | // with the actual /Pages tree. If you restrict changes to the |
| 610 | // /Pages tree, including addition, removal, or replacement of | 619 | // /Pages tree, including addition, removal, or replacement of |
| @@ -990,8 +999,6 @@ class QPDF | @@ -990,8 +999,6 @@ class QPDF | ||
| 990 | std::set<QPDFObjGen>& visited, | 999 | std::set<QPDFObjGen>& visited, |
| 991 | std::set<QPDFObjGen>& seen); | 1000 | std::set<QPDFObjGen>& seen); |
| 992 | void insertPage(QPDFObjectHandle newpage, int pos); | 1001 | void insertPage(QPDFObjectHandle newpage, int pos); |
| 993 | - int findPage(QPDFObjGen const& og); | ||
| 994 | - int findPage(QPDFObjectHandle& page); | ||
| 995 | void flattenPagesTree(); | 1002 | void flattenPagesTree(); |
| 996 | void insertPageobjToPage(QPDFObjectHandle const& obj, int pos, | 1003 | void insertPageobjToPage(QPDFObjectHandle const& obj, int pos, |
| 997 | bool check_duplicate); | 1004 | bool check_duplicate); |
libqpdf/QPDF_pages.cc
| @@ -345,6 +345,7 @@ QPDF::findPage(QPDFObjGen const& og) | @@ -345,6 +345,7 @@ QPDF::findPage(QPDFObjGen const& og) | ||
| 345 | this->m->pageobj_to_pages_pos.find(og); | 345 | this->m->pageobj_to_pages_pos.find(og); |
| 346 | if (it == this->m->pageobj_to_pages_pos.end()) | 346 | if (it == this->m->pageobj_to_pages_pos.end()) |
| 347 | { | 347 | { |
| 348 | + QTC::TC("qpdf", "QPDF_pages findPage not found"); | ||
| 348 | setLastObjectDescription("page object", og.getObj(), og.getGen()); | 349 | setLastObjectDescription("page object", og.getObj(), og.getGen()); |
| 349 | throw QPDFExc(qpdf_e_pages, this->m->file->getName(), | 350 | throw QPDFExc(qpdf_e_pages, this->m->file->getName(), |
| 350 | this->m->last_object_description, 0, | 351 | this->m->last_object_description, 0, |
qpdf/qpdf.testcov
| @@ -595,3 +595,4 @@ QPDF resolve duplicated page in insert 0 | @@ -595,3 +595,4 @@ QPDF resolve duplicated page in insert 0 | ||
| 595 | QPDFWriter preserve object streams 1 | 595 | QPDFWriter preserve object streams 1 |
| 596 | QPDFWriter exclude from object stream 0 | 596 | QPDFWriter exclude from object stream 0 |
| 597 | check unclosed --pages 1 | 597 | check unclosed --pages 1 |
| 598 | +QPDF_pages findPage not found 0 |