aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pdf-custom-filter.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-25 18:32:45 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-25 19:21:23 +0100
commit3bdefb4c2df28167fbce6d4bc266f3256454bb98 (patch)
tree13d1ed0b3918a87f0277b5a2bf87312a6d42f151 /examples/pdf-custom-filter.cc
parent0f0f60109b77b59d281921c583d1277dd657b967 (diff)
downloadqpdf-3bdefb4c2df28167fbce6d4bc266f3256454bb98.tar.zst
Update examples to use copyStream()
Diffstat (limited to 'examples/pdf-custom-filter.cc')
-rw-r--r--examples/pdf-custom-filter.cc20
1 files changed, 6 insertions, 14 deletions
diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc
index 1426e5fc..55ace6e2 100644
--- a/examples/pdf-custom-filter.cc
+++ b/examples/pdf-custom-filter.cc
@@ -198,8 +198,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
// original stream data is no longer directly accessible. Trying
// to retrieve the stream data would be an infinite loop because
// it would just end up calling provideStreamData again. This is
- // why maybeReplace uses a stashed copy of the original stream
- // from the "other" QPDF object.
+ // why maybeReplace uses a stashed copy of the original stream.
// Additional explanation can be found in the method
// implementations.
@@ -223,11 +222,6 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
// we are replacing. We need this to create a new stream.
QPDF* pdf;
- // This second QPDF instance gives us a place to copy streams to
- // so that we can access the original stream data of the streams
- // whose data we are replacing.
- QPDF other;
-
// Map the object/generation in original file to the copied stream
// in "other". We use this to retrieve the original data.
std::map<QPDFObjGen, QPDFObjectHandle> copied_streams;
@@ -241,10 +235,6 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
StreamReplacer::StreamReplacer(QPDF* pdf) :
pdf(pdf)
{
- // Our "other" QPDF is just a place to stash streams. It doesn't
- // have to be a valid PDF with pages, etc. We are never going to
- // write this out.
- this->other.emptyPDF();
}
bool
@@ -375,9 +365,11 @@ StreamReplacer::registerStream(
if (should_replace)
{
- // Copy the stream to another QPDF object so we can get to the
- // original data from the stream data provider.
- this->copied_streams[og] = this->other.copyForeignObject(stream);
+ // Copy the stream so we can get to the original data from the
+ // stream data provider. This doesn't actually copy any data,
+ // but the copy retains the original stream data after the
+ // original one is modified.
+ this->copied_streams[og] = stream.copyStream();
// Update the stream dictionary with any changes.
auto dict = stream.getDict();
for (auto const& k: dict_updates.getKeys())