Commit 4c61ba56d4204a6ec0e9549d9c6f8d6960b2bfcb

Authored by m-holger
1 parent 6d42b9a7

Refactor `QPDFJob`: split private structures and implementation details into `QP…

…DFJob_private.hh`, streamline includes, and reduce header dependencies.
include/qpdf/QPDFJob.hh
@@ -425,58 +425,12 @@ class QPDFJob @@ -425,58 +425,12 @@ class QPDFJob
425 [[deprecated("use job_json_schema(version)")]] static std::string QPDF_DLL job_json_schema_v1(); 425 [[deprecated("use job_json_schema(version)")]] static std::string QPDF_DLL job_json_schema_v1();
426 426
427 private: 427 private:
428 - struct RotationSpec  
429 - {  
430 - RotationSpec(int angle = 0, bool relative = false) :  
431 - angle(angle),  
432 - relative(relative)  
433 - {  
434 - }  
435 -  
436 - int angle;  
437 - bool relative;  
438 - }; 428 + struct RotationSpec;
  429 + struct UnderOverlay;
  430 + struct PageLabelSpec;
439 431
440 enum password_mode_e { pm_bytes, pm_hex_bytes, pm_unicode, pm_auto }; 432 enum password_mode_e { pm_bytes, pm_hex_bytes, pm_unicode, pm_auto };
441 433
442 - struct UnderOverlay  
443 - {  
444 - UnderOverlay(char const* which) :  
445 - which(which),  
446 - to_nr("1-z"),  
447 - from_nr("1-z"),  
448 - repeat_nr("")  
449 - {  
450 - }  
451 -  
452 - std::string which;  
453 - std::string filename;  
454 - std::string password;  
455 - std::string to_nr;  
456 - std::string from_nr;  
457 - std::string repeat_nr;  
458 - std::unique_ptr<QPDF> pdf;  
459 - std::vector<int> to_pagenos;  
460 - std::vector<int> from_pagenos;  
461 - std::vector<int> repeat_pagenos;  
462 - };  
463 -  
464 - struct PageLabelSpec  
465 - {  
466 - PageLabelSpec(  
467 - int first_page, qpdf_page_label_e label_type, int start_num, std::string_view prefix) :  
468 - first_page(first_page),  
469 - label_type(label_type),  
470 - start_num(start_num),  
471 - prefix(prefix)  
472 - {  
473 - }  
474 - int first_page;  
475 - qpdf_page_label_e label_type;  
476 - int start_num{1};  
477 - std::string prefix;  
478 - };  
479 -  
480 // Helper functions 434 // Helper functions
481 static void usage(std::string const& msg); 435 static void usage(std::string const& msg);
482 static JSON json_schema(int json_version, std::set<std::string>* keys = nullptr); 436 static JSON json_schema(int json_version, std::set<std::string>* keys = nullptr);
@@ -568,159 +522,8 @@ class QPDFJob @@ -568,159 +522,8 @@ class QPDFJob
568 522
569 enum remove_unref_e { re_auto, re_yes, re_no }; 523 enum remove_unref_e { re_auto, re_yes, re_no };
570 524
571 - class Members  
572 - {  
573 - friend class QPDFJob; 525 + class Members;
574 526
575 - public:  
576 - QPDF_DLL  
577 - ~Members() = default;  
578 -  
579 - private:  
580 - // These default values are duplicated in help and docs.  
581 - static int constexpr DEFAULT_KEEP_FILES_OPEN_THRESHOLD = 200;  
582 - static int constexpr DEFAULT_OI_MIN_WIDTH = 128;  
583 - static int constexpr DEFAULT_OI_MIN_HEIGHT = 128;  
584 - static int constexpr DEFAULT_OI_MIN_AREA = 16384;  
585 - static int constexpr DEFAULT_II_MIN_BYTES = 1024;  
586 -  
587 - Members();  
588 - Members(Members const&) = delete;  
589 -  
590 - std::shared_ptr<QPDFLogger> log;  
591 - std::string message_prefix{"qpdf"};  
592 - bool warnings{false};  
593 - unsigned long encryption_status{0};  
594 - bool verbose{false};  
595 - std::string password;  
596 - bool linearize{false};  
597 - bool decrypt{false};  
598 - bool remove_restrictions{false};  
599 - int split_pages{0};  
600 - bool progress{false};  
601 - std::function<void(int)> progress_handler{nullptr};  
602 - bool suppress_warnings{false};  
603 - bool warnings_exit_zero{false};  
604 - bool copy_encryption{false};  
605 - std::string encryption_file;  
606 - std::string encryption_file_password;  
607 - bool encrypt{false};  
608 - bool password_is_hex_key{false};  
609 - bool suppress_password_recovery{false};  
610 - password_mode_e password_mode{pm_auto};  
611 - bool allow_insecure{false};  
612 - bool allow_weak_crypto{false};  
613 - std::string user_password;  
614 - std::string owner_password;  
615 - int keylen{0};  
616 - bool r2_print{true};  
617 - bool r2_modify{true};  
618 - bool r2_extract{true};  
619 - bool r2_annotate{true};  
620 - bool r3_accessibility{true};  
621 - bool r3_extract{true};  
622 - bool r3_assemble{true};  
623 - bool r3_annotate_and_form{true};  
624 - bool r3_form_filling{true};  
625 - bool r3_modify_other{true};  
626 - qpdf_r3_print_e r3_print{qpdf_r3p_full};  
627 - bool force_V4{false};  
628 - bool force_R5{false};  
629 - bool cleartext_metadata{false};  
630 - bool use_aes{false};  
631 - bool stream_data_set{false};  
632 - qpdf_stream_data_e stream_data_mode{qpdf_s_compress};  
633 - bool compress_streams{true};  
634 - bool compress_streams_set{false};  
635 - bool recompress_flate{false};  
636 - bool recompress_flate_set{false};  
637 - int compression_level{-1};  
638 - int jpeg_quality{-1};  
639 - qpdf_stream_decode_level_e decode_level{qpdf_dl_generalized};  
640 - bool decode_level_set{false};  
641 - bool normalize_set{false};  
642 - bool normalize{false};  
643 - bool suppress_recovery{false};  
644 - bool object_stream_set{false};  
645 - qpdf_object_stream_e object_stream_mode{qpdf_o_preserve};  
646 - bool ignore_xref_streams{false};  
647 - bool qdf_mode{false};  
648 - bool preserve_unreferenced_objects{false};  
649 - remove_unref_e remove_unreferenced_page_resources{re_auto};  
650 - bool keep_files_open{true};  
651 - bool keep_files_open_set{false};  
652 - size_t keep_files_open_threshold{DEFAULT_KEEP_FILES_OPEN_THRESHOLD};  
653 - bool newline_before_endstream{false};  
654 - std::string linearize_pass1;  
655 - bool coalesce_contents{false};  
656 - bool flatten_annotations{false};  
657 - int flatten_annotations_required{0};  
658 - int flatten_annotations_forbidden{an_invisible | an_hidden};  
659 - bool generate_appearances{false};  
660 - PDFVersion max_input_version;  
661 - std::string min_version;  
662 - std::string force_version;  
663 - bool show_npages{false};  
664 - bool deterministic_id{false};  
665 - bool static_id{false};  
666 - bool static_aes_iv{false};  
667 - bool suppress_original_object_id{false};  
668 - bool show_encryption{false};  
669 - bool show_encryption_key{false};  
670 - bool check_linearization{false};  
671 - bool show_linearization{false};  
672 - bool show_xref{false};  
673 - bool show_trailer{false};  
674 - int show_obj{0};  
675 - int show_gen{0};  
676 - bool show_raw_stream_data{false};  
677 - bool show_filtered_stream_data{false};  
678 - bool show_pages{false};  
679 - bool show_page_images{false};  
680 - std::vector<size_t> collate;  
681 - bool flatten_rotation{false};  
682 - bool list_attachments{false};  
683 - std::string attachment_to_show;  
684 - std::list<std::string> attachments_to_remove;  
685 - std::list<AddAttachment> attachments_to_add;  
686 - std::list<CopyAttachmentFrom> attachments_to_copy;  
687 - int json_version{0};  
688 - std::set<std::string> json_keys;  
689 - std::set<std::string> json_objects;  
690 - qpdf_json_stream_data_e json_stream_data{qpdf_sj_none};  
691 - bool json_stream_data_set{false};  
692 - std::string json_stream_prefix;  
693 - bool test_json_schema{false};  
694 - bool check{false};  
695 - bool optimize_images{false};  
696 - bool externalize_inline_images{false};  
697 - bool keep_inline_images{false};  
698 - bool remove_info{false};  
699 - bool remove_metadata{false};  
700 - bool remove_page_labels{false};  
701 - bool remove_structure{false};  
702 - size_t oi_min_width{DEFAULT_OI_MIN_WIDTH};  
703 - size_t oi_min_height{DEFAULT_OI_MIN_HEIGHT};  
704 - size_t oi_min_area{DEFAULT_OI_MIN_AREA};  
705 - size_t ii_min_bytes{DEFAULT_II_MIN_BYTES};  
706 - std::vector<UnderOverlay> underlay;  
707 - std::vector<UnderOverlay> overlay;  
708 - UnderOverlay* under_overlay{nullptr};  
709 - std::vector<PageSpec> page_specs;  
710 - std::map<std::string, RotationSpec> rotations;  
711 - bool require_outfile{true};  
712 - bool replace_input{false};  
713 - bool check_is_encrypted{false};  
714 - bool check_requires_password{false};  
715 - std::string infilename;  
716 - bool empty_input{false};  
717 - std::string outfilename;  
718 - bool json_input{false};  
719 - bool json_output{false};  
720 - std::string update_from_json;  
721 - bool report_mem_usage{false};  
722 - std::vector<PageLabelSpec> page_label_specs;  
723 - };  
724 std::shared_ptr<Members> m; 527 std::shared_ptr<Members> m;
725 }; 528 };
726 529
libqpdf/QPDFJob.cc
1 -#include <qpdf/QPDFJob.hh> 1 +#include <qpdf/QPDFJob_private.hh>
2 2
3 #include <cstring> 3 #include <cstring>
4 #include <iostream> 4 #include <iostream>
libqpdf/QPDFJob_config.cc
1 -#include <qpdf/QPDFJob.hh> 1 +#include <qpdf/QPDFJob_private.hh>
2 2
3 #include <regex> 3 #include <regex>
4 4
libqpdf/QPDFJob_json.cc
1 -#include <qpdf/QPDFJob.hh> 1 +#include <qpdf/QPDFJob_private.hh>
2 2
3 #include <qpdf/JSONHandler.hh> 3 #include <qpdf/JSONHandler.hh>
4 #include <qpdf/QPDFUsage.hh> 4 #include <qpdf/QPDFUsage.hh>
libqpdf/qpdf/QPDFJob_private.hh 0 → 100644
  1 +#ifndef QPDFJOB_PRIVATE_HH
  2 +#define QPDFJOB_PRIVATE_HH
  3 +
  4 +#include <qpdf/QPDFJob.hh>
  5 +
  6 +#include <qpdf/ClosedFileInputSource.hh>
  7 +
  8 +struct QPDFJob::RotationSpec
  9 +{
  10 + RotationSpec(int angle = 0, bool relative = false) :
  11 + angle(angle),
  12 + relative(relative)
  13 + {
  14 + }
  15 +
  16 + int angle;
  17 + bool relative;
  18 +};
  19 +
  20 +struct QPDFJob::UnderOverlay
  21 +{
  22 + UnderOverlay(char const* which) :
  23 + which(which),
  24 + to_nr("1-z"),
  25 + from_nr("1-z"),
  26 + repeat_nr("")
  27 + {
  28 + }
  29 +
  30 + std::string which;
  31 + std::string filename;
  32 + std::string password;
  33 + std::string to_nr;
  34 + std::string from_nr;
  35 + std::string repeat_nr;
  36 + std::unique_ptr<QPDF> pdf;
  37 + std::vector<int> to_pagenos;
  38 + std::vector<int> from_pagenos;
  39 + std::vector<int> repeat_pagenos;
  40 +};
  41 +
  42 +struct QPDFJob::PageLabelSpec
  43 +{
  44 + PageLabelSpec(
  45 + int first_page, qpdf_page_label_e label_type, int start_num, std::string_view prefix) :
  46 + first_page(first_page),
  47 + label_type(label_type),
  48 + start_num(start_num),
  49 + prefix(prefix)
  50 + {
  51 + }
  52 + int first_page;
  53 + qpdf_page_label_e label_type;
  54 + int start_num{1};
  55 + std::string prefix;
  56 +};
  57 +
  58 +class QPDFJob::Members
  59 +{
  60 + friend class QPDFJob;
  61 +
  62 + public:
  63 + ~Members() = default;
  64 +
  65 + private:
  66 + // These default values are duplicated in help and docs.
  67 + static int constexpr DEFAULT_KEEP_FILES_OPEN_THRESHOLD = 200;
  68 + static int constexpr DEFAULT_OI_MIN_WIDTH = 128;
  69 + static int constexpr DEFAULT_OI_MIN_HEIGHT = 128;
  70 + static int constexpr DEFAULT_OI_MIN_AREA = 16384;
  71 + static int constexpr DEFAULT_II_MIN_BYTES = 1024;
  72 +
  73 + Members();
  74 + Members(Members const&) = delete;
  75 +
  76 + std::shared_ptr<QPDFLogger> log;
  77 + std::string message_prefix{"qpdf"};
  78 + bool warnings{false};
  79 + unsigned long encryption_status{0};
  80 + bool verbose{false};
  81 + std::string password;
  82 + bool linearize{false};
  83 + bool decrypt{false};
  84 + bool remove_restrictions{false};
  85 + int split_pages{0};
  86 + bool progress{false};
  87 + std::function<void(int)> progress_handler{nullptr};
  88 + bool suppress_warnings{false};
  89 + bool warnings_exit_zero{false};
  90 + bool copy_encryption{false};
  91 + std::string encryption_file;
  92 + std::string encryption_file_password;
  93 + bool encrypt{false};
  94 + bool password_is_hex_key{false};
  95 + bool suppress_password_recovery{false};
  96 + password_mode_e password_mode{pm_auto};
  97 + bool allow_insecure{false};
  98 + bool allow_weak_crypto{false};
  99 + std::string user_password;
  100 + std::string owner_password;
  101 + int keylen{0};
  102 + bool r2_print{true};
  103 + bool r2_modify{true};
  104 + bool r2_extract{true};
  105 + bool r2_annotate{true};
  106 + bool r3_accessibility{true};
  107 + bool r3_extract{true};
  108 + bool r3_assemble{true};
  109 + bool r3_annotate_and_form{true};
  110 + bool r3_form_filling{true};
  111 + bool r3_modify_other{true};
  112 + qpdf_r3_print_e r3_print{qpdf_r3p_full};
  113 + bool force_V4{false};
  114 + bool force_R5{false};
  115 + bool cleartext_metadata{false};
  116 + bool use_aes{false};
  117 + bool stream_data_set{false};
  118 + qpdf_stream_data_e stream_data_mode{qpdf_s_compress};
  119 + bool compress_streams{true};
  120 + bool compress_streams_set{false};
  121 + bool recompress_flate{false};
  122 + bool recompress_flate_set{false};
  123 + int compression_level{-1};
  124 + int jpeg_quality{-1};
  125 + qpdf_stream_decode_level_e decode_level{qpdf_dl_generalized};
  126 + bool decode_level_set{false};
  127 + bool normalize_set{false};
  128 + bool normalize{false};
  129 + bool suppress_recovery{false};
  130 + bool object_stream_set{false};
  131 + qpdf_object_stream_e object_stream_mode{qpdf_o_preserve};
  132 + bool ignore_xref_streams{false};
  133 + bool qdf_mode{false};
  134 + bool preserve_unreferenced_objects{false};
  135 + remove_unref_e remove_unreferenced_page_resources{re_auto};
  136 + bool keep_files_open{true};
  137 + bool keep_files_open_set{false};
  138 + size_t keep_files_open_threshold{DEFAULT_KEEP_FILES_OPEN_THRESHOLD};
  139 + bool newline_before_endstream{false};
  140 + std::string linearize_pass1;
  141 + bool coalesce_contents{false};
  142 + bool flatten_annotations{false};
  143 + int flatten_annotations_required{0};
  144 + int flatten_annotations_forbidden{an_invisible | an_hidden};
  145 + bool generate_appearances{false};
  146 + PDFVersion max_input_version;
  147 + std::string min_version;
  148 + std::string force_version;
  149 + bool show_npages{false};
  150 + bool deterministic_id{false};
  151 + bool static_id{false};
  152 + bool static_aes_iv{false};
  153 + bool suppress_original_object_id{false};
  154 + bool show_encryption{false};
  155 + bool show_encryption_key{false};
  156 + bool check_linearization{false};
  157 + bool show_linearization{false};
  158 + bool show_xref{false};
  159 + bool show_trailer{false};
  160 + int show_obj{0};
  161 + int show_gen{0};
  162 + bool show_raw_stream_data{false};
  163 + bool show_filtered_stream_data{false};
  164 + bool show_pages{false};
  165 + bool show_page_images{false};
  166 + std::vector<size_t> collate;
  167 + bool flatten_rotation{false};
  168 + bool list_attachments{false};
  169 + std::string attachment_to_show;
  170 + std::list<std::string> attachments_to_remove;
  171 + std::list<AddAttachment> attachments_to_add;
  172 + std::list<CopyAttachmentFrom> attachments_to_copy;
  173 + int json_version{0};
  174 + std::set<std::string> json_keys;
  175 + std::set<std::string> json_objects;
  176 + qpdf_json_stream_data_e json_stream_data{qpdf_sj_none};
  177 + bool json_stream_data_set{false};
  178 + std::string json_stream_prefix;
  179 + bool test_json_schema{false};
  180 + bool check{false};
  181 + bool optimize_images{false};
  182 + bool externalize_inline_images{false};
  183 + bool keep_inline_images{false};
  184 + bool remove_info{false};
  185 + bool remove_metadata{false};
  186 + bool remove_page_labels{false};
  187 + bool remove_structure{false};
  188 + size_t oi_min_width{DEFAULT_OI_MIN_WIDTH};
  189 + size_t oi_min_height{DEFAULT_OI_MIN_HEIGHT};
  190 + size_t oi_min_area{DEFAULT_OI_MIN_AREA};
  191 + size_t ii_min_bytes{DEFAULT_II_MIN_BYTES};
  192 + std::vector<UnderOverlay> underlay;
  193 + std::vector<UnderOverlay> overlay;
  194 + UnderOverlay* under_overlay{nullptr};
  195 + std::vector<PageSpec> page_specs;
  196 + std::map<std::string, RotationSpec> rotations;
  197 + bool require_outfile{true};
  198 + bool replace_input{false};
  199 + bool check_is_encrypted{false};
  200 + bool check_requires_password{false};
  201 + std::string infilename;
  202 + bool empty_input{false};
  203 + std::string outfilename;
  204 + bool json_input{false};
  205 + bool json_output{false};
  206 + std::string update_from_json;
  207 + bool report_mem_usage{false};
  208 + std::vector<PageLabelSpec> page_label_specs;
  209 +};
  210 +
  211 +#endif // QPDFOBJECT_PRIVATE_HH