Commit 8d9b9a1a75a2d55344267bf21142dfa6fecaae37

Authored by m-holger
1 parent b6f5330d

Use QPDFObjectHandle::as_dictionary instead of ditems in library

libqpdf/QPDFAcroFormDocumentHelper.cc
1 1 #include <qpdf/QPDFAcroFormDocumentHelper.hh>
2 2  
3 3 #include <qpdf/Pl_Buffer.hh>
  4 +#include <qpdf/QPDFObjectHandle_private.hh>
4 5 #include <qpdf/QPDFPageDocumentHelper.hh>
5 6 #include <qpdf/QTC.hh>
6 7 #include <qpdf/QUtil.hh>
... ... @@ -975,17 +976,14 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
975 976 auto replace_stream = [](auto& dict, auto& key, auto& old) {
976 977 return dict.replaceKeyAndGetNew(key, old.copyStream());
977 978 };
978   - if (apdict.isDictionary()) {
979   - for (auto& ap: apdict.ditems()) {
980   - if (ap.second.isStream()) {
981   - streams.push_back(replace_stream(apdict, ap.first, ap.second));
982   - } else if (ap.second.isDictionary()) {
983   - for (auto& ap2: ap.second.ditems()) {
984   - if (ap2.second.isStream()) {
985   - streams.push_back(
986   - // line-break
987   - replace_stream(ap.second, ap2.first, ap2.second));
988   - }
  979 +
  980 + for (auto& [key1, value1]: apdict.as_dictionary()) {
  981 + if (value1.isStream()) {
  982 + streams.emplace_back(replace_stream(apdict, key1, value1));
  983 + } else {
  984 + for (auto& [key2, value2]: value1.as_dictionary()) {
  985 + if (value2.isStream()) {
  986 + streams.emplace_back(replace_stream(value1, key2, value2));
989 987 }
990 988 }
991 989 }
... ...
libqpdf/QPDFFormFieldObjectHelper.cc
... ... @@ -4,6 +4,7 @@
4 4 #include <qpdf/QIntC.hh>
5 5 #include <qpdf/QPDFAcroFormDocumentHelper.hh>
6 6 #include <qpdf/QPDFAnnotationObjectHelper.hh>
  7 +#include <qpdf/QPDFObjectHandle_private.hh>
7 8 #include <qpdf/QTC.hh>
8 9 #include <qpdf/QUtil.hh>
9 10 #include <cstdlib>
... ... @@ -442,13 +443,10 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
442 443 // Set the "on" value to the first value in the appearance stream's normal state dictionary
443 444 // that isn't /Off. If not found, fall back to /Yes.
444 445 if (AP.isDictionary()) {
445   - auto N = AP.getKey("/N");
446   - if (N.isDictionary()) {
447   - for (auto const& iter: N.ditems()) {
448   - if (iter.first != "/Off") {
449   - on_value = iter.first;
450   - break;
451   - }
  446 + for (auto const& item: AP.getKey("/N").as_dictionary()) {
  447 + if (item.first != "/Off") {
  448 + on_value = item.first;
  449 + break;
452 450 }
453 451 }
454 452 }
... ...
libqpdf/QPDFJob.cc
... ... @@ -917,10 +917,13 @@ QPDFJob::doListAttachments(QPDF&amp; pdf)
917 917 v << " " << i2.first << " -> " << i2.second << "\n";
918 918 }
919 919 v << " all data streams:\n";
920   - for (auto const& i2: efoh->getEmbeddedFileStreams().ditems()) {
921   - auto efs = QPDFEFStreamObjectHelper(i2.second);
922   - v << " " << i2.first << " -> "
923   - << efs.getObjectHandle().getObjGen().unparse(',') << "\n";
  920 + for (auto const& [key2, value2]: efoh->getEmbeddedFileStreams().as_dictionary()) {
  921 + if (value2.null()) {
  922 + continue;
  923 + }
  924 + auto efs = QPDFEFStreamObjectHelper(value2);
  925 + v << " " << key2 << " -> " << efs.getObjectHandle().getObjGen().unparse(',')
  926 + << "\n";
924 927 v << " creation date: " << efs.getCreationDate() << "\n"
925 928 << " modification date: " << efs.getModDate() << "\n"
926 929 << " mime type: " << efs.getSubtype() << "\n"
... ... @@ -1339,9 +1342,12 @@ QPDFJob::doJSONAttachments(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1339 1342 j_names.addDictionaryMember(i2.first, JSON::makeString(i2.second));
1340 1343 }
1341 1344 auto j_streams = j_details.addDictionaryMember("streams", JSON::makeDictionary());
1342   - for (auto const& i2: fsoh->getEmbeddedFileStreams().ditems()) {
1343   - auto efs = QPDFEFStreamObjectHelper(i2.second);
1344   - auto j_stream = j_streams.addDictionaryMember(i2.first, JSON::makeDictionary());
  1345 + for (auto const& [key2, value2]: fsoh->getEmbeddedFileStreams().as_dictionary()) {
  1346 + if (value2.null()) {
  1347 + continue;
  1348 + }
  1349 + auto efs = QPDFEFStreamObjectHelper(value2);
  1350 + auto j_stream = j_streams.addDictionaryMember(key2, JSON::makeDictionary());
1345 1351 j_stream.addDictionaryMember(
1346 1352 "creationdate", null_or_string(to_iso8601(efs.getCreationDate())));
1347 1353 j_stream.addDictionaryMember(
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -1141,19 +1141,10 @@ QPDFObjectHandle::isOrHasName(std::string const&amp; value) const
1141 1141 void
1142 1142 QPDFObjectHandle::makeResourcesIndirect(QPDF& owning_qpdf)
1143 1143 {
1144   - if (!isDictionary()) {
1145   - return;
1146   - }
1147   - for (auto const& i1: ditems()) {
1148   - QPDFObjectHandle sub = i1.second;
1149   - if (!sub.isDictionary()) {
1150   - continue;
1151   - }
1152   - for (auto const& i2: sub.ditems()) {
1153   - std::string const& key = i2.first;
1154   - QPDFObjectHandle val = i2.second;
1155   - if (!val.isIndirect()) {
1156   - sub.replaceKey(key, owning_qpdf.makeIndirectObject(val));
  1144 + for (auto const& i1: as_dictionary()) {
  1145 + for (auto& i2: i1.second.as_dictionary()) {
  1146 + if (!i2.second.null() && !i2.second.isIndirect()) {
  1147 + i2.second = owning_qpdf.makeIndirectObject(i2.second);
1157 1148 }
1158 1149 }
1159 1150 }
... ... @@ -1170,18 +1161,17 @@ QPDFObjectHandle::mergeResources(
1170 1161  
1171 1162 auto make_og_to_name = [](QPDFObjectHandle& dict,
1172 1163 std::map<QPDFObjGen, std::string>& og_to_name) {
1173   - for (auto const& i: dict.ditems()) {
1174   - if (i.second.isIndirect()) {
1175   - og_to_name[i.second.getObjGen()] = i.first;
  1164 + for (auto const& [key, value]: dict.as_dictionary()) {
  1165 + if (!value.null() && value.isIndirect()) {
  1166 + og_to_name.insert_or_assign(value.getObjGen(), key);
1176 1167 }
1177 1168 }
1178 1169 };
1179 1170  
1180 1171 // This algorithm is described in comments in QPDFObjectHandle.hh
1181 1172 // above the declaration of mergeResources.
1182   - for (auto const& o_top: other.ditems()) {
1183   - std::string const& rtype = o_top.first;
1184   - QPDFObjectHandle other_val = o_top.second;
  1173 + for (auto const& [rtype, value1]: other.as_dictionary()) {
  1174 + auto other_val = value1;
1185 1175 if (hasKey(rtype)) {
1186 1176 QPDFObjectHandle this_val = getKey(rtype);
1187 1177 if (this_val.isDictionary() && other_val.isDictionary()) {
... ... @@ -1196,9 +1186,8 @@ QPDFObjectHandle::mergeResources(
1196 1186 std::set<std::string> rnames;
1197 1187 int min_suffix = 1;
1198 1188 bool initialized_maps = false;
1199   - for (auto const& ov_iter: other_val.ditems()) {
1200   - std::string const& key = ov_iter.first;
1201   - QPDFObjectHandle rval = ov_iter.second;
  1189 + for (auto const& [key, value2]: other_val.as_dictionary()) {
  1190 + QPDFObjectHandle rval = value2;
1202 1191 if (!this_val.hasKey(key)) {
1203 1192 if (!rval.isIndirect()) {
1204 1193 QTC::TC("qpdf", "QPDFObjectHandle merge shallow copy");
... ...