Commit 0889eba4787c103fbc204a11229a1a7244daa7de
1 parent
95424109
Refactor `ForeignStreamData`: move to `Streams::Copier::Data`, improve encapsula…
…tion, and streamline stream registration logic.
Showing
3 changed files
with
27 additions
and
26 deletions
include/qpdf/QPDF.hh
libqpdf/QPDF.cc
| ... | ... | @@ -112,8 +112,7 @@ namespace |
| 112 | 112 | }; |
| 113 | 113 | } // namespace |
| 114 | 114 | |
| 115 | -QPDF::ForeignStreamData::ForeignStreamData( | |
| 116 | - Stream& foreign, qpdf_offset_t offset, QPDFObjectHandle local_dict) : | |
| 115 | +Streams::Copier::Data::Data(Stream& foreign, qpdf_offset_t offset, QPDFObjectHandle local_dict) : | |
| 117 | 116 | encp(foreign.qpdf()->m->encp), |
| 118 | 117 | file(foreign.qpdf()->m->file), |
| 119 | 118 | foreign_og(foreign.id_gen()), |
| ... | ... | @@ -715,8 +714,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign_oh) |
| 715 | 714 | result.replaceStreamData( |
| 716 | 715 | m->objects.streams().copier(), dict["/Filter"], dict["/DecodeParms"]); |
| 717 | 716 | } else { |
| 718 | - auto foreign_stream_data = ForeignStreamData(foreign, foreign_oh.offset(), dict); | |
| 719 | - m->objects.streams().copier()->register_copy(local_og, foreign_stream_data); | |
| 717 | + m->objects.streams().copier()->register_copy(local_og, foreign, foreign_oh.offset(), dict); | |
| 720 | 718 | result.replaceStreamData( |
| 721 | 719 | m->objects.streams().copier(), dict["/Filter"], dict["/DecodeParms"]); |
| 722 | 720 | } | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -89,23 +89,6 @@ class QPDF::EncryptionParameters |
| 89 | 89 | bool owner_password_matched{false}; |
| 90 | 90 | }; |
| 91 | 91 | |
| 92 | -class QPDF::ForeignStreamData | |
| 93 | -{ | |
| 94 | - friend class QPDF; | |
| 95 | - | |
| 96 | - public: | |
| 97 | - ForeignStreamData(Stream& foreign, qpdf_offset_t offset, QPDFObjectHandle local_dict); | |
| 98 | - | |
| 99 | - private: | |
| 100 | - std::shared_ptr<EncryptionParameters> encp; | |
| 101 | - std::shared_ptr<InputSource> file; | |
| 102 | - QPDFObjGen foreign_og; | |
| 103 | - qpdf_offset_t offset; | |
| 104 | - size_t length; | |
| 105 | - QPDFObjectHandle local_dict; | |
| 106 | - bool is_root_metadata{false}; | |
| 107 | -}; | |
| 108 | - | |
| 109 | 92 | class QPDF::StringDecrypter final: public QPDFObjectHandle::StringDecrypter |
| 110 | 93 | { |
| 111 | 94 | friend class QPDF; |
| ... | ... | @@ -599,6 +582,23 @@ class QPDF::Doc |
| 599 | 582 | // local and foreign streams. |
| 600 | 583 | class Copier final: public QPDFObjectHandle::StreamDataProvider |
| 601 | 584 | { |
| 585 | + class Data | |
| 586 | + { | |
| 587 | + friend class Streams; | |
| 588 | + | |
| 589 | + public: | |
| 590 | + Data(Stream& foreign, qpdf_offset_t offset, QPDFObjectHandle local_dict); | |
| 591 | + | |
| 592 | + private: | |
| 593 | + std::shared_ptr<EncryptionParameters> encp; | |
| 594 | + std::shared_ptr<InputSource> file; | |
| 595 | + QPDFObjGen foreign_og; | |
| 596 | + qpdf_offset_t offset; | |
| 597 | + size_t length; | |
| 598 | + QPDFObjectHandle local_dict; | |
| 599 | + bool is_root_metadata{false}; | |
| 600 | + }; | |
| 601 | + | |
| 602 | 602 | public: |
| 603 | 603 | Copier() = delete; |
| 604 | 604 | Copier(StreamDataProvider const&) = delete; |
| ... | ... | @@ -616,21 +616,25 @@ class QPDF::Doc |
| 616 | 616 | bool will_retry) final; |
| 617 | 617 | |
| 618 | 618 | void |
| 619 | - register_copy(QPDFObjGen local_og, QPDFObjectHandle foreign_stream) | |
| 619 | + register_copy(QPDFObjGen local_og, QPDFObjectHandle const& foreign_stream) | |
| 620 | 620 | { |
| 621 | 621 | copied_streams.insert_or_assign(local_og, foreign_stream); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | void |
| 625 | - register_copy(QPDFObjGen local_og, ForeignStreamData foreign_stream) | |
| 625 | + register_copy( | |
| 626 | + QPDFObjGen local_og, | |
| 627 | + Stream& foreign, | |
| 628 | + qpdf_offset_t offset, | |
| 629 | + QPDFObjectHandle const& local_dict) | |
| 626 | 630 | { |
| 627 | - copied_data.insert_or_assign(local_og, foreign_stream); | |
| 631 | + copied_data.insert_or_assign(local_og, Data(foreign, offset, local_dict)); | |
| 628 | 632 | } |
| 629 | 633 | |
| 630 | 634 | private: |
| 631 | 635 | Streams& streams; |
| 632 | 636 | std::map<QPDFObjGen, QPDFObjectHandle> copied_streams; |
| 633 | - std::map<QPDFObjGen, ForeignStreamData> copied_data; | |
| 637 | + std::map<QPDFObjGen, Data> copied_data; | |
| 634 | 638 | }; |
| 635 | 639 | |
| 636 | 640 | public: | ... | ... |