From 2712869cf96916bceeac7def35b6d0a54bd10316 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 28 Jan 2019 21:43:06 -0500 Subject: [PATCH] Fix logic for when to compress object and xref streams (fixes #271) --- ChangeLog | 4 ++++ TODO | 4 ---- libqpdf/QPDFWriter.cc | 8 ++++++-- manual/qpdf-manual.xml | 7 +++++++ qpdf/qtest/qpdf.test | 13 +++++++++++-- qpdf/qtest/qpdf/compress-objstm-xref.pdf | Bin 0 -> 743 bytes 6 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 qpdf/qtest/qpdf/compress-objstm-xref.pdf diff --git a/ChangeLog b/ChangeLog index f24e1b75..180335f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-01-28 Jay Berkenbilt + * Bug fix: when using --stream-data=compress, object streams and + xref streams were not compressed. They were compressed if no + --stream-data option was specified. Fixes #271. + * When linearizing or getting the list of all pages in a file, replace duplicated page objects with a shallow copy of the page object. Linearization and all page manipulation APIs require page diff --git a/TODO b/TODO index 46d5d9df..42a348ed 100644 --- a/TODO +++ b/TODO @@ -9,10 +9,6 @@ Soon latter is appropriate when a page is being converted to a form XObject. - * Look at the file for issue 271 (../misc/bugs/271/6059954.pdf) to - figure out why the compression is bad and see if I can do anything - about it. - Next ABI ======== diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index c549728d..fee287bc 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1934,7 +1934,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) // Set up a stream to write the stream data into a buffer. Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); - if (! (this->m->stream_decode_level || this->m->qdf_mode)) + if ((this->m->compress_streams || + (this->m->stream_decode_level == qpdf_dl_none)) && + (! this->m->qdf_mode)) { compressed = true; next = pushPipeline( @@ -2876,7 +2878,9 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset, Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); bool compressed = false; - if (! (this->m->stream_decode_level || this->m->qdf_mode)) + if ((this->m->compress_streams || + (this->m->stream_decode_level == qpdf_dl_none)) && + (! this->m->qdf_mode)) { compressed = true; if (! skip_compression) diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index aaeaeb54..a724ba54 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -4417,6 +4417,13 @@ print "\n"; pages tree. + + + Using older option + with object streams, object streams and xref streams were + not compressed. + + diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 9b72706f..85b9b8de 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -1435,7 +1435,7 @@ foreach my $d ( " $flags streams-with-newlines.pdf a.pdf"}, {$td->STRING => "", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); - $td->runtest("check output", + $td->runtest("check output ($description)", {$td->FILE => "a.pdf"}, {$td->FILE => "newline-before-endstream-$suffix.pdf"}); if ($flags =~ /qdf/) @@ -2461,7 +2461,7 @@ for (my $n = 16; $n <= 19; ++$n) show_ntests(); # ---------- $td->notify("--- Specific File Tests ---"); -$n_tests += 2; +$n_tests += 4; # Special PDF files that caused problems at some point @@ -2473,6 +2473,15 @@ $td->runtest("damaged stream (C)", {$td->COMMAND => "qpdf-ctest 2 damaged-stream.pdf '' a.pdf"}, {$td->FILE => "damaged-stream-c-check.out", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); +$td->runtest("compress objstm and xref", + {$td->COMMAND => + "qpdf --static-id --stream-data=compress". + " --object-streams=generate minimal.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "compress-objstm-xref.pdf"}); show_ntests(); # ---------- diff --git a/qpdf/qtest/qpdf/compress-objstm-xref.pdf b/qpdf/qtest/qpdf/compress-objstm-xref.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a121ef24ac2463bf1fa7e9c0f25eb259a1478435 GIT binary patch literal 743 zcmY!laBZ^4|D>$ol3WFSpVYkck_-hS zBVz@9x6GW9)FL3AlUS1KlA4^K0#xXyU<#5cDlSnlGE=a#<0>vGN=?k=s+i;2AJ~1! zK%nLRU(wI}mt1oFCmdR--c->c_d~(%$*rX&N%$K$ zer(hXnWo$xRAe&W`Awc{#DqSDKbUXIx1XN z^8_6{_`aDgJae7GlLR-}tH!ghjI~XGM=ycdRvu%wQlD{+eR_gEjD!(+O z@J*fbqT@W4E~;Ygdl~vC$1Y9HOM!Y6$N~kOIZ_Zp1I@$&dzc{yQZd)VpnwbI#vukq zfgGO9o6hz&oN!Q7VLfq;f4dBwHa77ZH@229Gvl zBkV5Fhs0h$Vo`3f0w~g*^K(jb^NJNr6!Zg%Qd2UMOY(~p42^*Csh}UO5UpUSU4R{VPa-vW@2n? zVQge>X=+DUMJ!74Nls#5QgdUg6ZqKK$ax~!Mg5;K+dsxlrz99mzBAwD!U&4ulEk8t TilWpsE)!ETE>%@me>W}wSu6&d literal 0 HcmV?d00001