Commit b480f7186ffa6a2f4fe3a477c2e95871a64b2169
Committed by
GitHub
Merge pull request #928 from m-holger/wr_og
Add new data member QPDFWriter::Members::root_og
Showing
2 changed files
with
52 additions
and
95 deletions
include/qpdf/QPDFWriter.hh
| ... | ... | @@ -709,70 +709,71 @@ class QPDFWriter |
| 709 | 709 | Members(Members const&) = delete; |
| 710 | 710 | |
| 711 | 711 | QPDF& pdf; |
| 712 | - char const* filename; | |
| 713 | - FILE* file; | |
| 714 | - bool close_file; | |
| 715 | - Pl_Buffer* buffer_pipeline; | |
| 716 | - Buffer* output_buffer; | |
| 717 | - bool normalize_content_set; | |
| 718 | - bool normalize_content; | |
| 719 | - bool compress_streams; | |
| 720 | - bool compress_streams_set; | |
| 721 | - qpdf_stream_decode_level_e stream_decode_level; | |
| 722 | - bool stream_decode_level_set; | |
| 723 | - bool recompress_flate; | |
| 724 | - bool qdf_mode; | |
| 725 | - bool preserve_unreferenced_objects; | |
| 726 | - bool newline_before_endstream; | |
| 727 | - bool static_id; | |
| 728 | - bool suppress_original_object_ids; | |
| 729 | - bool direct_stream_lengths; | |
| 730 | - bool encrypted; | |
| 731 | - bool preserve_encryption; | |
| 732 | - bool linearized; | |
| 733 | - bool pclm; | |
| 734 | - qpdf_object_stream_e object_stream_mode; | |
| 712 | + QPDFObjGen root_og{-1, 0}; | |
| 713 | + char const* filename{"unspecified"}; | |
| 714 | + FILE* file{nullptr}; | |
| 715 | + bool close_file{false}; | |
| 716 | + Pl_Buffer* buffer_pipeline{nullptr}; | |
| 717 | + Buffer* output_buffer{nullptr}; | |
| 718 | + bool normalize_content_set{false}; | |
| 719 | + bool normalize_content{false}; | |
| 720 | + bool compress_streams{true}; | |
| 721 | + bool compress_streams_set{false}; | |
| 722 | + qpdf_stream_decode_level_e stream_decode_level{qpdf_dl_none}; | |
| 723 | + bool stream_decode_level_set{false}; | |
| 724 | + bool recompress_flate{false}; | |
| 725 | + bool qdf_mode{false}; | |
| 726 | + bool preserve_unreferenced_objects{false}; | |
| 727 | + bool newline_before_endstream{false}; | |
| 728 | + bool static_id{false}; | |
| 729 | + bool suppress_original_object_ids{false}; | |
| 730 | + bool direct_stream_lengths{true}; | |
| 731 | + bool encrypted{false}; | |
| 732 | + bool preserve_encryption{true}; | |
| 733 | + bool linearized{false}; | |
| 734 | + bool pclm{false}; | |
| 735 | + qpdf_object_stream_e object_stream_mode{qpdf_o_preserve}; | |
| 735 | 736 | std::string encryption_key; |
| 736 | - bool encrypt_metadata; | |
| 737 | - bool encrypt_use_aes; | |
| 737 | + bool encrypt_metadata{true}; | |
| 738 | + bool encrypt_use_aes{false}; | |
| 738 | 739 | std::map<std::string, std::string> encryption_dictionary; |
| 739 | - int encryption_V; | |
| 740 | - int encryption_R; | |
| 740 | + int encryption_V{0}; | |
| 741 | + int encryption_R{0}; | |
| 741 | 742 | |
| 742 | 743 | std::string id1; // for /ID key of |
| 743 | 744 | std::string id2; // trailer dictionary |
| 744 | 745 | std::string final_pdf_version; |
| 745 | - int final_extension_level; | |
| 746 | + int final_extension_level{0}; | |
| 746 | 747 | std::string min_pdf_version; |
| 747 | - int min_extension_level; | |
| 748 | + int min_extension_level{0}; | |
| 748 | 749 | std::string forced_pdf_version; |
| 749 | - int forced_extension_level; | |
| 750 | + int forced_extension_level{0}; | |
| 750 | 751 | std::string extra_header_text; |
| 751 | - int encryption_dict_objid; | |
| 752 | + int encryption_dict_objid{0}; | |
| 752 | 753 | std::string cur_data_key; |
| 753 | 754 | std::list<std::shared_ptr<Pipeline>> to_delete; |
| 754 | - Pl_Count* pipeline; | |
| 755 | + Pl_Count* pipeline{nullptr}; | |
| 755 | 756 | std::vector<QPDFObjectHandle> object_queue; |
| 756 | 757 | size_t object_queue_front{0}; |
| 757 | 758 | std::map<QPDFObjGen, int> obj_renumber; |
| 758 | 759 | std::map<int, QPDFXRefEntry> xref; |
| 759 | 760 | std::map<int, qpdf_offset_t> lengths; |
| 760 | - int next_objid; | |
| 761 | - int cur_stream_length_id; | |
| 762 | - size_t cur_stream_length; | |
| 763 | - bool added_newline; | |
| 764 | - int max_ostream_index; | |
| 761 | + int next_objid{1}; | |
| 762 | + int cur_stream_length_id{0}; | |
| 763 | + size_t cur_stream_length{0}; | |
| 764 | + bool added_newline{false}; | |
| 765 | + int max_ostream_index{0}; | |
| 765 | 766 | std::set<QPDFObjGen> normalized_streams; |
| 766 | 767 | std::map<QPDFObjGen, int> page_object_to_seq; |
| 767 | 768 | std::map<QPDFObjGen, int> contents_to_page_seq; |
| 768 | 769 | std::map<QPDFObjGen, int> object_to_object_stream; |
| 769 | 770 | std::map<int, std::set<QPDFObjGen>> object_stream_to_objects; |
| 770 | 771 | std::list<Pipeline*> pipeline_stack; |
| 771 | - unsigned long long next_stack_id; | |
| 772 | - bool deterministic_id; | |
| 773 | - Pl_MD5* md5_pipeline; | |
| 772 | + unsigned long long next_stack_id{0}; | |
| 773 | + bool deterministic_id{false}; | |
| 774 | + Pl_MD5* md5_pipeline{nullptr}; | |
| 774 | 775 | std::string deterministic_id_data; |
| 775 | - bool did_write_setup; | |
| 776 | + bool did_write_setup{false}; | |
| 776 | 777 | |
| 777 | 778 | // For linearization only |
| 778 | 779 | std::string lin_pass1_filename; |
| ... | ... | @@ -781,9 +782,9 @@ class QPDFWriter |
| 781 | 782 | |
| 782 | 783 | // For progress reporting |
| 783 | 784 | std::shared_ptr<ProgressReporter> progress_reporter; |
| 784 | - int events_expected; | |
| 785 | - int events_seen; | |
| 786 | - int next_progress_report; | |
| 785 | + int events_expected{0}; | |
| 786 | + int events_seen{0}; | |
| 787 | + int next_progress_report{0}; | |
| 787 | 788 | }; |
| 788 | 789 | |
| 789 | 790 | // Keep all member variables inside the Members object, which we | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -52,50 +52,9 @@ QPDFWriter::FunctionProgressReporter::reportProgress(int progress) |
| 52 | 52 | |
| 53 | 53 | QPDFWriter::Members::Members(QPDF& pdf) : |
| 54 | 54 | pdf(pdf), |
| 55 | - filename("unspecified"), | |
| 56 | - file(nullptr), | |
| 57 | - close_file(false), | |
| 58 | - buffer_pipeline(nullptr), | |
| 59 | - output_buffer(nullptr), | |
| 60 | - normalize_content_set(false), | |
| 61 | - normalize_content(false), | |
| 62 | - compress_streams(true), | |
| 63 | - compress_streams_set(false), | |
| 64 | - stream_decode_level(qpdf_dl_none), | |
| 65 | - stream_decode_level_set(false), | |
| 66 | - recompress_flate(false), | |
| 67 | - qdf_mode(false), | |
| 68 | - preserve_unreferenced_objects(false), | |
| 69 | - newline_before_endstream(false), | |
| 70 | - static_id(false), | |
| 71 | - suppress_original_object_ids(false), | |
| 72 | - direct_stream_lengths(true), | |
| 73 | - encrypted(false), | |
| 74 | - preserve_encryption(true), | |
| 75 | - linearized(false), | |
| 76 | - pclm(false), | |
| 77 | - object_stream_mode(qpdf_o_preserve), | |
| 78 | - encrypt_metadata(true), | |
| 79 | - encrypt_use_aes(false), | |
| 80 | - encryption_V(0), | |
| 81 | - encryption_R(0), | |
| 82 | - final_extension_level(0), | |
| 83 | - min_extension_level(0), | |
| 84 | - forced_extension_level(0), | |
| 85 | - encryption_dict_objid(0), | |
| 86 | - pipeline(nullptr), | |
| 87 | - next_objid(1), | |
| 88 | - cur_stream_length_id(0), | |
| 89 | - cur_stream_length(0), | |
| 90 | - added_newline(false), | |
| 91 | - max_ostream_index(0), | |
| 92 | - next_stack_id(0), | |
| 93 | - deterministic_id(false), | |
| 94 | - md5_pipeline(nullptr), | |
| 95 | - did_write_setup(false), | |
| 96 | - events_expected(0), | |
| 97 | - events_seen(0), | |
| 98 | - next_progress_report(0) | |
| 55 | + root_og( | |
| 56 | + pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen() | |
| 57 | + : QPDFObjGen(-1, 0)) | |
| 99 | 58 | { |
| 100 | 59 | } |
| 101 | 60 | |
| ... | ... | @@ -1534,14 +1493,12 @@ QPDFWriter::unparseObject( |
| 1534 | 1493 | // is direct through the ADBE dictionary, so we can modify in |
| 1535 | 1494 | // place. |
| 1536 | 1495 | |
| 1537 | - bool is_root = false; | |
| 1496 | + const bool is_root = (old_og == m->root_og); | |
| 1538 | 1497 | bool have_extensions_other = false; |
| 1539 | 1498 | bool have_extensions_adbe = false; |
| 1540 | 1499 | |
| 1541 | 1500 | QPDFObjectHandle extensions; |
| 1542 | - if ((old_og.getObj() != 0) && | |
| 1543 | - (old_og == this->m->pdf.getRoot().getObjGen())) { | |
| 1544 | - is_root = true; | |
| 1501 | + if (is_root) { | |
| 1545 | 1502 | if (object.hasKey("/Extensions") && |
| 1546 | 1503 | object.getKey("/Extensions").isDictionary()) { |
| 1547 | 1504 | extensions = object.getKey("/Extensions"); |
| ... | ... | @@ -2396,10 +2353,9 @@ QPDFWriter::doWriteSetup() |
| 2396 | 2353 | // 8.0.0 has a bug that prevents it from being able to handle |
| 2397 | 2354 | // encrypted files with compressed document catalogs, so we |
| 2398 | 2355 | // disable them in that case as well. |
| 2399 | - QPDFObjGen og = this->m->pdf.getRoot().getObjGen(); | |
| 2400 | - if (this->m->object_to_object_stream.count(og)) { | |
| 2356 | + if (m->object_to_object_stream.count(m->root_og)) { | |
| 2401 | 2357 | QTC::TC("qpdf", "QPDFWriter uncompressing root"); |
| 2402 | - this->m->object_to_object_stream.erase(og); | |
| 2358 | + this->m->object_to_object_stream.erase(m->root_og); | |
| 2403 | 2359 | } |
| 2404 | 2360 | } |
| 2405 | 2361 | ... | ... |