diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-02-14 20:04:40 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-02-14 20:42:24 +0100 |
commit | efbb21673c59cfbf6a74de6866a59cb2dbb8e59f (patch) | |
tree | 37439ac43400705551107542c9e9939ee8504294 /libqpdf | |
parent | e2593e2efe140d47870b0c511cbf5160db080edd (diff) | |
download | qpdf-efbb21673c59cfbf6a74de6866a59cb2dbb8e59f.tar.zst |
Add functional versions of QPDFObjectHandle::replaceStreamData
Also fix a bug in checking consistency of length for stream data
providers. Length should not be checked or recorded if the provider
says it failed to generate the data.
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 56 | ||||
-rw-r--r-- | libqpdf/QPDF_Stream.cc | 4 |
2 files changed, 58 insertions, 2 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 94875e13..d4796498 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1347,6 +1347,62 @@ QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider, provider, filter, decode_parms); } +class FunctionProvider: public QPDFObjectHandle::StreamDataProvider +{ + public: + FunctionProvider(std::function<void(Pipeline*)> provider) : + StreamDataProvider(false), + p1(provider), + p2(nullptr) + { + } + FunctionProvider(std::function<bool(Pipeline*, bool, bool)> provider) : + StreamDataProvider(true), + p1(nullptr), + p2(provider) + { + } + + virtual void provideStreamData(int, int, Pipeline* pipeline) override + { + p1(pipeline); + } + + virtual bool provideStreamData(int, int, Pipeline* pipeline, + bool suppress_warnings, + bool will_retry) override + { + return p2(pipeline, suppress_warnings, will_retry); + } + + private: + std::function<void(Pipeline*)> p1; + std::function<bool(Pipeline*, bool, bool)> p2; +}; + +void +QPDFObjectHandle::replaceStreamData(std::function<void(Pipeline*)> provider, + QPDFObjectHandle const& filter, + QPDFObjectHandle const& decode_parms) +{ + assertStream(); + PointerHolder<StreamDataProvider> sdp = new FunctionProvider(provider); + dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData( + sdp, filter, decode_parms); +} + +void +QPDFObjectHandle::replaceStreamData( + std::function<bool(Pipeline*, bool, bool)> provider, + QPDFObjectHandle const& filter, + QPDFObjectHandle const& decode_parms) +{ + assertStream(); + PointerHolder<StreamDataProvider> sdp = new FunctionProvider(provider); + dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData( + sdp, filter, decode_parms); +} + QPDFObjGen QPDFObjectHandle::getObjGen() const { diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index b05137df..bc3b1b56 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -533,7 +533,7 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, } qpdf_offset_t actual_length = count.getCount(); qpdf_offset_t desired_length = 0; - if (this->stream_dict.hasKey("/Length")) + if (success && this->stream_dict.hasKey("/Length")) { desired_length = this->stream_dict.getKey("/Length").getIntValue(); if (actual_length == desired_length) @@ -555,7 +555,7 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, QUtil::int_to_string(desired_length) + " bytes"); } } - else + else if (success) { QTC::TC("qpdf", "QPDF_Stream provider length not provided"); this->stream_dict.replaceKey( |