2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Bug fix: don't compress hint streams when --compress-streams=n

This commit is contained in:
Jay Berkenbilt 2023-12-20 11:08:36 -05:00
parent c5f622a09e
commit d61612a2e5
12 changed files with 28 additions and 14 deletions

View File

@ -1,7 +1,7 @@
2023-12-20 Jay Berkenbilt <ejb@ql.org> 2023-12-20 Jay Berkenbilt <ejb@ql.org>
* Bug fix: with --compress-streams=n, don't compress object or * Bug fix: with --compress-streams=n, don't compress object, XRef,
XRef streams. or linearization hint streams.
2023-12-16 Jay Berkenbilt <ejb@ql.org> 2023-12-16 Jay Berkenbilt <ejb@ql.org>

View File

@ -745,9 +745,10 @@ class QPDF
std::map<int, int> const& obj_renumber, std::map<int, int> const& obj_renumber,
std::shared_ptr<Buffer>& hint_stream, std::shared_ptr<Buffer>& hint_stream,
int& S, int& S,
int& O) int& O,
bool compressed)
{ {
return qpdf.generateHintStream(xref, lengths, obj_renumber, hint_stream, S, O); return qpdf.generateHintStream(xref, lengths, obj_renumber, hint_stream, S, O, compressed);
} }
static void static void
@ -1094,7 +1095,8 @@ class QPDF
std::map<int, int> const& obj_renumber, std::map<int, int> const& obj_renumber,
std::shared_ptr<Buffer>& hint_stream, std::shared_ptr<Buffer>& hint_stream,
int& S, int& S,
int& O); int& O,
bool compressed);
// Map object to object stream that contains it // Map object to object stream that contains it
void getObjectStreamData(std::map<int, int>&); void getObjectStreamData(std::map<int, int>&);

View File

@ -2289,15 +2289,20 @@ QPDFWriter::writeHintStream(int hint_id)
std::shared_ptr<Buffer> hint_buffer; std::shared_ptr<Buffer> hint_buffer;
int S = 0; int S = 0;
int O = 0; int O = 0;
bool compressed = (m->compress_streams && !m->qdf_mode);
QPDF::Writer::generateHintStream( QPDF::Writer::generateHintStream(
m->pdf, m->xref, m->lengths, m->obj_renumber_no_gen, hint_buffer, S, O); m->pdf, m->xref, m->lengths, m->obj_renumber_no_gen, hint_buffer, S, O, compressed);
openObject(hint_id); openObject(hint_id);
setDataKey(hint_id); setDataKey(hint_id);
size_t hlen = hint_buffer->getSize(); size_t hlen = hint_buffer->getSize();
writeString("<< /Filter /FlateDecode /S "); writeString("<< ");
if (compressed) {
writeString("/Filter /FlateDecode ");
}
writeString("/S ");
writeString(std::to_string(S)); writeString(std::to_string(S));
if (O) { if (O) {
writeString(" /O "); writeString(" /O ");

View File

@ -1748,10 +1748,10 @@ QPDF::writeHSharedObject(BitWriter& w)
void void
QPDF::writeHGeneric(BitWriter& w, HGeneric& t) QPDF::writeHGeneric(BitWriter& w, HGeneric& t)
{ {
w.writeBitsInt(t.first_object, 32); // 1 w.writeBitsInt(t.first_object, 32); // 1
w.writeBits(toULL(t.first_object_offset), 32); // 2 w.writeBits(toULL(t.first_object_offset), 32); // 2
w.writeBitsInt(t.nobjects, 32); // 3 w.writeBitsInt(t.nobjects, 32); // 3
w.writeBitsInt(t.group_length, 32); // 4 w.writeBitsInt(t.group_length, 32); // 4
} }
void void
@ -1761,7 +1761,8 @@ QPDF::generateHintStream(
std::map<int, int> const& obj_renumber, std::map<int, int> const& obj_renumber,
std::shared_ptr<Buffer>& hint_buffer, std::shared_ptr<Buffer>& hint_buffer,
int& S, int& S,
int& O) int& O,
bool compressed)
{ {
// Populate actual hint table values // Populate actual hint table values
calculateHPageOffset(xref, lengths, obj_renumber); calculateHPageOffset(xref, lengths, obj_renumber);
@ -1771,8 +1772,14 @@ QPDF::generateHintStream(
// Write the hint stream itself into a compressed memory buffer. Write through a counter so we // Write the hint stream itself into a compressed memory buffer. Write through a counter so we
// can get offsets. // can get offsets.
Pl_Buffer hint_stream("hint stream"); Pl_Buffer hint_stream("hint stream");
Pl_Flate f("compress hint stream", &hint_stream, Pl_Flate::a_deflate); Pipeline* next = &hint_stream;
Pl_Count c("count", &f); std::shared_ptr<Pipeline> flate;
if (compressed) {
flate =
std::make_shared<Pl_Flate>("compress hint stream", &hint_stream, Pl_Flate::a_deflate);
next = flate.get();
}
Pl_Count c("count", next);
BitWriter w(&c); BitWriter w(&c);
writeHPageOffset(w); writeHPageOffset(w);