Commit afd35f9a30e35011e82fef45b65cfae702a006a4
1 parent
5d0469f1
Overload StreamDataProvider::provideStreamData
Use 'QPDFObjGen const&' instead of 'int, int' in signature.
Showing
11 changed files
with
50 additions
and
38 deletions
examples/pdf-create.cc
| @@ -29,8 +29,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider | @@ -29,8 +29,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider | ||
| 29 | public: | 29 | public: |
| 30 | ImageProvider(std::string const& color_space, std::string const& filter); | 30 | ImageProvider(std::string const& color_space, std::string const& filter); |
| 31 | virtual ~ImageProvider() = default; | 31 | virtual ~ImageProvider() = default; |
| 32 | - virtual void | ||
| 33 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 32 | + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); |
| 34 | size_t getWidth() const; | 33 | size_t getWidth() const; |
| 35 | size_t getHeight() const; | 34 | size_t getHeight() const; |
| 36 | 35 | ||
| @@ -93,7 +92,7 @@ ImageProvider::getHeight() const | @@ -93,7 +92,7 @@ ImageProvider::getHeight() const | ||
| 93 | } | 92 | } |
| 94 | 93 | ||
| 95 | void | 94 | void |
| 96 | -ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) | 95 | +ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) |
| 97 | { | 96 | { |
| 98 | std::vector<std::shared_ptr<Pipeline>> to_delete; | 97 | std::vector<std::shared_ptr<Pipeline>> to_delete; |
| 99 | Pipeline* p = pipeline; | 98 | Pipeline* p = pipeline; |
| @@ -292,7 +291,7 @@ check( | @@ -292,7 +291,7 @@ check( | ||
| 292 | ImageProvider* p = new ImageProvider(desired_color_space, "null"); | 291 | ImageProvider* p = new ImageProvider(desired_color_space, "null"); |
| 293 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); | 292 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); |
| 294 | Pl_Buffer b_p("get image data"); | 293 | Pl_Buffer b_p("get image data"); |
| 295 | - provider->provideStreamData(0, 0, &b_p); | 294 | + provider->provideStreamData(QPDFObjGen(), &b_p); |
| 296 | std::shared_ptr<Buffer> desired_data(b_p.getBuffer()); | 295 | std::shared_ptr<Buffer> desired_data(b_p.getBuffer()); |
| 297 | 296 | ||
| 298 | if (desired_data->getSize() != actual_data->getSize()) { | 297 | if (desired_data->getSize() != actual_data->getSize()) { |
examples/pdf-custom-filter.cc
| @@ -201,7 +201,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider | @@ -201,7 +201,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider | ||
| 201 | StreamReplacer(QPDF* pdf); | 201 | StreamReplacer(QPDF* pdf); |
| 202 | virtual ~StreamReplacer() = default; | 202 | virtual ~StreamReplacer() = default; |
| 203 | virtual void | 203 | virtual void |
| 204 | - provideStreamData(int objid, int generation, Pipeline* pipeline) override; | 204 | + provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; |
| 205 | 205 | ||
| 206 | void registerStream( | 206 | void registerStream( |
| 207 | QPDFObjectHandle stream, | 207 | QPDFObjectHandle stream, |
| @@ -384,9 +384,8 @@ StreamReplacer::registerStream( | @@ -384,9 +384,8 @@ StreamReplacer::registerStream( | ||
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | void | 386 | void |
| 387 | -StreamReplacer::provideStreamData(int objid, int generation, Pipeline* pipeline) | 387 | +StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) |
| 388 | { | 388 | { |
| 389 | - QPDFObjGen og(objid, generation); | ||
| 390 | QPDFObjectHandle orig = this->copied_streams[og]; | 389 | QPDFObjectHandle orig = this->copied_streams[og]; |
| 391 | // call maybeReplace again, this time with the pipeline and no | 390 | // call maybeReplace again, this time with the pipeline and no |
| 392 | // dict_updates. In this mode, maybeReplace doesn't make any | 391 | // dict_updates. In this mode, maybeReplace doesn't make any |
examples/pdf-invert-images.cc
| @@ -35,7 +35,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider | @@ -35,7 +35,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider | ||
| 35 | public: | 35 | public: |
| 36 | virtual ~ImageInverter() = default; | 36 | virtual ~ImageInverter() = default; |
| 37 | virtual void | 37 | virtual void |
| 38 | - provideStreamData(int objid, int generation, Pipeline* pipeline) override; | 38 | + provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; |
| 39 | 39 | ||
| 40 | void registerImage( | 40 | void registerImage( |
| 41 | QPDFObjectHandle image, | 41 | QPDFObjectHandle image, |
| @@ -82,12 +82,11 @@ ImageInverter::registerImage( | @@ -82,12 +82,11 @@ ImageInverter::registerImage( | ||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | void | 84 | void |
| 85 | -ImageInverter::provideStreamData(int objid, int generation, Pipeline* pipeline) | 85 | +ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) |
| 86 | { | 86 | { |
| 87 | // Use the object and generation number supplied to look up the | 87 | // Use the object and generation number supplied to look up the |
| 88 | // image data. Then invert the image data and write the inverted | 88 | // image data. Then invert the image data and write the inverted |
| 89 | // data to the pipeline. | 89 | // data to the pipeline. |
| 90 | - QPDFObjGen og(objid, generation); | ||
| 91 | std::shared_ptr<Buffer> data = | 90 | std::shared_ptr<Buffer> data = |
| 92 | this->copied_images[og].getStreamData(qpdf_dl_all); | 91 | this->copied_images[og].getStreamData(qpdf_dl_all); |
| 93 | size_t size = data->getSize(); | 92 | size_t size = data->getSize(); |
include/qpdf/QPDF.hh
| @@ -990,8 +990,7 @@ class QPDF | @@ -990,8 +990,7 @@ class QPDF | ||
| 990 | CopiedStreamDataProvider(QPDF& destination_qpdf); | 990 | CopiedStreamDataProvider(QPDF& destination_qpdf); |
| 991 | virtual ~CopiedStreamDataProvider() = default; | 991 | virtual ~CopiedStreamDataProvider() = default; |
| 992 | virtual bool provideStreamData( | 992 | virtual bool provideStreamData( |
| 993 | - int objid, | ||
| 994 | - int generation, | 993 | + QPDFObjGen const& og, |
| 995 | Pipeline* pipeline, | 994 | Pipeline* pipeline, |
| 996 | bool suppress_warnings, | 995 | bool suppress_warnings, |
| 997 | bool will_retry) override; | 996 | bool will_retry) override; |
include/qpdf/QPDFObjectHandle.hh
| @@ -116,9 +116,17 @@ class QPDFObjectHandle | @@ -116,9 +116,17 @@ class QPDFObjectHandle | ||
| 116 | // indicating whether it ran without errors. | 116 | // indicating whether it ran without errors. |
| 117 | QPDF_DLL | 117 | QPDF_DLL |
| 118 | virtual void | 118 | virtual void |
| 119 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 119 | + provideStreamData(QPDFObjGen const& og, Pipeline* pipeline); |
| 120 | QPDF_DLL | 120 | QPDF_DLL |
| 121 | virtual bool provideStreamData( | 121 | virtual bool provideStreamData( |
| 122 | + QPDFObjGen const& og, | ||
| 123 | + Pipeline* pipeline, | ||
| 124 | + bool suppress_warnings, | ||
| 125 | + bool will_retry); | ||
| 126 | + // The following two overloads are deprecated. | ||
| 127 | + QPDF_DLL virtual void | ||
| 128 | + provideStreamData(int objid, int generation, Pipeline* pipeline); | ||
| 129 | + QPDF_DLL virtual bool provideStreamData( | ||
| 122 | int objid, | 130 | int objid, |
| 123 | int generation, | 131 | int generation, |
| 124 | Pipeline* pipeline, | 132 | Pipeline* pipeline, |
libqpdf/QPDF.cc
| @@ -135,22 +135,19 @@ QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider( | @@ -135,22 +135,19 @@ QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider( | ||
| 135 | 135 | ||
| 136 | bool | 136 | bool |
| 137 | QPDF::CopiedStreamDataProvider::provideStreamData( | 137 | QPDF::CopiedStreamDataProvider::provideStreamData( |
| 138 | - int objid, | ||
| 139 | - int generation, | 138 | + QPDFObjGen const& og, |
| 140 | Pipeline* pipeline, | 139 | Pipeline* pipeline, |
| 141 | bool suppress_warnings, | 140 | bool suppress_warnings, |
| 142 | bool will_retry) | 141 | bool will_retry) |
| 143 | { | 142 | { |
| 144 | - std::shared_ptr<ForeignStreamData> foreign_data = | ||
| 145 | - this->foreign_stream_data[QPDFObjGen(objid, generation)]; | 143 | + std::shared_ptr<ForeignStreamData> foreign_data = foreign_stream_data[og]; |
| 146 | bool result = false; | 144 | bool result = false; |
| 147 | if (foreign_data.get()) { | 145 | if (foreign_data.get()) { |
| 148 | result = destination_qpdf.pipeForeignStreamData( | 146 | result = destination_qpdf.pipeForeignStreamData( |
| 149 | foreign_data, pipeline, suppress_warnings, will_retry); | 147 | foreign_data, pipeline, suppress_warnings, will_retry); |
| 150 | QTC::TC("qpdf", "QPDF copy foreign with data", result ? 0 : 1); | 148 | QTC::TC("qpdf", "QPDF copy foreign with data", result ? 0 : 1); |
| 151 | } else { | 149 | } else { |
| 152 | - QPDFObjectHandle foreign_stream = | ||
| 153 | - this->foreign_streams[QPDFObjGen(objid, generation)]; | 150 | + auto foreign_stream = foreign_streams[og]; |
| 154 | result = foreign_stream.pipeStreamData( | 151 | result = foreign_stream.pipeStreamData( |
| 155 | pipeline, nullptr, 0, qpdf_dl_none, suppress_warnings, will_retry); | 152 | pipeline, nullptr, 0, qpdf_dl_none, suppress_warnings, will_retry); |
| 156 | QTC::TC( | 153 | QTC::TC( |
libqpdf/QPDFJob.cc
| @@ -49,8 +49,7 @@ namespace | @@ -49,8 +49,7 @@ namespace | ||
| 49 | size_t oi_min_area, | 49 | size_t oi_min_area, |
| 50 | QPDFObjectHandle& image); | 50 | QPDFObjectHandle& image); |
| 51 | virtual ~ImageOptimizer() = default; | 51 | virtual ~ImageOptimizer() = default; |
| 52 | - virtual void | ||
| 53 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 52 | + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); |
| 54 | std::shared_ptr<Pipeline> | 53 | std::shared_ptr<Pipeline> |
| 55 | makePipeline(std::string const& description, Pipeline* next); | 54 | makePipeline(std::string const& description, Pipeline* next); |
| 56 | bool evaluate(std::string const& description); | 55 | bool evaluate(std::string const& description); |
| @@ -250,7 +249,7 @@ ImageOptimizer::evaluate(std::string const& description) | @@ -250,7 +249,7 @@ ImageOptimizer::evaluate(std::string const& description) | ||
| 250 | } | 249 | } |
| 251 | 250 | ||
| 252 | void | 251 | void |
| 253 | -ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) | 252 | +ImageOptimizer::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) |
| 254 | { | 253 | { |
| 255 | std::shared_ptr<Pipeline> p = makePipeline("", pipeline); | 254 | std::shared_ptr<Pipeline> p = makePipeline("", pipeline); |
| 256 | if (p.get() == nullptr) { | 255 | if (p.get() == nullptr) { |
libqpdf/QPDFObjectHandle.cc
| @@ -53,6 +53,24 @@ QPDFObjectHandle::StreamDataProvider::~StreamDataProvider() | @@ -53,6 +53,24 @@ QPDFObjectHandle::StreamDataProvider::~StreamDataProvider() | ||
| 53 | 53 | ||
| 54 | void | 54 | void |
| 55 | QPDFObjectHandle::StreamDataProvider::provideStreamData( | 55 | QPDFObjectHandle::StreamDataProvider::provideStreamData( |
| 56 | + QPDFObjGen const& og, Pipeline* pipeline) | ||
| 57 | +{ | ||
| 58 | + return provideStreamData(og.getObj(), og.getGen(), pipeline); | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +bool | ||
| 62 | +QPDFObjectHandle::StreamDataProvider::provideStreamData( | ||
| 63 | + QPDFObjGen const& og, | ||
| 64 | + Pipeline* pipeline, | ||
| 65 | + bool suppress_warnings, | ||
| 66 | + bool will_retry) | ||
| 67 | +{ | ||
| 68 | + return provideStreamData( | ||
| 69 | + og.getObj(), og.getGen(), pipeline, suppress_warnings, will_retry); | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +void | ||
| 73 | +QPDFObjectHandle::StreamDataProvider::provideStreamData( | ||
| 56 | int objid, int generation, Pipeline* pipeline) | 74 | int objid, int generation, Pipeline* pipeline) |
| 57 | { | 75 | { |
| 58 | throw std::logic_error( | 76 | throw std::logic_error( |
| @@ -90,8 +108,7 @@ namespace | @@ -90,8 +108,7 @@ namespace | ||
| 90 | { | 108 | { |
| 91 | } | 109 | } |
| 92 | virtual ~CoalesceProvider() = default; | 110 | virtual ~CoalesceProvider() = default; |
| 93 | - virtual void | ||
| 94 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 111 | + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); |
| 95 | 112 | ||
| 96 | private: | 113 | private: |
| 97 | QPDFObjectHandle containing_page; | 114 | QPDFObjectHandle containing_page; |
| @@ -100,7 +117,7 @@ namespace | @@ -100,7 +117,7 @@ namespace | ||
| 100 | } // namespace | 117 | } // namespace |
| 101 | 118 | ||
| 102 | void | 119 | void |
| 103 | -CoalesceProvider::provideStreamData(int, int, Pipeline* p) | 120 | +CoalesceProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) |
| 104 | { | 121 | { |
| 105 | QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); | 122 | QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); |
| 106 | std::string description = | 123 | std::string description = |
| @@ -1425,15 +1442,14 @@ namespace | @@ -1425,15 +1442,14 @@ namespace | ||
| 1425 | } | 1442 | } |
| 1426 | 1443 | ||
| 1427 | virtual void | 1444 | virtual void |
| 1428 | - provideStreamData(int, int, Pipeline* pipeline) override | 1445 | + provideStreamData(QPDFObjGen const&, Pipeline* pipeline) override |
| 1429 | { | 1446 | { |
| 1430 | p1(pipeline); | 1447 | p1(pipeline); |
| 1431 | } | 1448 | } |
| 1432 | 1449 | ||
| 1433 | virtual bool | 1450 | virtual bool |
| 1434 | provideStreamData( | 1451 | provideStreamData( |
| 1435 | - int, | ||
| 1436 | - int, | 1452 | + QPDFObjGen const&, |
| 1437 | Pipeline* pipeline, | 1453 | Pipeline* pipeline, |
| 1438 | bool suppress_warnings, | 1454 | bool suppress_warnings, |
| 1439 | bool will_retry) override | 1455 | bool will_retry) override |
libqpdf/QPDFPageObjectHelper.cc
| @@ -21,8 +21,7 @@ namespace | @@ -21,8 +21,7 @@ namespace | ||
| 21 | { | 21 | { |
| 22 | } | 22 | } |
| 23 | virtual ~ContentProvider() = default; | 23 | virtual ~ContentProvider() = default; |
| 24 | - virtual void | ||
| 25 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 24 | + virtual void provideStreamData(QPDFObjGen const&, Pipeline* pipeline); |
| 26 | 25 | ||
| 27 | private: | 26 | private: |
| 28 | QPDFObjectHandle from_page; | 27 | QPDFObjectHandle from_page; |
| @@ -30,7 +29,7 @@ namespace | @@ -30,7 +29,7 @@ namespace | ||
| 30 | } // namespace | 29 | } // namespace |
| 31 | 30 | ||
| 32 | void | 31 | void |
| 33 | -ContentProvider::provideStreamData(int, int, Pipeline* p) | 32 | +ContentProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) |
| 34 | { | 33 | { |
| 35 | Pl_Concatenate concat("concatenate", p); | 34 | Pl_Concatenate concat("concatenate", p); |
| 36 | std::string description = | 35 | std::string description = |
libqpdf/QPDF_Stream.cc
| @@ -610,17 +610,12 @@ QPDF_Stream::pipeStreamData( | @@ -610,17 +610,12 @@ QPDF_Stream::pipeStreamData( | ||
| 610 | Pl_Count count("stream provider count", pipeline); | 610 | Pl_Count count("stream provider count", pipeline); |
| 611 | if (this->stream_provider->supportsRetry()) { | 611 | if (this->stream_provider->supportsRetry()) { |
| 612 | if (!this->stream_provider->provideStreamData( | 612 | if (!this->stream_provider->provideStreamData( |
| 613 | - og.getObj(), | ||
| 614 | - og.getGen(), | ||
| 615 | - &count, | ||
| 616 | - suppress_warnings, | ||
| 617 | - will_retry)) { | 613 | + og, &count, suppress_warnings, will_retry)) { |
| 618 | filter = false; | 614 | filter = false; |
| 619 | success = false; | 615 | success = false; |
| 620 | } | 616 | } |
| 621 | } else { | 617 | } else { |
| 622 | - this->stream_provider->provideStreamData( | ||
| 623 | - og.getObj(), og.getGen(), &count); | 618 | + this->stream_provider->provideStreamData(og, &count); |
| 624 | } | 619 | } |
| 625 | qpdf_offset_t actual_length = count.getCount(); | 620 | qpdf_offset_t actual_length = count.getCount(); |
| 626 | qpdf_offset_t desired_length = 0; | 621 | qpdf_offset_t desired_length = 0; |
qpdf/test_driver.cc
| @@ -56,6 +56,8 @@ class Provider: public QPDFObjectHandle::StreamDataProvider | @@ -56,6 +56,8 @@ class Provider: public QPDFObjectHandle::StreamDataProvider | ||
| 56 | virtual void | 56 | virtual void |
| 57 | provideStreamData(int objid, int generation, Pipeline* p) | 57 | provideStreamData(int objid, int generation, Pipeline* p) |
| 58 | { | 58 | { |
| 59 | + // Don't change signature to use QPDFObjGen const& to detect | ||
| 60 | + // problems forwarding to legacy implementations. | ||
| 59 | p->write(b->getBuffer(), b->getSize()); | 61 | p->write(b->getBuffer(), b->getSize()); |
| 60 | if (this->bad_length) { | 62 | if (this->bad_length) { |
| 61 | unsigned char ch = ' '; | 63 | unsigned char ch = ' '; |