Commit 2712869cf96916bceeac7def35b6d0a54bd10316
1 parent
52f9d326
Fix logic for when to compress object and xref streams (fixes #271)
Showing
6 changed files
with
28 additions
and
8 deletions
ChangeLog
| 1 | 2019-01-28 Jay Berkenbilt <ejb@ql.org> | 1 | 2019-01-28 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * Bug fix: when using --stream-data=compress, object streams and | ||
| 4 | + xref streams were not compressed. They were compressed if no | ||
| 5 | + --stream-data option was specified. Fixes #271. | ||
| 6 | + | ||
| 3 | * When linearizing or getting the list of all pages in a file, | 7 | * When linearizing or getting the list of all pages in a file, |
| 4 | replace duplicated page objects with a shallow copy of the page | 8 | replace duplicated page objects with a shallow copy of the page |
| 5 | object. Linearization and all page manipulation APIs require page | 9 | object. Linearization and all page manipulation APIs require page |
TODO
| @@ -9,10 +9,6 @@ Soon | @@ -9,10 +9,6 @@ Soon | ||
| 9 | latter is appropriate when a page is being converted to a form | 9 | latter is appropriate when a page is being converted to a form |
| 10 | XObject. | 10 | XObject. |
| 11 | 11 | ||
| 12 | - * Look at the file for issue 271 (../misc/bugs/271/6059954.pdf) to | ||
| 13 | - figure out why the compression is bad and see if I can do anything | ||
| 14 | - about it. | ||
| 15 | - | ||
| 16 | Next ABI | 12 | Next ABI |
| 17 | ======== | 13 | ======== |
| 18 | 14 |
libqpdf/QPDFWriter.cc
| @@ -1934,7 +1934,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1934,7 +1934,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1934 | 1934 | ||
| 1935 | // Set up a stream to write the stream data into a buffer. | 1935 | // Set up a stream to write the stream data into a buffer. |
| 1936 | Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); | 1936 | Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); |
| 1937 | - if (! (this->m->stream_decode_level || this->m->qdf_mode)) | 1937 | + if ((this->m->compress_streams || |
| 1938 | + (this->m->stream_decode_level == qpdf_dl_none)) && | ||
| 1939 | + (! this->m->qdf_mode)) | ||
| 1938 | { | 1940 | { |
| 1939 | compressed = true; | 1941 | compressed = true; |
| 1940 | next = pushPipeline( | 1942 | next = pushPipeline( |
| @@ -2876,7 +2878,9 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset, | @@ -2876,7 +2878,9 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset, | ||
| 2876 | 2878 | ||
| 2877 | Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); | 2879 | Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); |
| 2878 | bool compressed = false; | 2880 | bool compressed = false; |
| 2879 | - if (! (this->m->stream_decode_level || this->m->qdf_mode)) | 2881 | + if ((this->m->compress_streams || |
| 2882 | + (this->m->stream_decode_level == qpdf_dl_none)) && | ||
| 2883 | + (! this->m->qdf_mode)) | ||
| 2880 | { | 2884 | { |
| 2881 | compressed = true; | 2885 | compressed = true; |
| 2882 | if (! skip_compression) | 2886 | if (! skip_compression) |
manual/qpdf-manual.xml
| @@ -4417,6 +4417,13 @@ print "\n"; | @@ -4417,6 +4417,13 @@ print "\n"; | ||
| 4417 | pages tree. | 4417 | pages tree. |
| 4418 | </para> | 4418 | </para> |
| 4419 | </listitem> | 4419 | </listitem> |
| 4420 | + <listitem> | ||
| 4421 | + <para> | ||
| 4422 | + Using older option <option>--stream-data=compress</option> | ||
| 4423 | + with object streams, object streams and xref streams were | ||
| 4424 | + not compressed. | ||
| 4425 | + </para> | ||
| 4426 | + </listitem> | ||
| 4420 | </itemizedlist> | 4427 | </itemizedlist> |
| 4421 | </listitem> | 4428 | </listitem> |
| 4422 | <listitem> | 4429 | <listitem> |
qpdf/qtest/qpdf.test
| @@ -1435,7 +1435,7 @@ foreach my $d ( | @@ -1435,7 +1435,7 @@ foreach my $d ( | ||
| 1435 | " $flags streams-with-newlines.pdf a.pdf"}, | 1435 | " $flags streams-with-newlines.pdf a.pdf"}, |
| 1436 | {$td->STRING => "", $td->EXIT_STATUS => 0}, | 1436 | {$td->STRING => "", $td->EXIT_STATUS => 0}, |
| 1437 | $td->NORMALIZE_NEWLINES); | 1437 | $td->NORMALIZE_NEWLINES); |
| 1438 | - $td->runtest("check output", | 1438 | + $td->runtest("check output ($description)", |
| 1439 | {$td->FILE => "a.pdf"}, | 1439 | {$td->FILE => "a.pdf"}, |
| 1440 | {$td->FILE => "newline-before-endstream-$suffix.pdf"}); | 1440 | {$td->FILE => "newline-before-endstream-$suffix.pdf"}); |
| 1441 | if ($flags =~ /qdf/) | 1441 | if ($flags =~ /qdf/) |
| @@ -2461,7 +2461,7 @@ for (my $n = 16; $n <= 19; ++$n) | @@ -2461,7 +2461,7 @@ for (my $n = 16; $n <= 19; ++$n) | ||
| 2461 | show_ntests(); | 2461 | show_ntests(); |
| 2462 | # ---------- | 2462 | # ---------- |
| 2463 | $td->notify("--- Specific File Tests ---"); | 2463 | $td->notify("--- Specific File Tests ---"); |
| 2464 | -$n_tests += 2; | 2464 | +$n_tests += 4; |
| 2465 | 2465 | ||
| 2466 | # Special PDF files that caused problems at some point | 2466 | # Special PDF files that caused problems at some point |
| 2467 | 2467 | ||
| @@ -2473,6 +2473,15 @@ $td->runtest("damaged stream (C)", | @@ -2473,6 +2473,15 @@ $td->runtest("damaged stream (C)", | ||
| 2473 | {$td->COMMAND => "qpdf-ctest 2 damaged-stream.pdf '' a.pdf"}, | 2473 | {$td->COMMAND => "qpdf-ctest 2 damaged-stream.pdf '' a.pdf"}, |
| 2474 | {$td->FILE => "damaged-stream-c-check.out", $td->EXIT_STATUS => 0}, | 2474 | {$td->FILE => "damaged-stream-c-check.out", $td->EXIT_STATUS => 0}, |
| 2475 | $td->NORMALIZE_NEWLINES); | 2475 | $td->NORMALIZE_NEWLINES); |
| 2476 | +$td->runtest("compress objstm and xref", | ||
| 2477 | + {$td->COMMAND => | ||
| 2478 | + "qpdf --static-id --stream-data=compress". | ||
| 2479 | + " --object-streams=generate minimal.pdf a.pdf"}, | ||
| 2480 | + {$td->STRING => "", $td->EXIT_STATUS => 0}, | ||
| 2481 | + $td->NORMALIZE_NEWLINES); | ||
| 2482 | +$td->runtest("check output", | ||
| 2483 | + {$td->FILE => "a.pdf"}, | ||
| 2484 | + {$td->FILE => "compress-objstm-xref.pdf"}); | ||
| 2476 | 2485 | ||
| 2477 | show_ntests(); | 2486 | show_ntests(); |
| 2478 | # ---------- | 2487 | # ---------- |
qpdf/qtest/qpdf/compress-objstm-xref.pdf
0 → 100644
No preview for this file type