2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +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>
* Bug fix: with --compress-streams=n, don't compress object or
XRef streams.
* Bug fix: with --compress-streams=n, don't compress object, XRef,
or linearization hint streams.
2023-12-16 Jay Berkenbilt <ejb@ql.org>

View File

@ -745,9 +745,10 @@ class QPDF
std::map<int, int> const& obj_renumber,
std::shared_ptr<Buffer>& hint_stream,
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
@ -1094,7 +1095,8 @@ class QPDF
std::map<int, int> const& obj_renumber,
std::shared_ptr<Buffer>& hint_stream,
int& S,
int& O);
int& O,
bool compressed);
// Map object to object stream that contains it
void getObjectStreamData(std::map<int, int>&);

View File

@ -2289,15 +2289,20 @@ QPDFWriter::writeHintStream(int hint_id)
std::shared_ptr<Buffer> hint_buffer;
int S = 0;
int O = 0;
bool compressed = (m->compress_streams && !m->qdf_mode);
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);
setDataKey(hint_id);
size_t hlen = hint_buffer->getSize();
writeString("<< /Filter /FlateDecode /S ");
writeString("<< ");
if (compressed) {
writeString("/Filter /FlateDecode ");
}
writeString("/S ");
writeString(std::to_string(S));
if (O) {
writeString(" /O ");

View File

@ -1748,10 +1748,10 @@ QPDF::writeHSharedObject(BitWriter& w)
void
QPDF::writeHGeneric(BitWriter& w, HGeneric& t)
{
w.writeBitsInt(t.first_object, 32); // 1
w.writeBits(toULL(t.first_object_offset), 32); // 2
w.writeBitsInt(t.nobjects, 32); // 3
w.writeBitsInt(t.group_length, 32); // 4
w.writeBitsInt(t.first_object, 32); // 1
w.writeBits(toULL(t.first_object_offset), 32); // 2
w.writeBitsInt(t.nobjects, 32); // 3
w.writeBitsInt(t.group_length, 32); // 4
}
void
@ -1761,7 +1761,8 @@ QPDF::generateHintStream(
std::map<int, int> const& obj_renumber,
std::shared_ptr<Buffer>& hint_buffer,
int& S,
int& O)
int& O,
bool compressed)
{
// Populate actual hint table values
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
// can get offsets.
Pl_Buffer hint_stream("hint stream");
Pl_Flate f("compress hint stream", &hint_stream, Pl_Flate::a_deflate);
Pl_Count c("count", &f);
Pipeline* next = &hint_stream;
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);
writeHPageOffset(w);