From 52f9d326a56e6409a1487c724241f91de33e3ba6 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 28 Jan 2019 20:13:10 -0500 Subject: Resolve duplicated page objects (fixes #268) When linearizing a file or getting the list of all pages in a file, detect if the pages tree contains a duplicated page object and, if so, shallow copy it. This makes it possible to have a one to one mapping of page positions to page objects. --- include/qpdf/QPDF.hh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index ef0f0eb7..cfb10aac 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -527,15 +527,16 @@ class QPDF void optimize(std::map const& object_stream_data, bool allow_changes = true); - // Traverse page tree return all /Page objects. For efficiency, - // this method returns a const reference to an internal vector of - // pages. Calls to addPage, addPageAt, and removePage safely - // update this, but directly manipulation of the pages three or - // pushing inheritable objects to the page level may invalidate - // it. See comments for updateAllPagesCache() for additional - // notes. Newer code should use - // QPDFPageDocumentHelper::getAllPages instead. The decision to - // expose this internal cache was arguably incorrect, but it is + // Traverse page tree return all /Page objects. It also detects + // and resolves cases in which the same /Page object is + // duplicated. For efficiency, this method returns a const + // reference to an internal vector of pages. Calls to addPage, + // addPageAt, and removePage safely update this, but directly + // manipulation of the pages three or pushing inheritable objects + // to the page level may invalidate it. See comments for + // updateAllPagesCache() for additional notes. Newer code should + // use QPDFPageDocumentHelper::getAllPages instead. The decision + // to expose this internal cache was arguably incorrect, but it is // being left here for compatibility. It is, however, completely // safe to use this for files that you are not modifying. QPDF_DLL @@ -895,6 +896,10 @@ class QPDF void getAllPagesInternal2(QPDFObjectHandle cur_pages, std::vector& result, std::set& visited); + void getAllPagesInternal3(QPDFObjectHandle cur_pages, + std::vector& result, + std::set& visited, + std::set& seen); void insertPage(QPDFObjectHandle newpage, int pos); int findPage(QPDFObjGen const& og); int findPage(QPDFObjectHandle& page); -- cgit v1.2.3-54-g00ecf