Commit 998a6cbee911ee8d49b2ce2f24e0cb4898289492

Authored by Jay Berkenbilt
1 parent 9a06fc54

remove stream_data_handler; it wouldn't work as designed. replacement data imple…

…mented but not tested

git-svn-id: svn+q:///qpdf/trunk@988 71b93d88-0707-0410-a8cf-f5a4172ac649
... ... @@ -25,6 +25,9 @@ Next
25 25 QPDF_Stream.cc carefully line by line to make sure everything is
26 26 adjusted properly.
27 27  
  28 + Don't forget to provide a method that provides a pipeline through
  29 + which the stream data is to be piped.
  30 +
28 31 * Add helper routines for manipulating page content streams.
29 32 Operations should include ability to convert page contents from a
30 33 stream to an array of streams and to append or prepend to the page
... ...
include/qpdf/QPDFObjectHandle.hh
... ... @@ -197,52 +197,6 @@ class QPDFObjectHandle
197 197 void replaceStreamData(PointerHolder<Buffer> data,
198 198 QPDFObjectHandle filter,
199 199 QPDFObjectHandle decode_parms);
200   - class StreamDataHandler
201   - {
202   - public:
203   - QPDF_DLL
204   - virtual ~StreamDataHandler()
205   - {
206   - }
207   -
208   - // See replaceStreamData(StreamDataHandler) below for a
209   - // description of how to override this function.
210   - virtual void
211   - replaceStreamData(Buffer const& in_data,
212   - std::string const& in_filter,
213   - std::string const& in_decode_parms,
214   - bool filtered,
215   - Buffer& out_data,
216   - std::string& out_filter,
217   - std::string& out_decode_parms,
218   - bool& persist) = 0;
219   - };
220   - // Provide a hook for doing dynamic replacement of the stream's
221   - // data. When the stream's data is accessed either with
222   - // pipeStreamData or with getStreamData, if the stream doesn't
223   - // already have replacement data, an attempt is first made to
224   - // filter the stream's original data. If the attempt is
225   - // successful, the stream's filtered original data is passed to
226   - // the handler as in_data, and filtered is true. If the original
227   - // data cannot be processed, then in_data is the original raw data
228   - // (after any decryption filters have been applied) and filtered
229   - // is false. If the original input data has no filters applied,
230   - // the filtered is true. This way, if filtered is true, the
231   - // caller knows that in_data contains the fully filtered data.
232   - // The handler then provides replacement data, /Filter, and
233   - // /DecodeParms (handled is in the simpler form of
234   - // replaceStreamData above). If the persist argument is set to
235   - // true, then the replacement data is stored in the stream object
236   - // where it will be used on subsequent attempts to retrieve the
237   - // data (rather than calling the handler). If persist is set to
238   - // false, then the data will be used that one time and not saved.
239   - // In that case, the handler will be invoked again if the stream
240   - // data is accessed another time. Writing a handler that sets
241   - // persist to true essentially allows delaying the computation of
242   - // the stream data, while setting it to false reduces the amount
243   - // of memory that is used.
244   - QPDF_DLL
245   - void replaceStreamData(PointerHolder<StreamDataHandler> dh);
246 200  
247 201 // return 0 for direct objects
248 202 QPDF_DLL
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -362,13 +362,6 @@ QPDFObjectHandle::replaceStreamData(PointerHolder&lt;Buffer&gt; data,
362 362 data, filter, decode_parms);
363 363 }
364 364  
365   -void
366   -QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataHandler> dh)
367   -{
368   - assertType("Stream", isStream());
369   - dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData(dh);
370   -}
371   -
372 365 int
373 366 QPDFObjectHandle::getObjectID() const
374 367 {
... ...
libqpdf/QPDF_Stream.cc
... ... @@ -319,10 +319,20 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
319 319 }
320 320 }
321 321  
322   - // XXX handle stream_data and stream_data_handler
323   - QPDF::Pipe::pipeStreamData(this->qpdf, this->objid, this->generation,
324   - this->offset, this->length,
325   - this->stream_dict, pipeline);
  322 + if (this->stream_data.getPointer())
  323 + {
  324 + QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data");
  325 + Buffer& b = *(this->stream_data.getPointer());
  326 + pipeline->write(b.getBuffer(), b.getSize());
  327 + pipeline->finish();
  328 + }
  329 + else
  330 + {
  331 + QTC::TC("qpdf", "QPDF_Stream pipe original stream data");
  332 + QPDF::Pipe::pipeStreamData(this->qpdf, this->objid, this->generation,
  333 + this->offset, this->length,
  334 + this->stream_dict, pipeline);
  335 + }
326 336  
327 337 return filter;
328 338 }
... ... @@ -339,10 +349,3 @@ QPDF_Stream::replaceStreamData(PointerHolder&lt;Buffer&gt; data,
339 349 QPDFObjectHandle::newInteger(
340 350 data.getPointer()->getSize()));
341 351 }
342   -
343   -void
344   -QPDF_Stream::replaceStreamData(
345   - PointerHolder<QPDFObjectHandle::StreamDataHandler> dh)
346   -{
347   - this->stream_data_handler = dh;
348   -}
... ...
libqpdf/qpdf/QPDF_Stream.hh
... ... @@ -25,8 +25,6 @@ class QPDF_Stream: public QPDFObject
25 25 void replaceStreamData(PointerHolder<Buffer> data,
26 26 QPDFObjectHandle filter,
27 27 QPDFObjectHandle decode_parms);
28   - void replaceStreamData(
29   - PointerHolder<QPDFObjectHandle::StreamDataHandler> dh);
30 28  
31 29 private:
32 30 bool filterable(std::vector<std::string>& filters,
... ... @@ -38,7 +36,6 @@ class QPDF_Stream: public QPDFObject
38 36 QPDFObjectHandle stream_dict;
39 37 off_t offset;
40 38 int length;
41   - PointerHolder<QPDFObjectHandle::StreamDataHandler> stream_data_handler;
42 39 PointerHolder<Buffer> stream_data;
43 40 };
44 41  
... ...
qpdf/qpdf.testcov
... ... @@ -174,3 +174,5 @@ QPDF ERR object stream with wrong type 0
174 174 QPDF object gone after xref reconstruction 0
175 175 qpdf-c called qpdf_has_error 0
176 176 qpdf-c called qpdf_get_qpdf_version 0
  177 +QPDF_Stream pipe original stream data 0
  178 +QPDF_Stream pipe replaced stream data 0
... ...