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