Commit 61b022ec8e545c3e6c18ca0fd42002cd26884960
Committed by
GitHub
Merge pull request #1654 from m-holger/pa1312
Refactor QPDFJob::Input methods to pass QPDFJob reference
Showing
3 changed files
with
22 additions
and
23 deletions
libqpdf/QPDFJob.cc
| @@ -261,7 +261,7 @@ struct QPDFJob::PageNo | @@ -261,7 +261,7 @@ struct QPDFJob::PageNo | ||
| 261 | }; | 261 | }; |
| 262 | 262 | ||
| 263 | QPDFJob::QPDFJob() : | 263 | QPDFJob::QPDFJob() : |
| 264 | - m(std::make_shared<Members>(*this)) | 264 | + m(std::make_shared<Members>()) |
| 265 | { | 265 | { |
| 266 | } | 266 | } |
| 267 | 267 | ||
| @@ -2331,7 +2331,7 @@ added_page(QPDF& pdf, QPDFPageObjectHelper page) | @@ -2331,7 +2331,7 @@ added_page(QPDF& pdf, QPDFPageObjectHelper page) | ||
| 2331 | // Initialize all members that depend on the QPDF object. If both qpdf and qpdf_p are null do | 2331 | // Initialize all members that depend on the QPDF object. If both qpdf and qpdf_p are null do |
| 2332 | // nothing. | 2332 | // nothing. |
| 2333 | void | 2333 | void |
| 2334 | -QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) | 2334 | +QPDFJob::Input::initialize(QPDFJob& job, Inputs& in, QPDF* a_qpdf) |
| 2335 | { | 2335 | { |
| 2336 | qpdf = a_qpdf ? a_qpdf : qpdf_p.get(); | 2336 | qpdf = a_qpdf ? a_qpdf : qpdf_p.get(); |
| 2337 | if (qpdf) { | 2337 | if (qpdf) { |
| @@ -2340,8 +2340,8 @@ QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) | @@ -2340,8 +2340,8 @@ QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) | ||
| 2340 | n_pages = static_cast<int>(orig_pages.size()); | 2340 | n_pages = static_cast<int>(orig_pages.size()); |
| 2341 | copied_pages = std::vector<bool>(orig_pages.size(), false); | 2341 | copied_pages = std::vector<bool>(orig_pages.size(), false); |
| 2342 | 2342 | ||
| 2343 | - if (in.job.m->remove_unreferenced_page_resources != QPDFJob::re_no) { | ||
| 2344 | - remove_unreferenced = in.job.shouldRemoveUnreferencedResources(*qpdf); | 2343 | + if (job.m->remove_unreferenced_page_resources != QPDFJob::re_no) { |
| 2344 | + remove_unreferenced = job.shouldRemoveUnreferencedResources(*qpdf); | ||
| 2345 | } | 2345 | } |
| 2346 | if (doc.page_labels().hasPageLabels()) { | 2346 | if (doc.page_labels().hasPageLabels()) { |
| 2347 | in.any_page_labels = true; | 2347 | in.any_page_labels = true; |
| @@ -2372,7 +2372,7 @@ QPDFJob::Inputs::infile_name(std::string const& name) | @@ -2372,7 +2372,7 @@ QPDFJob::Inputs::infile_name(std::string const& name) | ||
| 2372 | } | 2372 | } |
| 2373 | 2373 | ||
| 2374 | void | 2374 | void |
| 2375 | -QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | 2375 | +QPDFJob::Inputs::process(QPDFJob& job, std::string const& filename, QPDFJob::Input& input) |
| 2376 | { | 2376 | { |
| 2377 | // Open the PDF file and store the QPDF object. Do not canonicalize the file name. Using two | 2377 | // Open the PDF file and store the QPDF object. Do not canonicalize the file name. Using two |
| 2378 | // different paths to refer to the same file is a documented workaround for duplicating a page. | 2378 | // different paths to refer to the same file is a documented workaround for duplicating a page. |
| @@ -2398,7 +2398,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | @@ -2398,7 +2398,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | ||
| 2398 | password.data(), | 2398 | password.data(), |
| 2399 | true); | 2399 | true); |
| 2400 | } | 2400 | } |
| 2401 | - input.initialize(*this); | 2401 | + input.initialize(job, *this); |
| 2402 | 2402 | ||
| 2403 | if (input.cfis) { | 2403 | if (input.cfis) { |
| 2404 | input.cfis->stayOpen(false); | 2404 | input.cfis->stayOpen(false); |
| @@ -2406,7 +2406,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | @@ -2406,7 +2406,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | ||
| 2406 | } | 2406 | } |
| 2407 | 2407 | ||
| 2408 | void | 2408 | void |
| 2409 | -QPDFJob::Inputs::process_all() | 2409 | +QPDFJob::Inputs::process_all(QPDFJob& job) |
| 2410 | { | 2410 | { |
| 2411 | if (!infile_name().empty()) { | 2411 | if (!infile_name().empty()) { |
| 2412 | files.erase(""); | 2412 | files.erase(""); |
| @@ -2425,7 +2425,7 @@ QPDFJob::Inputs::process_all() | @@ -2425,7 +2425,7 @@ QPDFJob::Inputs::process_all() | ||
| 2425 | 2425 | ||
| 2426 | for (auto& [filename, input]: files) { | 2426 | for (auto& [filename, input]: files) { |
| 2427 | if (!input.qpdf) { | 2427 | if (!input.qpdf) { |
| 2428 | - process(filename, input); | 2428 | + process(job, filename, input); |
| 2429 | } | 2429 | } |
| 2430 | 2430 | ||
| 2431 | for (auto& selection: selections) { | 2431 | for (auto& selection: selections) { |
| @@ -2519,10 +2519,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf) | @@ -2519,10 +2519,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf) | ||
| 2519 | return; | 2519 | return; |
| 2520 | } | 2520 | } |
| 2521 | auto& main_input = m->inputs.files[m->infile_name()]; | 2521 | auto& main_input = m->inputs.files[m->infile_name()]; |
| 2522 | - main_input.initialize(m->inputs, &pdf); | 2522 | + main_input.initialize(*this, m->inputs, &pdf); |
| 2523 | 2523 | ||
| 2524 | // Parse all section and translate them into lists of actual pages. | 2524 | // Parse all section and translate them into lists of actual pages. |
| 2525 | - m->inputs.process_all(); | 2525 | + m->inputs.process_all(*this); |
| 2526 | 2526 | ||
| 2527 | // Clear all pages out of the primary QPDF's pages tree but leave the objects in place in the | 2527 | // Clear all pages out of the primary QPDF's pages tree but leave the objects in place in the |
| 2528 | // file so they can be re-added without changing their object numbers. This enables other things | 2528 | // file so they can be re-added without changing their object numbers. This enables other things |
libqpdf/qpdf/QPDFJob_private.hh
| @@ -37,7 +37,7 @@ struct QPDFJob::Selection | @@ -37,7 +37,7 @@ struct QPDFJob::Selection | ||
| 37 | // filename. This is a documented work-around. | 37 | // filename. This is a documented work-around. |
| 38 | struct QPDFJob::Input | 38 | struct QPDFJob::Input |
| 39 | { | 39 | { |
| 40 | - void initialize(Inputs& in, QPDF* qpdf = nullptr); | 40 | + void initialize(QPDFJob& job, Inputs& in, QPDF* qpdf = nullptr); |
| 41 | 41 | ||
| 42 | std::string password; | 42 | std::string password; |
| 43 | std::unique_ptr<QPDF> qpdf_p; | 43 | std::unique_ptr<QPDF> qpdf_p; |
| @@ -56,12 +56,8 @@ struct QPDFJob::Inputs | @@ -56,12 +56,8 @@ struct QPDFJob::Inputs | ||
| 56 | // These default values are duplicated in help and docs. | 56 | // These default values are duplicated in help and docs. |
| 57 | static int constexpr DEFAULT_KEEP_FILES_OPEN_THRESHOLD = 200; | 57 | static int constexpr DEFAULT_KEEP_FILES_OPEN_THRESHOLD = 200; |
| 58 | 58 | ||
| 59 | - Inputs(QPDFJob& job) : | ||
| 60 | - job(job) | ||
| 61 | - { | ||
| 62 | - } | ||
| 63 | - void process(std::string const& filename, QPDFJob::Input& file_spec); | ||
| 64 | - void process_all(); | 59 | + void process(QPDFJob& job, std::string const& filename, QPDFJob::Input& file_spec); |
| 60 | + void process_all(QPDFJob& job); | ||
| 65 | 61 | ||
| 66 | // Destroy all owned QPDF objects. Return false if any of the QPDF objects recorded warnings. | 62 | // Destroy all owned QPDF objects. Return false if any of the QPDF objects recorded warnings. |
| 67 | bool clear(); | 63 | bool clear(); |
| @@ -90,9 +86,6 @@ struct QPDFJob::Inputs | @@ -90,9 +86,6 @@ struct QPDFJob::Inputs | ||
| 90 | std::vector<Selection> selections; | 86 | std::vector<Selection> selections; |
| 91 | 87 | ||
| 92 | bool any_page_labels{false}; | 88 | bool any_page_labels{false}; |
| 93 | - | ||
| 94 | - private: | ||
| 95 | - QPDFJob& job; | ||
| 96 | }; | 89 | }; |
| 97 | 90 | ||
| 98 | struct QPDFJob::RotationSpec | 91 | struct QPDFJob::RotationSpec |
| @@ -150,9 +143,8 @@ class QPDFJob::Members | @@ -150,9 +143,8 @@ class QPDFJob::Members | ||
| 150 | friend class QPDFJob; | 143 | friend class QPDFJob; |
| 151 | 144 | ||
| 152 | public: | 145 | public: |
| 153 | - Members(QPDFJob& job) : | ||
| 154 | - log(d_cfg.log()), | ||
| 155 | - inputs(job) | 146 | + Members() : |
| 147 | + log(d_cfg.log()) | ||
| 156 | { | 148 | { |
| 157 | } | 149 | } |
| 158 | Members(Members const&) = delete; | 150 | Members(Members const&) = delete; |
manual/release-notes.rst
| @@ -13,6 +13,13 @@ more detail. | @@ -13,6 +13,13 @@ more detail. | ||
| 13 | 13 | ||
| 14 | .. x.y.z: not yet released | 14 | .. x.y.z: not yet released |
| 15 | 15 | ||
| 16 | + | ||
| 17 | +12.3.1: not yet released | ||
| 18 | + - Bug fixes | ||
| 19 | + | ||
| 20 | + - Fix a bug causing ``QPDFJob::createQPDF`` to fail if called | ||
| 21 | + from pikepdf. | ||
| 22 | + | ||
| 16 | 12.3.0: January 10, 2026 | 23 | 12.3.0: January 10, 2026 |
| 17 | - Release changes | 24 | - Release changes |
| 18 | 25 |