Commit d9c46a5ec329079da7acee05a14cc97fa154d23e

Authored by m-holger
1 parent cfd17323

Refactor `QPDFAcroFormDocumentHelper::transformAnnotations`: update type handlin…

…g with `Dictionary` and `Array`.
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -992,17 +992,18 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
992 992 // Identify and copy any appearance streams
993 993  
994 994 auto ah = QPDFAnnotationObjectHelper(annot);
995   - auto apdict = ah.getAppearanceDictionary();
  995 + Dictionary apdict = ah.getAppearanceDictionary();
996 996 std::vector<QPDFObjectHandle> streams;
997 997 auto replace_stream = [](auto& dict, auto& key, auto& old) {
998   - return dict.replaceKeyAndGetNew(key, old.copyStream());
  998 + dict.replaceKey(key, old.copyStream());
  999 + return dict[key];
999 1000 };
1000 1001  
1001   - for (auto& [key1, value1]: apdict.as_dictionary()) {
  1002 + for (auto& [key1, value1]: apdict) {
1002 1003 if (value1.isStream()) {
1003 1004 streams.emplace_back(replace_stream(apdict, key1, value1));
1004 1005 } else {
1005   - for (auto& [key2, value2]: value1.as_dictionary()) {
  1006 + for (auto& [key2, value2]: Dictionary(value1)) {
1006 1007 if (value2.isStream()) {
1007 1008 streams.emplace_back(replace_stream(value1, key2, value2));
1008 1009 }
... ... @@ -1012,21 +1013,19 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
1012 1013  
1013 1014 // Now we can safely mutate the annotation and its appearance streams.
1014 1015 for (auto& stream: streams) {
1015   - auto dict = stream.getDict();
1016   - auto omatrix = dict["/Matrix"];
  1016 + Dictionary dict = stream.getDict();
  1017 +
1017 1018 QPDFMatrix apcm;
1018   - if (omatrix.isArray()) {
1019   - QTC::TC("qpdf", "QPDFAcroFormDocumentHelper modify ap matrix");
1020   - auto m1 = omatrix.getArrayAsMatrix();
1021   - apcm = QPDFMatrix(m1);
  1019 + Array omatrix = dict["/Matrix"];
  1020 + if (omatrix) {
  1021 + apcm = QPDFMatrix(QPDFObjectHandle(omatrix).getArrayAsMatrix());
1022 1022 }
1023 1023 apcm.concat(cm);
1024   - auto new_matrix = QPDFObjectHandle::newFromMatrix(apcm);
1025   - if (omatrix.isArray() || (apcm != QPDFMatrix())) {
1026   - dict.replaceKey("/Matrix", new_matrix);
  1024 + if (omatrix || apcm != QPDFMatrix()) {
  1025 + dict.replaceKey("/Matrix", QPDFObjectHandle::newFromMatrix(apcm));
1027 1026 }
1028   - auto resources = dict["/Resources"];
1029   - if ((!dr_map.empty()) && resources.isDictionary()) {
  1027 + Dictionary resources = dict["/Resources"];
  1028 + if (!dr_map.empty() && resources) {
1030 1029 adjustAppearanceStream(stream, dr_map);
1031 1030 }
1032 1031 }
... ...
qpdf/qpdf.testcov
... ... @@ -487,7 +487,6 @@ QPDFFileSpecObjectHelper empty compat_name 0
487 487 QPDFFileSpecObjectHelper non-empty compat_name 0
488 488 QPDFAcroFormDocumentHelper copy annotation 3
489 489 QPDFAcroFormDocumentHelper field with parent 3
490   -QPDFAcroFormDocumentHelper modify ap matrix 0
491 490 QPDFJob pages keeping field from original 0
492 491 QPDFObjectHandle merge reuse 0
493 492 QPDFObjectHandle merge generate 0
... ...