Commit b20485e4e4b9a3fd02beeaa72264ad2acaeb650f
1 parent
d7853db8
In QPDFWriter::writeObjectStream use Pl_String instead of Pl_Buffer
Showing
1 changed file
with
11 additions
and
8 deletions
libqpdf/QPDFWriter.cc
| ... | ... | @@ -1650,14 +1650,15 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1650 | 1650 | |
| 1651 | 1651 | // Generate stream itself. We have to do this in two passes so we can calculate offsets in the |
| 1652 | 1652 | // first pass. |
| 1653 | - std::shared_ptr<Buffer> stream_buffer; | |
| 1653 | + std::string stream_buffer_pass1; | |
| 1654 | + std::string stream_buffer_pass2; | |
| 1654 | 1655 | int first_obj = -1; |
| 1655 | 1656 | bool compressed = false; |
| 1656 | 1657 | { |
| 1657 | 1658 | // Pass 1 |
| 1658 | - PipelinePopper pp_ostream_pass1(this, &stream_buffer); | |
| 1659 | + PipelinePopper pp_ostream_pass1(this); | |
| 1659 | 1660 | |
| 1660 | - pushPipeline(new Pl_Buffer("object stream")); | |
| 1661 | + pushPipeline(new Pl_String("object stream", nullptr, stream_buffer_pass1)); | |
| 1661 | 1662 | activatePipelineStack(pp_ostream_pass1); |
| 1662 | 1663 | |
| 1663 | 1664 | int count = -1; |
| ... | ... | @@ -1702,7 +1703,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1702 | 1703 | } |
| 1703 | 1704 | } |
| 1704 | 1705 | { |
| 1705 | - PipelinePopper pp_ostream(this, &stream_buffer); | |
| 1706 | + PipelinePopper pp_ostream(this); | |
| 1706 | 1707 | // Adjust offsets to skip over comment before first object |
| 1707 | 1708 | first = offsets.at(0); |
| 1708 | 1709 | for (auto& iter: offsets) { |
| ... | ... | @@ -1718,14 +1719,16 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1718 | 1719 | } |
| 1719 | 1720 | |
| 1720 | 1721 | // Set up a stream to write the stream data into a buffer. |
| 1721 | - Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); | |
| 1722 | + Pipeline* next = pushPipeline(new Pl_String("object stream", nullptr, stream_buffer_pass2)); | |
| 1722 | 1723 | if (m->compress_streams && !m->qdf_mode) { |
| 1723 | 1724 | compressed = true; |
| 1724 | 1725 | next = pushPipeline(new Pl_Flate("compress object stream", next, Pl_Flate::a_deflate)); |
| 1725 | 1726 | } |
| 1726 | 1727 | activatePipelineStack(pp_ostream); |
| 1727 | 1728 | writeObjectStreamOffsets(offsets, first_obj); |
| 1728 | - writeBuffer(stream_buffer); | |
| 1729 | + writeString(stream_buffer_pass1); | |
| 1730 | + stream_buffer_pass1.clear(); | |
| 1731 | + stream_buffer_pass1.shrink_to_fit(); | |
| 1729 | 1732 | } |
| 1730 | 1733 | |
| 1731 | 1734 | // Write the object |
| ... | ... | @@ -1735,7 +1738,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1735 | 1738 | writeStringQDF("\n "); |
| 1736 | 1739 | writeString(" /Type /ObjStm"); |
| 1737 | 1740 | writeStringQDF("\n "); |
| 1738 | - size_t length = stream_buffer->getSize(); | |
| 1741 | + size_t length = stream_buffer_pass2.size(); | |
| 1739 | 1742 | adjustAESStreamLength(length); |
| 1740 | 1743 | writeString(" /Length " + std::to_string(length)); |
| 1741 | 1744 | writeStringQDF("\n "); |
| ... | ... | @@ -1765,7 +1768,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1765 | 1768 | { |
| 1766 | 1769 | PipelinePopper pp_enc(this); |
| 1767 | 1770 | pushEncryptionFilter(pp_enc); |
| 1768 | - writeBuffer(stream_buffer); | |
| 1771 | + writeString(stream_buffer_pass2); | |
| 1769 | 1772 | } |
| 1770 | 1773 | if (m->newline_before_endstream) { |
| 1771 | 1774 | writeString("\n"); | ... | ... |