Commit d61612a2e54d266d8fc4f55042080b780984272e
1 parent
c5f622a0
Bug fix: don't compress hint streams when --compress-streams=n
Showing
12 changed files
with
28 additions
and
14 deletions
ChangeLog
include/qpdf/QPDF.hh
| ... | ... | @@ -745,9 +745,10 @@ class QPDF |
| 745 | 745 | std::map<int, int> const& obj_renumber, |
| 746 | 746 | std::shared_ptr<Buffer>& hint_stream, |
| 747 | 747 | int& S, |
| 748 | - int& O) | |
| 748 | + int& O, | |
| 749 | + bool compressed) | |
| 749 | 750 | { |
| 750 | - return qpdf.generateHintStream(xref, lengths, obj_renumber, hint_stream, S, O); | |
| 751 | + return qpdf.generateHintStream(xref, lengths, obj_renumber, hint_stream, S, O, compressed); | |
| 751 | 752 | } |
| 752 | 753 | |
| 753 | 754 | static void |
| ... | ... | @@ -1094,7 +1095,8 @@ class QPDF |
| 1094 | 1095 | std::map<int, int> const& obj_renumber, |
| 1095 | 1096 | std::shared_ptr<Buffer>& hint_stream, |
| 1096 | 1097 | int& S, |
| 1097 | - int& O); | |
| 1098 | + int& O, | |
| 1099 | + bool compressed); | |
| 1098 | 1100 | |
| 1099 | 1101 | // Map object to object stream that contains it |
| 1100 | 1102 | void getObjectStreamData(std::map<int, int>&); | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -2289,15 +2289,20 @@ QPDFWriter::writeHintStream(int hint_id) |
| 2289 | 2289 | std::shared_ptr<Buffer> hint_buffer; |
| 2290 | 2290 | int S = 0; |
| 2291 | 2291 | int O = 0; |
| 2292 | + bool compressed = (m->compress_streams && !m->qdf_mode); | |
| 2292 | 2293 | QPDF::Writer::generateHintStream( |
| 2293 | - m->pdf, m->xref, m->lengths, m->obj_renumber_no_gen, hint_buffer, S, O); | |
| 2294 | + m->pdf, m->xref, m->lengths, m->obj_renumber_no_gen, hint_buffer, S, O, compressed); | |
| 2294 | 2295 | |
| 2295 | 2296 | openObject(hint_id); |
| 2296 | 2297 | setDataKey(hint_id); |
| 2297 | 2298 | |
| 2298 | 2299 | size_t hlen = hint_buffer->getSize(); |
| 2299 | 2300 | |
| 2300 | - writeString("<< /Filter /FlateDecode /S "); | |
| 2301 | + writeString("<< "); | |
| 2302 | + if (compressed) { | |
| 2303 | + writeString("/Filter /FlateDecode "); | |
| 2304 | + } | |
| 2305 | + writeString("/S "); | |
| 2301 | 2306 | writeString(std::to_string(S)); |
| 2302 | 2307 | if (O) { |
| 2303 | 2308 | writeString(" /O "); | ... | ... |
libqpdf/QPDF_linearization.cc
| ... | ... | @@ -1748,10 +1748,10 @@ QPDF::writeHSharedObject(BitWriter& w) |
| 1748 | 1748 | void |
| 1749 | 1749 | QPDF::writeHGeneric(BitWriter& w, HGeneric& t) |
| 1750 | 1750 | { |
| 1751 | - w.writeBitsInt(t.first_object, 32); // 1 | |
| 1752 | - w.writeBits(toULL(t.first_object_offset), 32); // 2 | |
| 1753 | - w.writeBitsInt(t.nobjects, 32); // 3 | |
| 1754 | - w.writeBitsInt(t.group_length, 32); // 4 | |
| 1751 | + w.writeBitsInt(t.first_object, 32); // 1 | |
| 1752 | + w.writeBits(toULL(t.first_object_offset), 32); // 2 | |
| 1753 | + w.writeBitsInt(t.nobjects, 32); // 3 | |
| 1754 | + w.writeBitsInt(t.group_length, 32); // 4 | |
| 1755 | 1755 | } |
| 1756 | 1756 | |
| 1757 | 1757 | void |
| ... | ... | @@ -1761,7 +1761,8 @@ QPDF::generateHintStream( |
| 1761 | 1761 | std::map<int, int> const& obj_renumber, |
| 1762 | 1762 | std::shared_ptr<Buffer>& hint_buffer, |
| 1763 | 1763 | int& S, |
| 1764 | - int& O) | |
| 1764 | + int& O, | |
| 1765 | + bool compressed) | |
| 1765 | 1766 | { |
| 1766 | 1767 | // Populate actual hint table values |
| 1767 | 1768 | calculateHPageOffset(xref, lengths, obj_renumber); |
| ... | ... | @@ -1771,8 +1772,14 @@ QPDF::generateHintStream( |
| 1771 | 1772 | // Write the hint stream itself into a compressed memory buffer. Write through a counter so we |
| 1772 | 1773 | // can get offsets. |
| 1773 | 1774 | Pl_Buffer hint_stream("hint stream"); |
| 1774 | - Pl_Flate f("compress hint stream", &hint_stream, Pl_Flate::a_deflate); | |
| 1775 | - Pl_Count c("count", &f); | |
| 1775 | + Pipeline* next = &hint_stream; | |
| 1776 | + std::shared_ptr<Pipeline> flate; | |
| 1777 | + if (compressed) { | |
| 1778 | + flate = | |
| 1779 | + std::make_shared<Pl_Flate>("compress hint stream", &hint_stream, Pl_Flate::a_deflate); | |
| 1780 | + next = flate.get(); | |
| 1781 | + } | |
| 1782 | + Pl_Count c("count", next); | |
| 1776 | 1783 | BitWriter w(&c); |
| 1777 | 1784 | |
| 1778 | 1785 | writeHPageOffset(w); | ... | ... |
qpdf/qtest/qpdf/job-json-misc-options.pdf
No preview for this file type
qpdf/qtest/qpdf/lin-special.disable.exp
No preview for this file type
qpdf/qtest/qpdf/lin-special.generate.exp
No preview for this file type
qpdf/qtest/qpdf/lin-special.preserve.exp
No preview for this file type
qpdf/qtest/qpdf/object-stream.disable.exp
No preview for this file type
qpdf/qtest/qpdf/object-stream.generate.exp
No preview for this file type
qpdf/qtest/qpdf/object-stream.preserve.exp
No preview for this file type
qpdf/qtest/qpdf/replaced-stream-data-flate.pdf
No preview for this file type