Commit 98765c3b5ceecb2c2540405eab1dd7ae1f02ec31
1 parent
998a6cbe
tested basic stream replacement
git-svn-id: svn+q:///qpdf/trunk@989 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
5 changed files
with
194 additions
and
1 deletions
qpdf/qtest/qpdf.test
| @@ -77,7 +77,7 @@ flush_tiff_cache(); | @@ -77,7 +77,7 @@ flush_tiff_cache(); | ||
| 77 | show_ntests(); | 77 | show_ntests(); |
| 78 | # ---------- | 78 | # ---------- |
| 79 | $td->notify("--- Miscellaneous Tests ---"); | 79 | $td->notify("--- Miscellaneous Tests ---"); |
| 80 | -$n_tests += 22; | 80 | +$n_tests += 26; |
| 81 | 81 | ||
| 82 | $td->runtest("qpdf version", | 82 | $td->runtest("qpdf version", |
| 83 | {$td->COMMAND => "qpdf --version"}, | 83 | {$td->COMMAND => "qpdf --version"}, |
| @@ -97,6 +97,22 @@ foreach (my $i = 1; $i <= 3; ++$i) | @@ -97,6 +97,22 @@ foreach (my $i = 1; $i <= 3; ++$i) | ||
| 97 | $td->NORMALIZE_NEWLINES); | 97 | $td->NORMALIZE_NEWLINES); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | +$td->runtest("replace stream data", | ||
| 101 | + {$td->COMMAND => "test_driver 7 qstream.pdf"}, | ||
| 102 | + {$td->STRING => "test 7 done\n", $td->EXIT_STATUS => 0}, | ||
| 103 | + $td->NORMALIZE_NEWLINES); | ||
| 104 | +$td->runtest("check output", | ||
| 105 | + {$td->FILE => "a.pdf"}, | ||
| 106 | + {$td->FILE => "replaced-stream-data.out"}); | ||
| 107 | + | ||
| 108 | +$td->runtest("replace stream data compressed", | ||
| 109 | + {$td->COMMAND => "test_driver 8 qstream.pdf"}, | ||
| 110 | + {$td->STRING => "test 8 done\n", $td->EXIT_STATUS => 0}, | ||
| 111 | + $td->NORMALIZE_NEWLINES); | ||
| 112 | +$td->runtest("check output", | ||
| 113 | + {$td->FILE => "a.pdf"}, | ||
| 114 | + {$td->FILE => "replaced-stream-data-flate.out"}); | ||
| 115 | + | ||
| 100 | # Make sure we ignore decode parameters that we don't understand | 116 | # Make sure we ignore decode parameters that we don't understand |
| 101 | $td->runtest("unknown decode parameters", | 117 | $td->runtest("unknown decode parameters", |
| 102 | {$td->COMMAND => "qpdf --check fax-decode-parms.pdf"}, | 118 | {$td->COMMAND => "qpdf --check fax-decode-parms.pdf"}, |
qpdf/qtest/qpdf/qstream.pdf
0 → 100644
| 1 | +%PDF-1.3 | ||
| 2 | +1 0 obj | ||
| 3 | +<< | ||
| 4 | + /Type /Catalog | ||
| 5 | + /Pages 2 0 R | ||
| 6 | + /QStream 7 0 R | ||
| 7 | +>> | ||
| 8 | +endobj | ||
| 9 | + | ||
| 10 | +2 0 obj | ||
| 11 | +<< | ||
| 12 | + /Type /Pages | ||
| 13 | + /Kids [ | ||
| 14 | + 3 0 R | ||
| 15 | + ] | ||
| 16 | + /Count 1 | ||
| 17 | +>> | ||
| 18 | +endobj | ||
| 19 | + | ||
| 20 | +3 0 obj | ||
| 21 | +<< | ||
| 22 | + /Type /Page | ||
| 23 | + /Parent 2 0 R | ||
| 24 | + /MediaBox [0 0 612 792] | ||
| 25 | + /Contents 4 0 R | ||
| 26 | + /Resources << | ||
| 27 | + /ProcSet 5 0 R | ||
| 28 | + /Font << | ||
| 29 | + /F1 6 0 R | ||
| 30 | + >> | ||
| 31 | + >> | ||
| 32 | +>> | ||
| 33 | +endobj | ||
| 34 | + | ||
| 35 | +4 0 obj | ||
| 36 | +<< | ||
| 37 | + /Length 44 | ||
| 38 | +>> | ||
| 39 | +stream | ||
| 40 | +BT | ||
| 41 | + /F1 24 Tf | ||
| 42 | + 72 720 Td | ||
| 43 | + (Potato) Tj | ||
| 44 | +ET | ||
| 45 | +endstream | ||
| 46 | +endobj | ||
| 47 | + | ||
| 48 | +5 0 obj | ||
| 49 | +[ | ||
| 50 | |||
| 51 | + /Text | ||
| 52 | +] | ||
| 53 | +endobj | ||
| 54 | + | ||
| 55 | +6 0 obj | ||
| 56 | +<< | ||
| 57 | + /Type /Font | ||
| 58 | + /Subtype /Type1 | ||
| 59 | + /Name /F1 | ||
| 60 | + /BaseFont /Helvetica | ||
| 61 | + /Encoding /WinAnsiEncoding | ||
| 62 | +>> | ||
| 63 | +endobj | ||
| 64 | + | ||
| 65 | +7 0 obj | ||
| 66 | +<< | ||
| 67 | + /Length 29 | ||
| 68 | +>> | ||
| 69 | +stream | ||
| 70 | +This is the old stream data. | ||
| 71 | +endstream | ||
| 72 | +endobj | ||
| 73 | + | ||
| 74 | +xref | ||
| 75 | +0 8 | ||
| 76 | +0000000000 65535 f | ||
| 77 | +0000000009 00000 n | ||
| 78 | +0000000080 00000 n | ||
| 79 | +0000000152 00000 n | ||
| 80 | +0000000324 00000 n | ||
| 81 | +0000000420 00000 n | ||
| 82 | +0000000455 00000 n | ||
| 83 | +0000000573 00000 n | ||
| 84 | +trailer << | ||
| 85 | + /Size 8 | ||
| 86 | + /Root 1 0 R | ||
| 87 | +>> | ||
| 88 | +startxref | ||
| 89 | +654 | ||
| 90 | +%%EOF |
qpdf/qtest/qpdf/replaced-stream-data-flate.out
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/replaced-stream-data.out
0 → 100644
| 1 | +%PDF-1.3 | ||
| 2 | +%¿÷¢þ | ||
| 3 | +1 0 obj | ||
| 4 | +<< /Pages 2 0 R /QStream 3 0 R /Type /Catalog >> | ||
| 5 | +endobj | ||
| 6 | +2 0 obj | ||
| 7 | +<< /Count 1 /Kids [ 4 0 R ] /Type /Pages >> | ||
| 8 | +endobj | ||
| 9 | +3 0 obj | ||
| 10 | +<< /Length 20 >> | ||
| 11 | +stream | ||
| 12 | +new data for stream | ||
| 13 | +endstream | ||
| 14 | +endobj | ||
| 15 | +4 0 obj | ||
| 16 | +<< /Contents 5 0 R /MediaBox [ 0 0 612 792 ] /Parent 2 0 R /Resources << /Font << /F1 6 0 R >> /ProcSet 7 0 R >> /Type /Page >> | ||
| 17 | +endobj | ||
| 18 | +5 0 obj | ||
| 19 | +<< /Length 44 >> | ||
| 20 | +stream | ||
| 21 | +BT | ||
| 22 | + /F1 24 Tf | ||
| 23 | + 72 720 Td | ||
| 24 | + (Potato) Tj | ||
| 25 | +ET | ||
| 26 | +endstream | ||
| 27 | +endobj | ||
| 28 | +6 0 obj | ||
| 29 | +<< /BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font >> | ||
| 30 | +endobj | ||
| 31 | +7 0 obj | ||
| 32 | +[ /PDF /Text ] | ||
| 33 | +endobj | ||
| 34 | +xref | ||
| 35 | +0 8 | ||
| 36 | +0000000000 65535 f | ||
| 37 | +0000000015 00000 n | ||
| 38 | +0000000079 00000 n | ||
| 39 | +0000000138 00000 n | ||
| 40 | +0000000207 00000 n | ||
| 41 | +0000000350 00000 n | ||
| 42 | +0000000443 00000 n | ||
| 43 | +0000000550 00000 n | ||
| 44 | +trailer << /Root 1 0 R /Size 8 /ID [<31415926535897932384626433832795><31415926535897932384626433832795>] >> | ||
| 45 | +startxref | ||
| 46 | +580 | ||
| 47 | +%%EOF |
qpdf/test_driver.cc
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | #include <qpdf/QTC.hh> | 7 | #include <qpdf/QTC.hh> |
| 8 | #include <qpdf/Pl_StdioFile.hh> | 8 | #include <qpdf/Pl_StdioFile.hh> |
| 9 | #include <qpdf/Pl_Buffer.hh> | 9 | #include <qpdf/Pl_Buffer.hh> |
| 10 | +#include <qpdf/Pl_Flate.hh> | ||
| 10 | #include <qpdf/QPDFWriter.hh> | 11 | #include <qpdf/QPDFWriter.hh> |
| 11 | #include <iostream> | 12 | #include <iostream> |
| 12 | #include <stdio.h> | 13 | #include <stdio.h> |
| @@ -309,6 +310,45 @@ void runtest(int n, char const* filename) | @@ -309,6 +310,45 @@ void runtest(int n, char const* filename) | ||
| 309 | << (cleartext ? 1 : 0) | 310 | << (cleartext ? 1 : 0) |
| 310 | << std::endl; | 311 | << std::endl; |
| 311 | } | 312 | } |
| 313 | + else if (n == 7) | ||
| 314 | + { | ||
| 315 | + QPDFObjectHandle root = pdf.getRoot(); | ||
| 316 | + QPDFObjectHandle qstream = root.getKey("/QStream"); | ||
| 317 | + if (! qstream.isStream()) | ||
| 318 | + { | ||
| 319 | + throw std::logic_error("test 7 run on file with no QStream"); | ||
| 320 | + } | ||
| 321 | + PointerHolder<Buffer> b = new Buffer(20); | ||
| 322 | + unsigned char* bp = b.getPointer()->getBuffer(); | ||
| 323 | + memcpy(bp, (char*)"new data for stream\n", 20); // no null! | ||
| 324 | + qstream.replaceStreamData( | ||
| 325 | + b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | ||
| 326 | + QPDFWriter w(pdf, "a.pdf"); | ||
| 327 | + w.setStaticID(true); | ||
| 328 | + w.setStreamDataMode(qpdf_s_preserve); | ||
| 329 | + w.write(); | ||
| 330 | + } | ||
| 331 | + else if (n == 8) | ||
| 332 | + { | ||
| 333 | + QPDFObjectHandle root = pdf.getRoot(); | ||
| 334 | + QPDFObjectHandle qstream = root.getKey("/QStream"); | ||
| 335 | + if (! qstream.isStream()) | ||
| 336 | + { | ||
| 337 | + throw std::logic_error("test 7 run on file with no QStream"); | ||
| 338 | + } | ||
| 339 | + Pl_Buffer p1("buffer"); | ||
| 340 | + Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate); | ||
| 341 | + p2.write((unsigned char*)"new data for stream\n", 20); // no null! | ||
| 342 | + p2.finish(); | ||
| 343 | + PointerHolder<Buffer> b = p1.getBuffer(); | ||
| 344 | + qstream.replaceStreamData( | ||
| 345 | + b, QPDFObjectHandle::newName("/FlateDecode"), | ||
| 346 | + QPDFObjectHandle::newNull()); | ||
| 347 | + QPDFWriter w(pdf, "a.pdf"); | ||
| 348 | + w.setStaticID(true); | ||
| 349 | + w.setStreamDataMode(qpdf_s_preserve); | ||
| 350 | + w.write(); | ||
| 351 | + } | ||
| 312 | else | 352 | else |
| 313 | { | 353 | { |
| 314 | throw std::runtime_error(std::string("invalid test ") + | 354 | throw std::runtime_error(std::string("invalid test ") + |