aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFAcroFormDocumentHelper.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-30 02:21:07 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-30 02:28:02 +0200
commitd8fdf632a979a7adb4a6423fd55ef1971fb06afd (patch)
tree5a736f66733a3b4fa52f5519e1877d4841d3a8a3 /libqpdf/QPDFAcroFormDocumentHelper.cc
parente80fad86e95af978ada2a6cc5c4b209a1f65f7c0 (diff)
downloadqpdf-d8fdf632a979a7adb4a6423fd55ef1971fb06afd.tar.zst
Use replaceKeyAndGet in a few places in existing code
Diffstat (limited to 'libqpdf/QPDFAcroFormDocumentHelper.cc')
-rw-r--r--libqpdf/QPDFAcroFormDocumentHelper.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc
index 6d4b3b83..2bb52f44 100644
--- a/libqpdf/QPDFAcroFormDocumentHelper.cc
+++ b/libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -40,9 +40,9 @@ QPDFAcroFormDocumentHelper::getOrCreateAcroForm()
{
auto acroform = this->qpdf.getRoot().getKey("/AcroForm");
if (!acroform.isDictionary()) {
- acroform =
- this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
- this->qpdf.getRoot().replaceKey("/AcroForm", acroform);
+ acroform = this->qpdf.getRoot().replaceKeyAndGet(
+ "/AcroForm",
+ this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()));
}
return acroform;
}
@@ -53,8 +53,8 @@ QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff)
auto acroform = getOrCreateAcroForm();
auto fields = acroform.getKey("/Fields");
if (!fields.isArray()) {
- fields = QPDFObjectHandle::newArray();
- acroform.replaceKey("/Fields", fields);
+ fields =
+ acroform.replaceKeyAndGet("/Fields", QPDFObjectHandle::newArray());
}
fields.appendItem(ff.getObjectHandle());
std::set<QPDFObjGen> visited;
@@ -877,8 +877,8 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
}
dr.makeResourcesIndirect(this->qpdf);
if (!dr.isIndirect()) {
- dr = this->qpdf.makeIndirectObject(dr);
- acroform.replaceKey("/DR", dr);
+ dr = acroform.replaceKeyAndGet(
+ "/DR", this->qpdf.makeIndirectObject(dr));
}
// Merge the other document's /DR, creating a conflict
// map. mergeResources checks to make sure both objects
@@ -1099,9 +1099,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
auto apdict = ah.getAppearanceDictionary();
std::vector<QPDFObjectHandle> streams;
auto replace_stream = [](auto& dict, auto& key, auto& old) {
- auto new_stream = old.copyStream();
- dict.replaceKey(key, new_stream);
- return new_stream;
+ return dict.replaceKeyAndGet(key, old.copyStream());
};
if (apdict.isDictionary()) {
for (auto& ap : apdict.ditems()) {