Commit 9f7207d3be4adce435a17a820de14b362af6437e
1 parent
7c8156f4
Refactor QPDFJob::Input methods to pass QPDFJob reference
By-pass an issue calling QPDFJob::createQPDF from pikepdf. See https://github.com/pdfarranger/pdfarranger/issues/1312
Showing
3 changed files
with
22 additions
and
23 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -261,7 +261,7 @@ struct QPDFJob::PageNo |
| 261 | 261 | }; |
| 262 | 262 | |
| 263 | 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 | 2331 | // Initialize all members that depend on the QPDF object. If both qpdf and qpdf_p are null do |
| 2332 | 2332 | // nothing. |
| 2333 | 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 | 2336 | qpdf = a_qpdf ? a_qpdf : qpdf_p.get(); |
| 2337 | 2337 | if (qpdf) { |
| ... | ... | @@ -2340,8 +2340,8 @@ QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) |
| 2340 | 2340 | n_pages = static_cast<int>(orig_pages.size()); |
| 2341 | 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 | 2346 | if (doc.page_labels().hasPageLabels()) { |
| 2347 | 2347 | in.any_page_labels = true; |
| ... | ... | @@ -2372,7 +2372,7 @@ QPDFJob::Inputs::infile_name(std::string const& name) |
| 2372 | 2372 | } |
| 2373 | 2373 | |
| 2374 | 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 | 2377 | // Open the PDF file and store the QPDF object. Do not canonicalize the file name. Using two |
| 2378 | 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 | 2398 | password.data(), |
| 2399 | 2399 | true); |
| 2400 | 2400 | } |
| 2401 | - input.initialize(*this); | |
| 2401 | + input.initialize(job, *this); | |
| 2402 | 2402 | |
| 2403 | 2403 | if (input.cfis) { |
| 2404 | 2404 | input.cfis->stayOpen(false); |
| ... | ... | @@ -2406,7 +2406,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) |
| 2406 | 2406 | } |
| 2407 | 2407 | |
| 2408 | 2408 | void |
| 2409 | -QPDFJob::Inputs::process_all() | |
| 2409 | +QPDFJob::Inputs::process_all(QPDFJob& job) | |
| 2410 | 2410 | { |
| 2411 | 2411 | if (!infile_name().empty()) { |
| 2412 | 2412 | files.erase(""); |
| ... | ... | @@ -2425,7 +2425,7 @@ QPDFJob::Inputs::process_all() |
| 2425 | 2425 | |
| 2426 | 2426 | for (auto& [filename, input]: files) { |
| 2427 | 2427 | if (!input.qpdf) { |
| 2428 | - process(filename, input); | |
| 2428 | + process(job, filename, input); | |
| 2429 | 2429 | } |
| 2430 | 2430 | |
| 2431 | 2431 | for (auto& selection: selections) { |
| ... | ... | @@ -2519,10 +2519,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf) |
| 2519 | 2519 | return; |
| 2520 | 2520 | } |
| 2521 | 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 | 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 | 2527 | // Clear all pages out of the primary QPDF's pages tree but leave the objects in place in the |
| 2528 | 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 | 37 | // filename. This is a documented work-around. |
| 38 | 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 | 42 | std::string password; |
| 43 | 43 | std::unique_ptr<QPDF> qpdf_p; |
| ... | ... | @@ -56,12 +56,8 @@ struct QPDFJob::Inputs |
| 56 | 56 | // These default values are duplicated in help and docs. |
| 57 | 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 | 62 | // Destroy all owned QPDF objects. Return false if any of the QPDF objects recorded warnings. |
| 67 | 63 | bool clear(); |
| ... | ... | @@ -90,9 +86,6 @@ struct QPDFJob::Inputs |
| 90 | 86 | std::vector<Selection> selections; |
| 91 | 87 | |
| 92 | 88 | bool any_page_labels{false}; |
| 93 | - | |
| 94 | - private: | |
| 95 | - QPDFJob& job; | |
| 96 | 89 | }; |
| 97 | 90 | |
| 98 | 91 | struct QPDFJob::RotationSpec |
| ... | ... | @@ -150,9 +143,8 @@ class QPDFJob::Members |
| 150 | 143 | friend class QPDFJob; |
| 151 | 144 | |
| 152 | 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 | 150 | Members(Members const&) = delete; | ... | ... |
manual/release-notes.rst
| ... | ... | @@ -13,6 +13,13 @@ more detail. |
| 13 | 13 | |
| 14 | 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 | 23 | 12.3.0: January 10, 2026 |
| 17 | 24 | - Release changes |
| 18 | 25 | ... | ... |