Commit 80631cb00d32d2e1ebd9f7fba8997d82c4c48559
1 parent
876c238e
Enhance pl::Count to incorporate an end-of-line Pl_String
Showing
3 changed files
with
27 additions
and
11 deletions
include/qpdf/QPDFWriter.hh
| ... | ... | @@ -597,12 +597,14 @@ class QPDFWriter |
| 597 | 597 | // activate the pipeline stack. When the passed in PipelinePopper goes out of scope, the stack |
| 598 | 598 | // is popped. |
| 599 | 599 | Pipeline* pushPipeline(Pipeline*); |
| 600 | - void activatePipelineStack(PipelinePopper& pp, bool discard = false); | |
| 600 | + void | |
| 601 | + activatePipelineStack(PipelinePopper& pp, bool discard = false, std::string* str = nullptr); | |
| 601 | 602 | void initializePipelineStack(Pipeline*); |
| 602 | 603 | |
| 603 | 604 | void adjustAESStreamLength(size_t& length); |
| 604 | 605 | void pushEncryptionFilter(PipelinePopper&); |
| 605 | 606 | void pushDiscardFilter(PipelinePopper&); |
| 607 | + void pushStringPipeline(PipelinePopper&, std::string& str); | |
| 606 | 608 | void pushMD5Pipeline(PipelinePopper&); |
| 607 | 609 | void computeDeterministicIDData(); |
| 608 | 610 | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -917,10 +917,11 @@ QPDFWriter::initializePipelineStack(Pipeline* p) |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | void |
| 920 | -QPDFWriter::activatePipelineStack(PipelinePopper& pp, bool discard) | |
| 920 | +QPDFWriter::activatePipelineStack(PipelinePopper& pp, bool discard, std::string* str) | |
| 921 | 921 | { |
| 922 | 922 | std::string stack_id("stack " + std::to_string(m->next_stack_id)); |
| 923 | - auto* c = new pl::Count(stack_id.c_str(), discard ? nullptr : m->pipeline_stack.back()); | |
| 923 | + auto* c = str ? new pl::Count(stack_id.c_str(), str) | |
| 924 | + : new pl::Count(stack_id.c_str(), discard ? nullptr : m->pipeline_stack.back()); | |
| 924 | 925 | ++m->next_stack_id; |
| 925 | 926 | m->pipeline_stack.emplace_back(c); |
| 926 | 927 | m->pipeline = c; |
| ... | ... | @@ -996,6 +997,12 @@ QPDFWriter::pushDiscardFilter(PipelinePopper& pp) |
| 996 | 997 | } |
| 997 | 998 | |
| 998 | 999 | void |
| 1000 | +QPDFWriter::pushStringPipeline(PipelinePopper& pp, std::string& str) | |
| 1001 | +{ | |
| 1002 | + activatePipelineStack(pp, true, &str); | |
| 1003 | +} | |
| 1004 | + | |
| 1005 | +void | |
| 999 | 1006 | QPDFWriter::pushMD5Pipeline(PipelinePopper& pp) |
| 1000 | 1007 | { |
| 1001 | 1008 | if (!m->id2.empty()) { |
| ... | ... | @@ -1280,8 +1287,7 @@ QPDFWriter::willFilterStream( |
| 1280 | 1287 | for (bool first_attempt: {true, false}) { |
| 1281 | 1288 | PipelinePopper pp_stream_data(this); |
| 1282 | 1289 | if (stream_data != nullptr) { |
| 1283 | - pushPipeline(new Pl_String("stream data", nullptr, *stream_data)); | |
| 1284 | - activatePipelineStack(pp_stream_data); | |
| 1290 | + pushStringPipeline(pp_stream_data, *stream_data); | |
| 1285 | 1291 | } else { |
| 1286 | 1292 | pushDiscardFilter(pp_stream_data); |
| 1287 | 1293 | } |
| ... | ... | @@ -1644,9 +1650,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1644 | 1650 | { |
| 1645 | 1651 | // Pass 1 |
| 1646 | 1652 | PipelinePopper pp_ostream_pass1(this); |
| 1647 | - | |
| 1648 | - pushPipeline(new Pl_String("object stream", nullptr, stream_buffer_pass1)); | |
| 1649 | - activatePipelineStack(pp_ostream_pass1); | |
| 1653 | + pushStringPipeline(pp_ostream_pass1, stream_buffer_pass1); | |
| 1650 | 1654 | |
| 1651 | 1655 | int count = -1; |
| 1652 | 1656 | for (auto const& obj: m->object_stream_to_objects[old_id]) { |
| ... | ... | @@ -2888,9 +2892,8 @@ QPDFWriter::writeLinearized() |
| 2888 | 2892 | |
| 2889 | 2893 | // Write hint stream to a buffer |
| 2890 | 2894 | { |
| 2891 | - pushPipeline(new Pl_String("hint buffer", nullptr, hint_buffer)); | |
| 2892 | 2895 | PipelinePopper pp_hint(this); |
| 2893 | - activatePipelineStack(pp_hint); | |
| 2896 | + pushStringPipeline(pp_hint, hint_buffer); | |
| 2894 | 2897 | writeHintStream(hint_id); |
| 2895 | 2898 | } |
| 2896 | 2899 | hint_length = QIntC::to_offset(hint_buffer.size()); | ... | ... |
libqpdf/qpdf/Pipeline_private.hh
| ... | ... | @@ -13,12 +13,22 @@ namespace qpdf::pl |
| 13 | 13 | { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + Count(char const* identifier, std::string* str) : | |
| 17 | + Pipeline(identifier, nullptr), | |
| 18 | + str(str) | |
| 19 | + { | |
| 20 | + } | |
| 21 | + | |
| 16 | 22 | ~Count() final = default; |
| 17 | 23 | |
| 18 | 24 | void |
| 19 | 25 | write(unsigned char const* buf, size_t len) final |
| 20 | 26 | { |
| 21 | 27 | if (len) { |
| 28 | + if (str) { | |
| 29 | + str->append(reinterpret_cast<char const*>(buf), len); | |
| 30 | + return; | |
| 31 | + } | |
| 22 | 32 | count += static_cast<qpdf_offset_t>(len); |
| 23 | 33 | if (next()) { |
| 24 | 34 | next()->write(buf, len); |
| ... | ... | @@ -37,11 +47,12 @@ namespace qpdf::pl |
| 37 | 47 | qpdf_offset_t |
| 38 | 48 | getCount() const |
| 39 | 49 | { |
| 40 | - return count; | |
| 50 | + return str ? static_cast<qpdf_offset_t>(str->size()) : count; | |
| 41 | 51 | } |
| 42 | 52 | |
| 43 | 53 | private: |
| 44 | 54 | qpdf_offset_t count{0}; |
| 55 | + std::string* str{nullptr}; | |
| 45 | 56 | }; |
| 46 | 57 | } // namespace qpdf::pl |
| 47 | 58 | ... | ... |