Commit 9c00874e7786fa38e15e9a4ddf9767b63e88386d

Authored by Tobias Hoffmann
1 parent b04fb5cf

added QPDFObjectHandle::replaceStreamData(std::string data).

include/qpdf/QPDFObjectHandle.hh
@@ -363,6 +363,15 @@ class QPDFObjectHandle @@ -363,6 +363,15 @@ class QPDFObjectHandle
363 QPDFObjectHandle const& filter, 363 QPDFObjectHandle const& filter,
364 QPDFObjectHandle const& decode_parms); 364 QPDFObjectHandle const& decode_parms);
365 365
  366 + // Replace the stream's stream data with the given string.
  367 + // This method will create a copy of the data rather than using
  368 + // the user-provided buffer as in the PointerHolder<Buffer> version
  369 + // of replaceStreamData.
  370 + QPDF_DLL
  371 + void replaceStreamData(std::string const& data,
  372 + QPDFObjectHandle const& filter,
  373 + QPDFObjectHandle const& decode_parms);
  374 +
366 // As above, replace this stream's stream data. Instead of 375 // As above, replace this stream's stream data. Instead of
367 // directly providing a buffer with the stream data, call the 376 // directly providing a buffer with the stream data, call the
368 // given provider's provideStreamData method. See comments on the 377 // given provider's provideStreamData method. See comments on the
libqpdf/QPDFObjectHandle.cc
@@ -442,6 +442,19 @@ QPDFObjectHandle::replaceStreamData(PointerHolder&lt;Buffer&gt; data, @@ -442,6 +442,19 @@ QPDFObjectHandle::replaceStreamData(PointerHolder&lt;Buffer&gt; data,
442 } 442 }
443 443
444 void 444 void
  445 +QPDFObjectHandle::replaceStreamData(std::string const& data,
  446 + QPDFObjectHandle const& filter,
  447 + QPDFObjectHandle const& decode_parms)
  448 +{
  449 + assertStream();
  450 + PointerHolder<Buffer> b = new Buffer(data.length());
  451 + unsigned char* bp = b->getBuffer();
  452 + memcpy(bp, (char*)data.c_str(), data.length());
  453 + dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData(
  454 + b, filter, decode_parms);
  455 +}
  456 +
  457 +void
445 QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider, 458 QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider,
446 QPDFObjectHandle const& filter, 459 QPDFObjectHandle const& filter,
447 QPDFObjectHandle const& decode_parms) 460 QPDFObjectHandle const& decode_parms)
@@ -978,10 +991,9 @@ QPDFObjectHandle @@ -978,10 +991,9 @@ QPDFObjectHandle
978 QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data) 991 QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data)
979 { 992 {
980 QTC::TC("qpdf", "QPDFObjectHandle newStream with string"); 993 QTC::TC("qpdf", "QPDFObjectHandle newStream with string");
981 - PointerHolder<Buffer> b = new Buffer(data.length());  
982 - unsigned char* bp = b->getBuffer();  
983 - memcpy(bp, (char*)data.c_str(), data.length());  
984 - return QPDFObjectHandle::newStream(qpdf, b); 994 + QPDFObjectHandle result = newStream(qpdf);
  995 + result.replaceStreamData(data, newNull(), newNull());
  996 + return result;
985 } 997 }
986 998
987 QPDFObjectHandle 999 QPDFObjectHandle