Commit 41c5af8f2664cef36d4a1253ba5251603a937605
1 parent
9373881c
QPDFJob: convert pages
Showing
7 changed files
with
88 additions
and
32 deletions
generate_auto_job
| ... | ... | @@ -33,17 +33,6 @@ def write_file(filename): |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | # QXXXQ |
| 36 | -# These need manual handlers. | |
| 37 | -complex = set([ | |
| 38 | - 'add-attachment', | |
| 39 | - 'copy-attachments-from', | |
| 40 | - 'encrypt', | |
| 41 | - 'overlay', | |
| 42 | - 'pages', | |
| 43 | - 'underlay', | |
| 44 | -]) | |
| 45 | - | |
| 46 | -# QXXXQ | |
| 47 | 36 | # These are trivial but not in main and so need a different config |
| 48 | 37 | # object. Some are in more than one table. |
| 49 | 38 | not_yet = set([ |
| ... | ... | @@ -466,8 +455,8 @@ class Main: |
| 466 | 455 | for i, [kind, v] in flags.items(): |
| 467 | 456 | self.options_without_help.add(f'--{i}') |
| 468 | 457 | add_jdata(i, table_prefix or table) |
| 469 | - # QXXXQ complex, not_yet | |
| 470 | - if i in complex or i in not_yet or config is None: | |
| 458 | + # QXXXQ not_yet | |
| 459 | + if i in not_yet or config is None or i in o.get('manual', []): | |
| 471 | 460 | identifier = self.to_identifier(i, arg_prefix, False) |
| 472 | 461 | self.handle_flag(i, identifier, kind, v) |
| 473 | 462 | else: |
| ... | ... | @@ -581,7 +570,7 @@ class Main: |
| 581 | 570 | ['choices', 'options', 'no-json', 'json'])) |
| 582 | 571 | for o in data['options']: |
| 583 | 572 | self.check_keys('top', o, set( |
| 584 | - ['table', 'prefix', 'config', 'bare', 'positional', | |
| 573 | + ['table', 'prefix', 'config', 'manual', 'bare', 'positional', | |
| 585 | 574 | 'optional_parameter', 'required_parameter', |
| 586 | 575 | 'required_choices', 'optional_choices', 'from_table'])) |
| 587 | 576 | ... | ... |
include/qpdf/QPDFJob.hh
| ... | ... | @@ -135,6 +135,17 @@ class QPDFJob |
| 135 | 135 | bool replace; |
| 136 | 136 | }; |
| 137 | 137 | |
| 138 | + struct PageSpec | |
| 139 | + { | |
| 140 | + PageSpec(std::string const& filename, | |
| 141 | + char const* password, | |
| 142 | + std::string const& range); | |
| 143 | + | |
| 144 | + std::string filename; | |
| 145 | + std::shared_ptr<char> password; | |
| 146 | + std::string range; | |
| 147 | + }; | |
| 148 | + | |
| 138 | 149 | public: |
| 139 | 150 | class Config; |
| 140 | 151 | |
| ... | ... | @@ -172,6 +183,24 @@ class QPDFJob |
| 172 | 183 | CopyAttachmentFrom caf; |
| 173 | 184 | }; |
| 174 | 185 | |
| 186 | + class PagesConfig | |
| 187 | + { | |
| 188 | + friend class QPDFJob; | |
| 189 | + friend class Config; | |
| 190 | + public: | |
| 191 | + PagesConfig& pageSpec(std::string const& filename, | |
| 192 | + char const* password, | |
| 193 | + std::string const& range); | |
| 194 | + | |
| 195 | +# include <qpdf/auto_job_c_pages.hh> | |
| 196 | + | |
| 197 | + private: | |
| 198 | + PagesConfig(Config&); | |
| 199 | + PagesConfig(PagesConfig const&) = delete; | |
| 200 | + | |
| 201 | + Config& config; | |
| 202 | + }; | |
| 203 | + | |
| 175 | 204 | // Configuration is performed by calling methods XXX QXXXQ document |
| 176 | 205 | class Config |
| 177 | 206 | { |
| ... | ... | @@ -180,6 +209,7 @@ class QPDFJob |
| 180 | 209 | QPDF_DLL |
| 181 | 210 | std::shared_ptr<CopyAttConfig> copyAttachmentsFrom(); |
| 182 | 211 | std::shared_ptr<AttConfig> addAttachment(); |
| 212 | + std::shared_ptr<PagesConfig> pages(); | |
| 183 | 213 | |
| 184 | 214 | # include <qpdf/auto_job_c_main.hh> |
| 185 | 215 | |
| ... | ... | @@ -243,17 +273,6 @@ class QPDFJob |
| 243 | 273 | static void parse_object_id( |
| 244 | 274 | std::string const& objspec, bool& trailer, int& obj, int& gen); |
| 245 | 275 | |
| 246 | - struct PageSpec | |
| 247 | - { | |
| 248 | - PageSpec(std::string const& filename, | |
| 249 | - char const* password, | |
| 250 | - std::string const& range); | |
| 251 | - | |
| 252 | - std::string filename; | |
| 253 | - std::shared_ptr<char> password; | |
| 254 | - std::string range; | |
| 255 | - }; | |
| 256 | - | |
| 257 | 276 | struct RotationSpec |
| 258 | 277 | { |
| 259 | 278 | RotationSpec(int angle = 0, bool relative = false) : | ... | ... |
include/qpdf/auto_job_c_pages.hh
0 โ 100644
job.sums
| 1 | 1 | # Generated by generate_auto_job |
| 2 | -generate_auto_job d9f75a50dd4e503ede676bad54f80f856de096da7f3ad0e4594b0d09a6e1215d | |
| 2 | +generate_auto_job 66e43cdb4ae166d020be19fcc6f8e9f0445c4de6a5395ff5aff511b89763c4e1 | |
| 3 | 3 | include/qpdf/auto_job_c_att.hh ecc3f8f711b486b491e811176362a90c022eb225ff12157df3a10ca021be87b1 |
| 4 | 4 | include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a |
| 5 | 5 | include/qpdf/auto_job_c_main.hh 5fdd9c85aa295a3caec467b9607fe82c874cd3aaeb7806b9d18074f7b96fd085 |
| 6 | -job.yml e649f7dbb3748584f338b330043336ce4a4d51a34b00b42caa89dcfbc7bdcb84 | |
| 6 | +include/qpdf/auto_job_c_pages.hh 79ee6e52a36fedfd0e6ca60bd926bc25a3e975ab6fa984a7e798a48791e8ba86 | |
| 7 | +job.yml 4cd60df0caa74b68cc39352910a8381c3411248bc3edef69f9d16d75e807f451 | |
| 7 | 8 | libqpdf/qpdf/auto_job_decl.hh 38f7462e34fea7d46d5e5519ac1742be6e57ea6f66c47b37d5425f3a2b9ca536 |
| 8 | 9 | libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538 |
| 9 | 10 | libqpdf/qpdf/auto_job_init.hh b49d839078d84398142f8f14bdae8a71f44fbff13cdf7b350b84ef2410aaa6a3 | ... | ... |
job.yml
| ... | ... | @@ -61,6 +61,13 @@ options: |
| 61 | 61 | - job-json-help |
| 62 | 62 | - table: main |
| 63 | 63 | config: c_main |
| 64 | + manual: | |
| 65 | + - add-attachment | |
| 66 | + - copy-attachments-from | |
| 67 | + - encrypt | |
| 68 | + - overlay | |
| 69 | + - pages | |
| 70 | + - underlay | |
| 64 | 71 | positional: true |
| 65 | 72 | bare: |
| 66 | 73 | - add-attachment |
| ... | ... | @@ -148,8 +155,11 @@ options: |
| 148 | 155 | remove-unreferenced-resources: remove_unref |
| 149 | 156 | stream-data: stream_data |
| 150 | 157 | - table: pages |
| 158 | + config: c_pages | |
| 151 | 159 | prefix: Pages |
| 152 | 160 | positional: true |
| 161 | + manual: | |
| 162 | + - password | |
| 153 | 163 | required_parameter: |
| 154 | 164 | password: password |
| 155 | 165 | - table: encryption | ... | ... |
libqpdf/QPDFJob_argv.cc
| ... | ... | @@ -46,6 +46,7 @@ namespace |
| 46 | 46 | std::shared_ptr<QPDFJob::Config> c_main; |
| 47 | 47 | std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att; |
| 48 | 48 | std::shared_ptr<QPDFJob::AttConfig> c_att; |
| 49 | + std::shared_ptr<QPDFJob::PagesConfig> c_pages; | |
| 49 | 50 | std::vector<char*> accumulated_args; // points to member in ap |
| 50 | 51 | char* pages_password; |
| 51 | 52 | }; |
| ... | ... | @@ -310,6 +311,7 @@ ArgParser::argPages() |
| 310 | 311 | usage("the --pages may only be specified one time"); |
| 311 | 312 | } |
| 312 | 313 | this->accumulated_args.clear(); |
| 314 | + this->c_pages = c_main->pages(); | |
| 313 | 315 | this->ap.selectOptionTable(O_PAGES); |
| 314 | 316 | } |
| 315 | 317 | |
| ... | ... | @@ -402,7 +404,7 @@ ArgParser::argPagesPositional(char* arg) |
| 402 | 404 | { |
| 403 | 405 | range = "1-z"; |
| 404 | 406 | } |
| 405 | - o.page_specs.push_back(QPDFJob::PageSpec(file, this->pages_password, range)); | |
| 407 | + this->c_pages->pageSpec(file, this->pages_password, range); | |
| 406 | 408 | this->accumulated_args.clear(); |
| 407 | 409 | this->pages_password = nullptr; |
| 408 | 410 | if (next_file != nullptr) |
| ... | ... | @@ -415,10 +417,8 @@ void |
| 415 | 417 | ArgParser::argEndPages() |
| 416 | 418 | { |
| 417 | 419 | argPagesPositional(nullptr); |
| 418 | - if (o.page_specs.empty()) | |
| 419 | - { | |
| 420 | - usage("--pages: no page specifications given"); | |
| 421 | - } | |
| 420 | + c_pages->end(); | |
| 421 | + c_pages = nullptr; | |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | void | ... | ... |
libqpdf/QPDFJob_config.cc
| ... | ... | @@ -657,3 +657,34 @@ QPDFJob::AttConfig::end() |
| 657 | 657 | this->config.o.attachments_to_add.push_back(this->att); |
| 658 | 658 | return this->config; |
| 659 | 659 | } |
| 660 | + | |
| 661 | +QPDFJob::PagesConfig::PagesConfig(Config& c) : | |
| 662 | + config(c) | |
| 663 | +{ | |
| 664 | +} | |
| 665 | + | |
| 666 | +std::shared_ptr<QPDFJob::PagesConfig> | |
| 667 | +QPDFJob::Config::pages() | |
| 668 | +{ | |
| 669 | + return std::shared_ptr<PagesConfig>(new PagesConfig(*this)); | |
| 670 | +} | |
| 671 | + | |
| 672 | +QPDFJob::Config& | |
| 673 | +QPDFJob::PagesConfig::end() | |
| 674 | +{ | |
| 675 | + if (this->config.o.page_specs.empty()) | |
| 676 | + { | |
| 677 | + throw QPDFJob::ConfigError("--pages: no page specifications given"); | |
| 678 | + } | |
| 679 | + return this->config; | |
| 680 | +} | |
| 681 | + | |
| 682 | +QPDFJob::PagesConfig& | |
| 683 | +QPDFJob::PagesConfig::pageSpec(std::string const& filename, | |
| 684 | + char const* password, | |
| 685 | + std::string const& range) | |
| 686 | +{ | |
| 687 | + this->config.o.page_specs.push_back( | |
| 688 | + QPDFJob::PageSpec(filename, password, range)); | |
| 689 | + return *this; | |
| 690 | +} | ... | ... |