From afd35f9a30e35011e82fef45b65cfae702a006a4 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 24 Jul 2022 14:16:37 +0100 Subject: Overload StreamDataProvider::provideStreamData Use 'QPDFObjGen const&' instead of 'int, int' in signature. --- examples/pdf-create.cc | 7 +++---- examples/pdf-custom-filter.cc | 5 ++--- examples/pdf-invert-images.cc | 5 ++--- include/qpdf/QPDF.hh | 3 +-- include/qpdf/QPDFObjectHandle.hh | 10 +++++++++- libqpdf/QPDF.cc | 9 +++------ libqpdf/QPDFJob.cc | 5 ++--- libqpdf/QPDFObjectHandle.cc | 28 ++++++++++++++++++++++------ libqpdf/QPDFPageObjectHelper.cc | 5 ++--- libqpdf/QPDF_Stream.cc | 9 ++------- qpdf/test_driver.cc | 2 ++ 11 files changed, 50 insertions(+), 38 deletions(-) diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index 5e9e4239..785021da 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -29,8 +29,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider public: ImageProvider(std::string const& color_space, std::string const& filter); virtual ~ImageProvider() = default; - virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline); + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); size_t getWidth() const; size_t getHeight() const; @@ -93,7 +92,7 @@ ImageProvider::getHeight() const } void -ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) +ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) { std::vector> to_delete; Pipeline* p = pipeline; @@ -292,7 +291,7 @@ check( ImageProvider* p = new ImageProvider(desired_color_space, "null"); std::shared_ptr provider(p); Pl_Buffer b_p("get image data"); - provider->provideStreamData(0, 0, &b_p); + provider->provideStreamData(QPDFObjGen(), &b_p); std::shared_ptr desired_data(b_p.getBuffer()); if (desired_data->getSize() != actual_data->getSize()) { diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc index ede4a19c..e7877bea 100644 --- a/examples/pdf-custom-filter.cc +++ b/examples/pdf-custom-filter.cc @@ -201,7 +201,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider StreamReplacer(QPDF* pdf); virtual ~StreamReplacer() = default; virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline) override; + provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; void registerStream( QPDFObjectHandle stream, @@ -384,9 +384,8 @@ StreamReplacer::registerStream( } void -StreamReplacer::provideStreamData(int objid, int generation, Pipeline* pipeline) +StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) { - QPDFObjGen og(objid, generation); QPDFObjectHandle orig = this->copied_streams[og]; // call maybeReplace again, this time with the pipeline and no // dict_updates. In this mode, maybeReplace doesn't make any diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc index 2c9a88e7..94392ac3 100644 --- a/examples/pdf-invert-images.cc +++ b/examples/pdf-invert-images.cc @@ -35,7 +35,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider public: virtual ~ImageInverter() = default; virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline) override; + provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; void registerImage( QPDFObjectHandle image, @@ -82,12 +82,11 @@ ImageInverter::registerImage( } void -ImageInverter::provideStreamData(int objid, int generation, Pipeline* pipeline) +ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) { // Use the object and generation number supplied to look up the // image data. Then invert the image data and write the inverted // data to the pipeline. - QPDFObjGen og(objid, generation); std::shared_ptr data = this->copied_images[og].getStreamData(qpdf_dl_all); size_t size = data->getSize(); diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index ae5c89e2..a80ddcd5 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -990,8 +990,7 @@ class QPDF CopiedStreamDataProvider(QPDF& destination_qpdf); virtual ~CopiedStreamDataProvider() = default; virtual bool provideStreamData( - int objid, - int generation, + QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry) override; diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 68fc78f8..8e33085c 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -116,9 +116,17 @@ class QPDFObjectHandle // indicating whether it ran without errors. QPDF_DLL virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline); + provideStreamData(QPDFObjGen const& og, Pipeline* pipeline); QPDF_DLL virtual bool provideStreamData( + QPDFObjGen const& og, + Pipeline* pipeline, + bool suppress_warnings, + bool will_retry); + // The following two overloads are deprecated. + QPDF_DLL virtual void + provideStreamData(int objid, int generation, Pipeline* pipeline); + QPDF_DLL virtual bool provideStreamData( int objid, int generation, Pipeline* pipeline, diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index a24c17e6..a64096a2 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -135,22 +135,19 @@ QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider( bool QPDF::CopiedStreamDataProvider::provideStreamData( - int objid, - int generation, + QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry) { - std::shared_ptr foreign_data = - this->foreign_stream_data[QPDFObjGen(objid, generation)]; + std::shared_ptr foreign_data = foreign_stream_data[og]; bool result = false; if (foreign_data.get()) { result = destination_qpdf.pipeForeignStreamData( foreign_data, pipeline, suppress_warnings, will_retry); QTC::TC("qpdf", "QPDF copy foreign with data", result ? 0 : 1); } else { - QPDFObjectHandle foreign_stream = - this->foreign_streams[QPDFObjGen(objid, generation)]; + auto foreign_stream = foreign_streams[og]; result = foreign_stream.pipeStreamData( pipeline, nullptr, 0, qpdf_dl_none, suppress_warnings, will_retry); QTC::TC( diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 617d6b80..343fa348 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -49,8 +49,7 @@ namespace size_t oi_min_area, QPDFObjectHandle& image); virtual ~ImageOptimizer() = default; - virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline); + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); std::shared_ptr makePipeline(std::string const& description, Pipeline* next); bool evaluate(std::string const& description); @@ -250,7 +249,7 @@ ImageOptimizer::evaluate(std::string const& description) } void -ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) +ImageOptimizer::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) { std::shared_ptr p = makePipeline("", pipeline); if (p.get() == nullptr) { diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index e883dcd0..753493ec 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -51,6 +51,24 @@ QPDFObjectHandle::StreamDataProvider::~StreamDataProvider() // README-maintainer } +void +QPDFObjectHandle::StreamDataProvider::provideStreamData( + QPDFObjGen const& og, Pipeline* pipeline) +{ + return provideStreamData(og.getObj(), og.getGen(), pipeline); +} + +bool +QPDFObjectHandle::StreamDataProvider::provideStreamData( + QPDFObjGen const& og, + Pipeline* pipeline, + bool suppress_warnings, + bool will_retry) +{ + return provideStreamData( + og.getObj(), og.getGen(), pipeline, suppress_warnings, will_retry); +} + void QPDFObjectHandle::StreamDataProvider::provideStreamData( int objid, int generation, Pipeline* pipeline) @@ -90,8 +108,7 @@ namespace { } virtual ~CoalesceProvider() = default; - virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline); + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); private: QPDFObjectHandle containing_page; @@ -100,7 +117,7 @@ namespace } // namespace void -CoalesceProvider::provideStreamData(int, int, Pipeline* p) +CoalesceProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) { QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); std::string description = @@ -1425,15 +1442,14 @@ namespace } virtual void - provideStreamData(int, int, Pipeline* pipeline) override + provideStreamData(QPDFObjGen const&, Pipeline* pipeline) override { p1(pipeline); } virtual bool provideStreamData( - int, - int, + QPDFObjGen const&, Pipeline* pipeline, bool suppress_warnings, bool will_retry) override diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index 16ab346f..96a8ce69 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -21,8 +21,7 @@ namespace { } virtual ~ContentProvider() = default; - virtual void - provideStreamData(int objid, int generation, Pipeline* pipeline); + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); private: QPDFObjectHandle from_page; @@ -30,7 +29,7 @@ namespace } // namespace void -ContentProvider::provideStreamData(int, int, Pipeline* p) +ContentProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) { Pl_Concatenate concat("concatenate", p); std::string description = diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index aed9370d..84965102 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -610,17 +610,12 @@ QPDF_Stream::pipeStreamData( Pl_Count count("stream provider count", pipeline); if (this->stream_provider->supportsRetry()) { if (!this->stream_provider->provideStreamData( - og.getObj(), - og.getGen(), - &count, - suppress_warnings, - will_retry)) { + og, &count, suppress_warnings, will_retry)) { filter = false; success = false; } } else { - this->stream_provider->provideStreamData( - og.getObj(), og.getGen(), &count); + this->stream_provider->provideStreamData(og, &count); } qpdf_offset_t actual_length = count.getCount(); qpdf_offset_t desired_length = 0; diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 0eb6ed8d..f1c1d72a 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -56,6 +56,8 @@ class Provider: public QPDFObjectHandle::StreamDataProvider virtual void provideStreamData(int objid, int generation, Pipeline* p) { + // Don't change signature to use QPDFObjGen const& to detect + // problems forwarding to legacy implementations. p->write(b->getBuffer(), b->getSize()); if (this->bad_length) { unsigned char ch = ' '; -- cgit v1.2.3-54-g00ecf