Commit d8fdf632a979a7adb4a6423fd55ef1971fb06afd
1 parent
e80fad86
Use replaceKeyAndGet in a few places in existing code
Showing
7 changed files
with
21 additions
and
26 deletions
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -40,9 +40,9 @@ QPDFAcroFormDocumentHelper::getOrCreateAcroForm() | @@ -40,9 +40,9 @@ QPDFAcroFormDocumentHelper::getOrCreateAcroForm() | ||
| 40 | { | 40 | { |
| 41 | auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); | 41 | auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); |
| 42 | if (!acroform.isDictionary()) { | 42 | if (!acroform.isDictionary()) { |
| 43 | - acroform = | ||
| 44 | - this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); | ||
| 45 | - this->qpdf.getRoot().replaceKey("/AcroForm", acroform); | 43 | + acroform = this->qpdf.getRoot().replaceKeyAndGet( |
| 44 | + "/AcroForm", | ||
| 45 | + this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary())); | ||
| 46 | } | 46 | } |
| 47 | return acroform; | 47 | return acroform; |
| 48 | } | 48 | } |
| @@ -53,8 +53,8 @@ QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff) | @@ -53,8 +53,8 @@ QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff) | ||
| 53 | auto acroform = getOrCreateAcroForm(); | 53 | auto acroform = getOrCreateAcroForm(); |
| 54 | auto fields = acroform.getKey("/Fields"); | 54 | auto fields = acroform.getKey("/Fields"); |
| 55 | if (!fields.isArray()) { | 55 | if (!fields.isArray()) { |
| 56 | - fields = QPDFObjectHandle::newArray(); | ||
| 57 | - acroform.replaceKey("/Fields", fields); | 56 | + fields = |
| 57 | + acroform.replaceKeyAndGet("/Fields", QPDFObjectHandle::newArray()); | ||
| 58 | } | 58 | } |
| 59 | fields.appendItem(ff.getObjectHandle()); | 59 | fields.appendItem(ff.getObjectHandle()); |
| 60 | std::set<QPDFObjGen> visited; | 60 | std::set<QPDFObjGen> visited; |
| @@ -877,8 +877,8 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -877,8 +877,8 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 877 | } | 877 | } |
| 878 | dr.makeResourcesIndirect(this->qpdf); | 878 | dr.makeResourcesIndirect(this->qpdf); |
| 879 | if (!dr.isIndirect()) { | 879 | if (!dr.isIndirect()) { |
| 880 | - dr = this->qpdf.makeIndirectObject(dr); | ||
| 881 | - acroform.replaceKey("/DR", dr); | 880 | + dr = acroform.replaceKeyAndGet( |
| 881 | + "/DR", this->qpdf.makeIndirectObject(dr)); | ||
| 882 | } | 882 | } |
| 883 | // Merge the other document's /DR, creating a conflict | 883 | // Merge the other document's /DR, creating a conflict |
| 884 | // map. mergeResources checks to make sure both objects | 884 | // map. mergeResources checks to make sure both objects |
| @@ -1099,9 +1099,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -1099,9 +1099,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 1099 | auto apdict = ah.getAppearanceDictionary(); | 1099 | auto apdict = ah.getAppearanceDictionary(); |
| 1100 | std::vector<QPDFObjectHandle> streams; | 1100 | std::vector<QPDFObjectHandle> streams; |
| 1101 | auto replace_stream = [](auto& dict, auto& key, auto& old) { | 1101 | auto replace_stream = [](auto& dict, auto& key, auto& old) { |
| 1102 | - auto new_stream = old.copyStream(); | ||
| 1103 | - dict.replaceKey(key, new_stream); | ||
| 1104 | - return new_stream; | 1102 | + return dict.replaceKeyAndGet(key, old.copyStream()); |
| 1105 | }; | 1103 | }; |
| 1106 | if (apdict.isDictionary()) { | 1104 | if (apdict.isDictionary()) { |
| 1107 | for (auto& ap : apdict.ditems()) { | 1105 | for (auto& ap : apdict.ditems()) { |
libqpdf/QPDFEFStreamObjectHelper.cc
| @@ -28,8 +28,8 @@ QPDFEFStreamObjectHelper::setParam( | @@ -28,8 +28,8 @@ QPDFEFStreamObjectHelper::setParam( | ||
| 28 | { | 28 | { |
| 29 | auto params = this->oh.getDict().getKey("/Params"); | 29 | auto params = this->oh.getDict().getKey("/Params"); |
| 30 | if (!params.isDictionary()) { | 30 | if (!params.isDictionary()) { |
| 31 | - params = QPDFObjectHandle::newDictionary(); | ||
| 32 | - this->oh.getDict().replaceKey("/Params", params); | 31 | + params = this->oh.getDict().replaceKeyAndGet( |
| 32 | + "/Params", QPDFObjectHandle::newDictionary()); | ||
| 33 | } | 33 | } |
| 34 | params.replaceKey(pkey, pval); | 34 | params.replaceKey(pkey, pval); |
| 35 | } | 35 | } |
libqpdf/QPDFEmbeddedFileDocumentHelper.cc
| @@ -62,8 +62,8 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | @@ -62,8 +62,8 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | ||
| 62 | auto root = qpdf.getRoot(); | 62 | auto root = qpdf.getRoot(); |
| 63 | auto names = root.getKey("/Names"); | 63 | auto names = root.getKey("/Names"); |
| 64 | if (!names.isDictionary()) { | 64 | if (!names.isDictionary()) { |
| 65 | - names = QPDFObjectHandle::newDictionary(); | ||
| 66 | - root.replaceKey("/Names", names); | 65 | + names = |
| 66 | + root.replaceKeyAndGet("/Names", QPDFObjectHandle::newDictionary()); | ||
| 67 | } | 67 | } |
| 68 | auto embedded_files = names.getKey("/EmbeddedFiles"); | 68 | auto embedded_files = names.getKey("/EmbeddedFiles"); |
| 69 | if (!embedded_files.isDictionary()) { | 69 | if (!embedded_files.isDictionary()) { |
libqpdf/QPDFJob.cc
| @@ -1958,8 +1958,8 @@ QPDFJob::doUnderOverlayForPage( | @@ -1958,8 +1958,8 @@ QPDFJob::doUnderOverlayForPage( | ||
| 1958 | QPDFObjectHandle resources = dest_page.getAttribute("/Resources", true); | 1958 | QPDFObjectHandle resources = dest_page.getAttribute("/Resources", true); |
| 1959 | if (!resources.isDictionary()) { | 1959 | if (!resources.isDictionary()) { |
| 1960 | QTC::TC("qpdf", "QPDFJob overlay page with no resources"); | 1960 | QTC::TC("qpdf", "QPDFJob overlay page with no resources"); |
| 1961 | - resources = QPDFObjectHandle::newDictionary(); | ||
| 1962 | - dest_page.getObjectHandle().replaceKey("/Resources", resources); | 1961 | + resources = dest_page.getObjectHandle().replaceKeyAndGet( |
| 1962 | + "/Resources", QPDFObjectHandle::newDictionary()); | ||
| 1963 | } | 1963 | } |
| 1964 | for (std::vector<int>::iterator iter = pagenos[pageno].begin(); | 1964 | for (std::vector<int>::iterator iter = pagenos[pageno].begin(); |
| 1965 | iter != pagenos[pageno].end(); | 1965 | iter != pagenos[pageno].end(); |
libqpdf/QPDFObjectHandle.cc
| @@ -1172,8 +1172,7 @@ QPDFObjectHandle::mergeResources( | @@ -1172,8 +1172,7 @@ QPDFObjectHandle::mergeResources( | ||
| 1172 | // subdictionaries just to get this shallow copy | 1172 | // subdictionaries just to get this shallow copy |
| 1173 | // functionality. | 1173 | // functionality. |
| 1174 | QTC::TC("qpdf", "QPDFObjectHandle replace with copy"); | 1174 | QTC::TC("qpdf", "QPDFObjectHandle replace with copy"); |
| 1175 | - this_val = this_val.shallowCopy(); | ||
| 1176 | - replaceKey(rtype, this_val); | 1175 | + this_val = replaceKeyAndGet(rtype, this_val.shallowCopy()); |
| 1177 | } | 1176 | } |
| 1178 | std::map<QPDFObjGen, std::string> og_to_name; | 1177 | std::map<QPDFObjGen, std::string> og_to_name; |
| 1179 | std::set<std::string> rnames; | 1178 | std::set<std::string> rnames; |
libqpdf/QPDFPageObjectHelper.cc
| @@ -597,8 +597,7 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( | @@ -597,8 +597,7 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( | ||
| 597 | for (auto const& iter : to_filter) { | 597 | for (auto const& iter : to_filter) { |
| 598 | QPDFObjectHandle dict = resources.getKey(iter); | 598 | QPDFObjectHandle dict = resources.getKey(iter); |
| 599 | if (dict.isDictionary()) { | 599 | if (dict.isDictionary()) { |
| 600 | - dict = dict.shallowCopy(); | ||
| 601 | - resources.replaceKey(iter, dict); | 600 | + dict = resources.replaceKeyAndGet(iter, dict.shallowCopy()); |
| 602 | rdicts.push_back(dict); | 601 | rdicts.push_back(dict); |
| 603 | auto keys = dict.getKeys(); | 602 | auto keys = dict.getKeys(); |
| 604 | known_names.insert(keys.begin(), keys.end()); | 603 | known_names.insert(keys.begin(), keys.end()); |
| @@ -1113,8 +1112,8 @@ QPDFPageObjectHelper::copyAnnotations( | @@ -1113,8 +1112,8 @@ QPDFPageObjectHelper::copyAnnotations( | ||
| 1113 | afdh->addAndRenameFormFields(new_fields); | 1112 | afdh->addAndRenameFormFields(new_fields); |
| 1114 | auto annots = this->oh.getKey("/Annots"); | 1113 | auto annots = this->oh.getKey("/Annots"); |
| 1115 | if (!annots.isArray()) { | 1114 | if (!annots.isArray()) { |
| 1116 | - annots = QPDFObjectHandle::newArray(); | ||
| 1117 | - this->oh.replaceKey("/Annots", annots); | 1115 | + annots = |
| 1116 | + this->oh.replaceKeyAndGet("/Annots", QPDFObjectHandle::newArray()); | ||
| 1118 | } | 1117 | } |
| 1119 | for (auto const& annot : new_annots) { | 1118 | for (auto const& annot : new_annots) { |
| 1120 | annots.appendItem(annot); | 1119 | annots.appendItem(annot); |
libqpdf/QPDFWriter.cc
| @@ -1662,8 +1662,8 @@ QPDFWriter::unparseObject( | @@ -1662,8 +1662,8 @@ QPDFWriter::unparseObject( | ||
| 1662 | "qpdf", | 1662 | "qpdf", |
| 1663 | "QPDFWriter create Extensions", | 1663 | "QPDFWriter create Extensions", |
| 1664 | this->m->qdf_mode ? 0 : 1); | 1664 | this->m->qdf_mode ? 0 : 1); |
| 1665 | - extensions = QPDFObjectHandle::newDictionary(); | ||
| 1666 | - object.replaceKey("/Extensions", extensions); | 1665 | + extensions = object.replaceKeyAndGet( |
| 1666 | + "/Extensions", QPDFObjectHandle::newDictionary()); | ||
| 1667 | } | 1667 | } |
| 1668 | } else if (!have_extensions_other) { | 1668 | } else if (!have_extensions_other) { |
| 1669 | // We have Extensions dictionary and don't want one. | 1669 | // We have Extensions dictionary and don't want one. |
| @@ -2387,8 +2387,7 @@ QPDFWriter::prepareFileForWrite() | @@ -2387,8 +2387,7 @@ QPDFWriter::prepareFileForWrite() | ||
| 2387 | if (oh.isIndirect()) { | 2387 | if (oh.isIndirect()) { |
| 2388 | QTC::TC("qpdf", "QPDFWriter make Extensions direct"); | 2388 | QTC::TC("qpdf", "QPDFWriter make Extensions direct"); |
| 2389 | extensions_indirect = true; | 2389 | extensions_indirect = true; |
| 2390 | - oh = oh.shallowCopy(); | ||
| 2391 | - root.replaceKey(key, oh); | 2390 | + oh = root.replaceKeyAndGet(key, oh.shallowCopy()); |
| 2392 | } | 2391 | } |
| 2393 | if (oh.hasKey("/ADBE")) { | 2392 | if (oh.hasKey("/ADBE")) { |
| 2394 | QPDFObjectHandle adbe = oh.getKey("/ADBE"); | 2393 | QPDFObjectHandle adbe = oh.getKey("/ADBE"); |