diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 15cea44..5731e4a 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -425,9 +425,7 @@ QPDFJob::createQPDF() pdf.updateFromJSON(m->update_from_json); } - if (!m->selections.empty()) { - handlePageSpecs(pdf); - } + handlePageSpecs(pdf); if (!m->rotations.empty()) { handleRotations(pdf); } @@ -2351,10 +2349,10 @@ QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) } void -QPDFJob::new_selection( +QPDFJob::Inputs::new_selection( std::string const& filename, std::string const& password, std::string const& range) { - m->selections.emplace_back(filename, password, range); + selections.emplace_back(filename, password, range); } void @@ -2430,11 +2428,14 @@ QPDFJob::Inputs::clear() void QPDFJob::handlePageSpecs(QPDF& pdf) { + if (m->inputs.selections.empty()) { + return; + } auto& main_input = m->inputs.files[m->infilename]; main_input.initialize(m->inputs, &pdf); // Handle "." as a shortcut for the input file. - for (auto& selection: m->selections) { + for (auto& selection: m->inputs.selections) { if (selection.filename == ".") { selection.filename = m->infilename; } else { @@ -2452,7 +2453,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf) m->inputs.process_all(); std::map> copied_pages; - for (auto& selection: m->selections) { + for (auto& selection: m->inputs.selections) { // Read original pages from the PDF, and parse the page range associated with this // occurrence of the file. auto const& input = m->inputs.files[selection.filename]; @@ -2476,7 +2477,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf) } auto n_collate = m->collate.size(); - auto n_specs = m->selections.size(); + auto n_specs = m->inputs.selections.size(); if (!(n_collate == 0 || n_collate == 1 || n_collate == n_specs)) { usage( "--pages: if --collate has more than one value, it must have one value per page " @@ -2497,7 +2498,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf) while (got_pages) { got_pages = false; for (size_t i = 0; i < n_specs; ++i) { - auto& page_data = m->selections.at(i); + auto& page_data = m->inputs.selections.at(i); for (size_t j = 0; j < m->collate.at(i); ++j) { if (cur_page.at(i) + j < page_data.selected_pages.size()) { got_pages = true; @@ -2518,7 +2519,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf) int out_pageno = 0; auto& this_afdh = pdf.acroform(); std::set referenced_fields; - for (auto& selection: new_specs.empty() ? m->selections : new_specs) { + for (auto& selection: new_specs.empty() ? m->inputs.selections : new_specs) { auto& input = m->inputs.files[selection.filename]; if (input.cfis) { input.cfis->stayOpen(true); diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index 6aac121..fb58d52 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -978,7 +978,7 @@ QPDFJob::PagesConfig::PagesConfig(Config* c) : std::shared_ptr QPDFJob::Config::pages() { - if (!o.m->selections.empty()) { + if (!o.m->inputs.selections.empty()) { usage("--pages may only be specified one time"); } return std::shared_ptr(new PagesConfig(this)); @@ -987,7 +987,7 @@ QPDFJob::Config::pages() QPDFJob::Config* QPDFJob::PagesConfig::endPages() { - auto n_specs = config->o.m->selections.size(); + auto n_specs = config->o.m->inputs.selections.size(); if (n_specs == 0) { usage("--pages: no page specifications given"); } @@ -998,24 +998,24 @@ QPDFJob::PagesConfig* QPDFJob::PagesConfig::pageSpec( std::string const& filename, std::string const& range, char const* password) { - config->o.new_selection(filename, {password ? password : ""}, range); + config->o.m->inputs.new_selection(filename, {password ? password : ""}, range); return this; } QPDFJob::PagesConfig* QPDFJob::PagesConfig::file(std::string const& arg) { - config->o.new_selection(arg, {}, {}); + config->o.m->inputs.new_selection(arg, {}, {}); return this; } QPDFJob::PagesConfig* QPDFJob::PagesConfig::range(std::string const& arg) { - if (config->o.m->selections.empty()) { + if (config->o.m->inputs.selections.empty()) { usage("in --range must follow a file name"); } - auto& last = config->o.m->selections.back(); + auto& last = config->o.m->inputs.selections.back(); if (!last.range.empty()) { usage("--range already specified for this file"); } @@ -1026,10 +1026,10 @@ QPDFJob::PagesConfig::range(std::string const& arg) QPDFJob::PagesConfig* QPDFJob::PagesConfig::password(std::string const& arg) { - if (config->o.m->selections.empty()) { + if (config->o.m->inputs.selections.empty()) { usage("in --pages, --password must follow a file name"); } - auto& last = config->o.m->selections.back(); + auto& last = config->o.m->inputs.selections.back(); if (!last.password.empty()) { usage("--password already specified for this file"); } diff --git a/libqpdf/qpdf/QPDFJob_private.hh b/libqpdf/qpdf/QPDFJob_private.hh index f207721..28bdced 100644 --- a/libqpdf/qpdf/QPDFJob_private.hh +++ b/libqpdf/qpdf/QPDFJob_private.hh @@ -66,6 +66,9 @@ struct QPDFJob::Inputs // Destroy all owned QPDF objects. Return false if any of the QPDF objects recorded warnings. bool clear(); + void new_selection( + std::string const& filename, std::string const& password, std::string const& range); + std::string encryption_file; std::string encryption_file_password; bool keep_files_open{true}; @@ -73,6 +76,7 @@ struct QPDFJob::Inputs size_t keep_files_open_threshold{DEFAULT_KEEP_FILES_OPEN_THRESHOLD}; std::map files; + std::vector selections; private: QPDFJob& job; @@ -263,7 +267,6 @@ class QPDFJob::Members std::vector overlay; UnderOverlay* under_overlay{nullptr}; Inputs inputs; - std::vector selections; std::map rotations; bool require_outfile{true}; bool replace_input{false};