Commit 8a32515a62960af10abfb863157a4c67ea3b506f
1 parent
272fb9de
Add warnings for some additional page tree repair
Showing
8 changed files
with
34 additions
and
7 deletions
libqpdf/QPDF_pages.cc
| @@ -110,12 +110,19 @@ QPDF::getAllPagesInternal( | @@ -110,12 +110,19 @@ QPDF::getAllPagesInternal( | ||
| 110 | QPDFObjectHandle kid = kids.getArrayItem(i); | 110 | QPDFObjectHandle kid = kids.getArrayItem(i); |
| 111 | if (!kid.isIndirect()) { | 111 | if (!kid.isIndirect()) { |
| 112 | QTC::TC("qpdf", "QPDF handle direct page object"); | 112 | QTC::TC("qpdf", "QPDF handle direct page object"); |
| 113 | + cur_node.warnIfPossible( | ||
| 114 | + "kid " + QUtil::int_to_string(i) + | ||
| 115 | + " (from 0) is direct; converting to indirect"); | ||
| 113 | kid = makeIndirectObject(kid); | 116 | kid = makeIndirectObject(kid); |
| 114 | kids.setArrayItem(i, kid); | 117 | kids.setArrayItem(i, kid); |
| 115 | } else if (seen.count(kid.getObjGen())) { | 118 | } else if (seen.count(kid.getObjGen())) { |
| 116 | // Make a copy of the page. This does the same as | 119 | // Make a copy of the page. This does the same as |
| 117 | // shallowCopyPage in QPDFPageObjectHelper. | 120 | // shallowCopyPage in QPDFPageObjectHelper. |
| 118 | QTC::TC("qpdf", "QPDF resolve duplicated page object"); | 121 | QTC::TC("qpdf", "QPDF resolve duplicated page object"); |
| 122 | + cur_node.warnIfPossible( | ||
| 123 | + "kid " + QUtil::int_to_string(i) + | ||
| 124 | + " (from 0) appears more than once in the pages tree;" | ||
| 125 | + " creating a new page object as a copy"); | ||
| 119 | kid = makeIndirectObject(QPDFObjectHandle(kid).shallowCopy()); | 126 | kid = makeIndirectObject(QPDFObjectHandle(kid).shallowCopy()); |
| 120 | kids.setArrayItem(i, kid); | 127 | kids.setArrayItem(i, kid); |
| 121 | } | 128 | } |
qpdf/qtest/pages-tree.test
| @@ -14,13 +14,14 @@ cleanup(); | @@ -14,13 +14,14 @@ cleanup(); | ||
| 14 | 14 | ||
| 15 | my $td = new TestDriver('pages-tree'); | 15 | my $td = new TestDriver('pages-tree'); |
| 16 | 16 | ||
| 17 | -my $n_tests = 11; | 17 | +my $n_tests = 13; |
| 18 | 18 | ||
| 19 | $td->runtest("linearize duplicated pages", | 19 | $td->runtest("linearize duplicated pages", |
| 20 | {$td->COMMAND => | 20 | {$td->COMMAND => |
| 21 | "qpdf --static-id --linearize" . | 21 | "qpdf --static-id --linearize" . |
| 22 | " page_api_2.pdf a.pdf"}, | 22 | " page_api_2.pdf a.pdf"}, |
| 23 | - {$td->STRING => "", $td->EXIT_STATUS => 0}, | 23 | + {$td->FILE => "duplicate-page-warning.out", |
| 24 | + $td->EXIT_STATUS => 3}, | ||
| 24 | $td->NORMALIZE_NEWLINES); | 25 | $td->NORMALIZE_NEWLINES); |
| 25 | $td->runtest("compare files", | 26 | $td->runtest("compare files", |
| 26 | {$td->FILE => "a.pdf"}, | 27 | {$td->FILE => "a.pdf"}, |
| @@ -29,7 +30,8 @@ $td->runtest("extract duplicated pages", | @@ -29,7 +30,8 @@ $td->runtest("extract duplicated pages", | ||
| 29 | {$td->COMMAND => | 30 | {$td->COMMAND => |
| 30 | "qpdf --static-id page_api_2.pdf" . | 31 | "qpdf --static-id page_api_2.pdf" . |
| 31 | " --pages . -- a.pdf"}, | 32 | " --pages . -- a.pdf"}, |
| 32 | - {$td->STRING => "", $td->EXIT_STATUS => 0}, | 33 | + {$td->FILE => "duplicate-page-warning.out", |
| 34 | + $td->EXIT_STATUS => 3}, | ||
| 33 | $td->NORMALIZE_NEWLINES); | 35 | $td->NORMALIZE_NEWLINES); |
| 34 | $td->runtest("compare files", | 36 | $td->runtest("compare files", |
| 35 | {$td->FILE => "a.pdf"}, | 37 | {$td->FILE => "a.pdf"}, |
| @@ -37,7 +39,7 @@ $td->runtest("compare files", | @@ -37,7 +39,7 @@ $td->runtest("compare files", | ||
| 37 | $td->runtest("direct pages", | 39 | $td->runtest("direct pages", |
| 38 | {$td->COMMAND => | 40 | {$td->COMMAND => |
| 39 | "qpdf --static-id direct-pages.pdf --pages . -- a.pdf"}, | 41 | "qpdf --static-id direct-pages.pdf --pages . -- a.pdf"}, |
| 40 | - {$td->STRING => "", $td->EXIT_STATUS => 0}, | 42 | + {$td->FILE => "direct-page-warning.out", $td->EXIT_STATUS => 3}, |
| 41 | $td->NORMALIZE_NEWLINES); | 43 | $td->NORMALIZE_NEWLINES); |
| 42 | $td->runtest("check output", | 44 | $td->runtest("check output", |
| 43 | {$td->FILE => "a.pdf"}, | 45 | {$td->FILE => "a.pdf"}, |
| @@ -45,7 +47,7 @@ $td->runtest("check output", | @@ -45,7 +47,7 @@ $td->runtest("check output", | ||
| 45 | $td->runtest("show direct pages", | 47 | $td->runtest("show direct pages", |
| 46 | {$td->COMMAND => | 48 | {$td->COMMAND => |
| 47 | "qpdf --show-pages direct-pages.pdf"}, | 49 | "qpdf --show-pages direct-pages.pdf"}, |
| 48 | - {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 0}, | 50 | + {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 3}, |
| 49 | $td->NORMALIZE_NEWLINES); | 51 | $td->NORMALIZE_NEWLINES); |
| 50 | 52 | ||
| 51 | # Json mode for direct and duplicated pages illustrates that the | 53 | # Json mode for direct and duplicated pages illustrates that the |
| @@ -62,8 +64,12 @@ foreach my $f (qw(page_api_2 direct-pages)) | @@ -62,8 +64,12 @@ foreach my $f (qw(page_api_2 direct-pages)) | ||
| 62 | $td->runtest("json for $f (with pages)", | 64 | $td->runtest("json for $f (with pages)", |
| 63 | {$td->COMMAND => | 65 | {$td->COMMAND => |
| 64 | "qpdf --json=latest $f.pdf" . | 66 | "qpdf --json=latest $f.pdf" . |
| 65 | - " --json-key=objects --json-key=pages"}, | ||
| 66 | - {$td->FILE => "$f-json-pages.out", $td->EXIT_STATUS => 0}, | 67 | + " --json-key=objects --json-key=pages 2>warn.tmpout"}, |
| 68 | + {$td->FILE => "$f-json-pages.out", $td->EXIT_STATUS => 3}, | ||
| 69 | + $td->NORMALIZE_NEWLINES); | ||
| 70 | + $td->runtest("check page warnings", | ||
| 71 | + {$td->FILE => "warn.tmpout"}, | ||
| 72 | + {$td->FILE => "$f-json-warning.out"}, | ||
| 67 | $td->NORMALIZE_NEWLINES); | 73 | $td->NORMALIZE_NEWLINES); |
| 68 | } | 74 | } |
| 69 | 75 |
qpdf/qtest/qpdf/direct-page-warning.out
0 → 100644
qpdf/qtest/qpdf/direct-pages-json-warning.out
0 → 100644
qpdf/qtest/qpdf/direct-pages.out
| 1 | +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 0 (from 0) is direct; converting to indirect | ||
| 2 | +WARNING: direct-pages.pdf, object 2 0 at offset 143: kid 1 (from 0) is direct; converting to indirect | ||
| 1 | page 1: 7 0 R | 3 | page 1: 7 0 R |
| 2 | content: | 4 | content: |
| 3 | 3 0 R | 5 | 3 0 R |
| 4 | page 2: 8 0 R | 6 | page 2: 8 0 R |
| 5 | content: | 7 | content: |
| 6 | 3 0 R | 8 | 3 0 R |
| 9 | +qpdf: operation succeeded with warnings |
qpdf/qtest/qpdf/duplicate-page-warning.out
0 → 100644
qpdf/qtest/qpdf/page_api_2-json-warning.out
0 → 100644
qpdf/qtest/qpdf/page_api_2.out