From 998a6cbee911ee8d49b2ce2f24e0cb4898289492 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 2 Aug 2010 22:40:52 +0000 Subject: remove stream_data_handler; it wouldn't work as designed. replacement data implemented but not tested git-svn-id: svn+q:///qpdf/trunk@988 71b93d88-0707-0410-a8cf-f5a4172ac649 --- TODO | 3 +++ include/qpdf/QPDFObjectHandle.hh | 46 ---------------------------------------- libqpdf/QPDFObjectHandle.cc | 7 ------ libqpdf/QPDF_Stream.cc | 25 ++++++++++++---------- libqpdf/qpdf/QPDF_Stream.hh | 3 --- qpdf/qpdf.testcov | 2 ++ 6 files changed, 19 insertions(+), 67 deletions(-) diff --git a/TODO b/TODO index f257f0cc..f20c44c0 100644 --- a/TODO +++ b/TODO @@ -25,6 +25,9 @@ Next QPDF_Stream.cc carefully line by line to make sure everything is adjusted properly. + Don't forget to provide a method that provides a pipeline through + which the stream data is to be piped. + * Add helper routines for manipulating page content streams. Operations should include ability to convert page contents from a stream to an array of streams and to append or prepend to the page diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 83e3592f..a7b8b991 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -197,52 +197,6 @@ class QPDFObjectHandle void replaceStreamData(PointerHolder data, QPDFObjectHandle filter, QPDFObjectHandle decode_parms); - class StreamDataHandler - { - public: - QPDF_DLL - virtual ~StreamDataHandler() - { - } - - // See replaceStreamData(StreamDataHandler) below for a - // description of how to override this function. - virtual void - replaceStreamData(Buffer const& in_data, - std::string const& in_filter, - std::string const& in_decode_parms, - bool filtered, - Buffer& out_data, - std::string& out_filter, - std::string& out_decode_parms, - bool& persist) = 0; - }; - // Provide a hook for doing dynamic replacement of the stream's - // data. When the stream's data is accessed either with - // pipeStreamData or with getStreamData, if the stream doesn't - // already have replacement data, an attempt is first made to - // filter the stream's original data. If the attempt is - // successful, the stream's filtered original data is passed to - // the handler as in_data, and filtered is true. If the original - // data cannot be processed, then in_data is the original raw data - // (after any decryption filters have been applied) and filtered - // is false. If the original input data has no filters applied, - // the filtered is true. This way, if filtered is true, the - // caller knows that in_data contains the fully filtered data. - // The handler then provides replacement data, /Filter, and - // /DecodeParms (handled is in the simpler form of - // replaceStreamData above). If the persist argument is set to - // true, then the replacement data is stored in the stream object - // where it will be used on subsequent attempts to retrieve the - // data (rather than calling the handler). If persist is set to - // false, then the data will be used that one time and not saved. - // In that case, the handler will be invoked again if the stream - // data is accessed another time. Writing a handler that sets - // persist to true essentially allows delaying the computation of - // the stream data, while setting it to false reduces the amount - // of memory that is used. - QPDF_DLL - void replaceStreamData(PointerHolder dh); // return 0 for direct objects QPDF_DLL diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 2fff0e31..756f3f55 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -362,13 +362,6 @@ QPDFObjectHandle::replaceStreamData(PointerHolder data, data, filter, decode_parms); } -void -QPDFObjectHandle::replaceStreamData(PointerHolder dh) -{ - assertType("Stream", isStream()); - dynamic_cast(obj.getPointer())->replaceStreamData(dh); -} - int QPDFObjectHandle::getObjectID() const { diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 500dfb10..5e53b2ae 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -319,10 +319,20 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, } } - // XXX handle stream_data and stream_data_handler - QPDF::Pipe::pipeStreamData(this->qpdf, this->objid, this->generation, - this->offset, this->length, - this->stream_dict, pipeline); + if (this->stream_data.getPointer()) + { + QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data"); + Buffer& b = *(this->stream_data.getPointer()); + pipeline->write(b.getBuffer(), b.getSize()); + pipeline->finish(); + } + else + { + QTC::TC("qpdf", "QPDF_Stream pipe original stream data"); + QPDF::Pipe::pipeStreamData(this->qpdf, this->objid, this->generation, + this->offset, this->length, + this->stream_dict, pipeline); + } return filter; } @@ -339,10 +349,3 @@ QPDF_Stream::replaceStreamData(PointerHolder data, QPDFObjectHandle::newInteger( data.getPointer()->getSize())); } - -void -QPDF_Stream::replaceStreamData( - PointerHolder dh) -{ - this->stream_data_handler = dh; -} diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index cc7cbf0a..86a585c9 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -25,8 +25,6 @@ class QPDF_Stream: public QPDFObject void replaceStreamData(PointerHolder data, QPDFObjectHandle filter, QPDFObjectHandle decode_parms); - void replaceStreamData( - PointerHolder dh); private: bool filterable(std::vector& filters, @@ -38,7 +36,6 @@ class QPDF_Stream: public QPDFObject QPDFObjectHandle stream_dict; off_t offset; int length; - PointerHolder stream_data_handler; PointerHolder stream_data; }; diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 54f22f1a..c90fcba4 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -174,3 +174,5 @@ QPDF ERR object stream with wrong type 0 QPDF object gone after xref reconstruction 0 qpdf-c called qpdf_has_error 0 qpdf-c called qpdf_get_qpdf_version 0 +QPDF_Stream pipe original stream data 0 +QPDF_Stream pipe replaced stream data 0 -- cgit v1.2.3-54-g00ecf