Commit bd7261da9b3735688e8dcaeefe21294a1d13afd6
1 parent
54303cea
getRawStreamData()
git-svn-id: svn+q:///qpdf/trunk@1010 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
12 changed files
with
176 additions
and
3 deletions
ChangeLog
TODO
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -216,6 +216,9 @@ class QPDFObjectHandle |
| 216 | 216 | // exception if the stream is filtered and we can't decode it. |
| 217 | 217 | QPDF_DLL |
| 218 | 218 | PointerHolder<Buffer> getStreamData(); |
| 219 | + // Returns unfiltered (raw) stream data. | |
| 220 | + QPDF_DLL | |
| 221 | + PointerHolder<Buffer> getRawStreamData(); | |
| 219 | 222 | |
| 220 | 223 | // Write stream data through the given pipeline. A null pipeline |
| 221 | 224 | // value may be used if all you want to do is determine whether a | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -343,6 +343,13 @@ QPDFObjectHandle::getStreamData() |
| 343 | 343 | return dynamic_cast<QPDF_Stream*>(obj.getPointer())->getStreamData(); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | +PointerHolder<Buffer> | |
| 347 | +QPDFObjectHandle::getRawStreamData() | |
| 348 | +{ | |
| 349 | + assertType("Stream", isStream()); | |
| 350 | + return dynamic_cast<QPDF_Stream*>(obj.getPointer())->getRawStreamData(); | |
| 351 | +} | |
| 352 | + | |
| 346 | 353 | bool |
| 347 | 354 | QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter, |
| 348 | 355 | bool normalize, bool compress) | ... | ... |
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -75,6 +75,16 @@ QPDF_Stream::getStreamData() |
| 75 | 75 | { |
| 76 | 76 | throw std::logic_error("getStreamData called on unfilterable stream"); |
| 77 | 77 | } |
| 78 | + QTC::TC("qpdf", "QPDF_Stream getStreamData"); | |
| 79 | + return buf.getBuffer(); | |
| 80 | +} | |
| 81 | + | |
| 82 | +PointerHolder<Buffer> | |
| 83 | +QPDF_Stream::getRawStreamData() | |
| 84 | +{ | |
| 85 | + Pl_Buffer buf("stream data buffer"); | |
| 86 | + pipeStreamData(&buf, false, false, false); | |
| 87 | + QTC::TC("qpdf", "QPDF_Stream getRawStreamData"); | |
| 78 | 88 | return buf.getBuffer(); |
| 79 | 89 | } |
| 80 | 90 | ... | ... |
libqpdf/qpdf/QPDF_Stream.hh
| ... | ... | @@ -22,6 +22,7 @@ class QPDF_Stream: public QPDFObject |
| 22 | 22 | bool pipeStreamData(Pipeline*, bool filter, |
| 23 | 23 | bool normalize, bool compress); |
| 24 | 24 | PointerHolder<Buffer> getStreamData(); |
| 25 | + PointerHolder<Buffer> getRawStreamData(); | |
| 25 | 26 | void replaceStreamData(PointerHolder<Buffer> data, |
| 26 | 27 | QPDFObjectHandle const& filter, |
| 27 | 28 | QPDFObjectHandle const& decode_parms); | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -2107,6 +2107,16 @@ print "\n"; |
| 2107 | 2107 | </listitem> |
| 2108 | 2108 | <listitem> |
| 2109 | 2109 | <para> |
| 2110 | + Add new method in <classname>QPDFObjectHandle</classname>: | |
| 2111 | + <function>getRawStreamData</function>, which returns the raw | |
| 2112 | + (unfiltered) stream data into a buffer. This complements the | |
| 2113 | + <function>getStreamData</function> method, which returns the | |
| 2114 | + filtered (uncompressed) stream data and can only be used when | |
| 2115 | + the stream's data is filterable. | |
| 2116 | + </para> | |
| 2117 | + </listitem> | |
| 2118 | + <listitem> | |
| 2119 | + <para> | |
| 2110 | 2120 | Provide two new examples: |
| 2111 | 2121 | <command>pdf-double-page-size</command> and |
| 2112 | 2122 | <command>pdf-invert-images</command> that illustrate the newly | ... | ... |
qpdf/qpdf.testcov
qpdf/qtest/qpdf.test
| ... | ... | @@ -111,7 +111,7 @@ $td->runtest("new stream", |
| 111 | 111 | show_ntests(); |
| 112 | 112 | # ---------- |
| 113 | 113 | $td->notify("--- Miscellaneous Tests ---"); |
| 114 | -$n_tests += 22; | |
| 114 | +$n_tests += 23; | |
| 115 | 115 | |
| 116 | 116 | $td->runtest("qpdf version", |
| 117 | 117 | {$td->COMMAND => "qpdf --version"}, |
| ... | ... | @@ -131,6 +131,11 @@ foreach (my $i = 1; $i <= 3; ++$i) |
| 131 | 131 | $td->NORMALIZE_NEWLINES); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | +$td->runtest("get stream data", | |
| 135 | + {$td->COMMAND => "test_driver 11 stream-data.pdf"}, | |
| 136 | + {$td->FILE => "test11.out", $td->EXIT_STATUS => 0}, | |
| 137 | + $td->NORMALIZE_NEWLINES); | |
| 138 | + | |
| 134 | 139 | # Make sure we ignore decode parameters that we don't understand |
| 135 | 140 | $td->runtest("unknown decode parameters", |
| 136 | 141 | {$td->COMMAND => "qpdf --check fax-decode-parms.pdf"}, | ... | ... |
qpdf/qtest/qpdf/stream-data.pdf
0 → 100644
| 1 | +%PDF-1.3 | |
| 2 | +%¿÷¢þ | |
| 3 | +%QDF-1.0 | |
| 4 | + | |
| 5 | +1 0 obj | |
| 6 | +<< | |
| 7 | + /Pages 2 0 R | |
| 8 | + /QStream 3 0 R | |
| 9 | + /Type /Catalog | |
| 10 | +>> | |
| 11 | +endobj | |
| 12 | + | |
| 13 | +2 0 obj | |
| 14 | +<< | |
| 15 | + /Count 1 | |
| 16 | + /Kids [ | |
| 17 | + 5 0 R | |
| 18 | + ] | |
| 19 | + /Type /Pages | |
| 20 | +>> | |
| 21 | +endobj | |
| 22 | + | |
| 23 | +3 0 obj | |
| 24 | +<< | |
| 25 | + /Length 4 0 R | |
| 26 | + /Filter /ASCIIHexDecode | |
| 27 | +>> | |
| 28 | +stream | |
| 29 | +706F7461746F0A | |
| 30 | +endstream | |
| 31 | +endobj | |
| 32 | + | |
| 33 | +4 0 obj | |
| 34 | +15 | |
| 35 | +endobj | |
| 36 | + | |
| 37 | +%% Page 1 | |
| 38 | +5 0 obj | |
| 39 | +<< | |
| 40 | + /Contents 6 0 R | |
| 41 | + /MediaBox [ | |
| 42 | + 0 | |
| 43 | + 0 | |
| 44 | + 612 | |
| 45 | + 792 | |
| 46 | + ] | |
| 47 | + /Parent 2 0 R | |
| 48 | + /Resources << | |
| 49 | + /Font << | |
| 50 | + /F1 8 0 R | |
| 51 | + >> | |
| 52 | + /ProcSet 9 0 R | |
| 53 | + >> | |
| 54 | + /Type /Page | |
| 55 | +>> | |
| 56 | +endobj | |
| 57 | + | |
| 58 | +%% Contents for page 1 | |
| 59 | +6 0 obj | |
| 60 | +<< | |
| 61 | + /Length 7 0 R | |
| 62 | +>> | |
| 63 | +stream | |
| 64 | +BT | |
| 65 | + /F1 24 Tf | |
| 66 | + 72 720 Td | |
| 67 | + (Potato) Tj | |
| 68 | +ET | |
| 69 | +endstream | |
| 70 | +endobj | |
| 71 | + | |
| 72 | +7 0 obj | |
| 73 | +44 | |
| 74 | +endobj | |
| 75 | + | |
| 76 | +8 0 obj | |
| 77 | +<< | |
| 78 | + /BaseFont /Helvetica | |
| 79 | + /Encoding /WinAnsiEncoding | |
| 80 | + /Name /F1 | |
| 81 | + /Subtype /Type1 | |
| 82 | + /Type /Font | |
| 83 | +>> | |
| 84 | +endobj | |
| 85 | + | |
| 86 | +9 0 obj | |
| 87 | +[ | |
| 88 | ||
| 89 | + /Text | |
| 90 | +] | |
| 91 | +endobj | |
| 92 | + | |
| 93 | +xref | |
| 94 | +0 10 | |
| 95 | +0000000000 65535 f | |
| 96 | +0000000025 00000 n | |
| 97 | +0000000096 00000 n | |
| 98 | +0000000168 00000 n | |
| 99 | +0000000264 00000 n | |
| 100 | +0000000293 00000 n | |
| 101 | +0000000508 00000 n | |
| 102 | +0000000607 00000 n | |
| 103 | +0000000626 00000 n | |
| 104 | +0000000744 00000 n | |
| 105 | +trailer << | |
| 106 | + /Root 1 0 R | |
| 107 | + /Size 10 | |
| 108 | + /ID [<422061d5d2701ad547ece6eb89b05b77><422061d5d2701ad547ece6eb89b05b77>] | |
| 109 | +>> | |
| 110 | +startxref | |
| 111 | +779 | |
| 112 | +%%EOF | ... | ... |
qpdf/qtest/qpdf/test11.out
0 → 100644
qpdf/test_driver.cc
| ... | ... | @@ -445,6 +445,23 @@ void runtest(int n, char const* filename) |
| 445 | 445 | w.setStreamDataMode(qpdf_s_preserve); |
| 446 | 446 | w.write(); |
| 447 | 447 | } |
| 448 | + else if (n == 11) | |
| 449 | + { | |
| 450 | + QPDFObjectHandle root = pdf.getRoot(); | |
| 451 | + QPDFObjectHandle qstream = root.getKey("/QStream"); | |
| 452 | + PointerHolder<Buffer> b1 = qstream.getStreamData(); | |
| 453 | + PointerHolder<Buffer> b2 = qstream.getRawStreamData(); | |
| 454 | + if ((b1.getPointer()->getSize() == 7) && | |
| 455 | + (memcmp(b1.getPointer()->getBuffer(), "potato\n", 7) == 0)) | |
| 456 | + { | |
| 457 | + std::cout << "filtered stream data okay" << std::endl; | |
| 458 | + } | |
| 459 | + if ((b2.getPointer()->getSize() == 15) && | |
| 460 | + (memcmp(b2.getPointer()->getBuffer(), "706F7461746F0A\n", 15) == 0)) | |
| 461 | + { | |
| 462 | + std::cout << "raw stream data okay" << std::endl; | |
| 463 | + } | |
| 464 | + } | |
| 448 | 465 | else |
| 449 | 466 | { |
| 450 | 467 | throw std::runtime_error(std::string("invalid test ") + | ... | ... |