Commit 4cfe44a4186b54494b7370e247295cd47a3fd158

Authored by m-holger
1 parent 78fc0d1b

Refactor `QPDF_Stream`: replace `getKey` and `getName` with `Name`, `Dictionary`…

…, and `Array` for improved clarity and consistency, and simplify `/Filter` and `/DecodeParms` handling.
Showing 1 changed file with 8 additions and 9 deletions
libqpdf/QPDF_Stream.cc
@@ -38,11 +38,10 @@ namespace @@ -38,11 +38,10 @@ namespace
38 setDecodeParms(QPDFObjectHandle decode_parms) final 38 setDecodeParms(QPDFObjectHandle decode_parms) final
39 { 39 {
40 // we only validate here - processing happens in decryptStream 40 // we only validate here - processing happens in decryptStream
41 - if (auto dict = decode_parms.as_dictionary(optional)) { 41 + if (Dictionary dict = decode_parms) {
42 for (auto const& [key, value]: dict) { 42 for (auto const& [key, value]: dict) {
43 if (key == "/Type" && 43 if (key == "/Type" &&
44 - (value.null() ||  
45 - (value.isName() && value.getName() == "/CryptFilterDecodeParms"))) { 44 + (value.null() || Name(value) == "/CryptFilterDecodeParms")) {
46 continue; 45 continue;
47 } 46 }
48 if (key == "/Name") { 47 if (key == "/Name") {
@@ -54,7 +53,7 @@ namespace @@ -54,7 +53,7 @@ namespace
54 } 53 }
55 return true; 54 return true;
56 } 55 }
57 - return false; 56 + return decode_parms.null();
58 } 57 }
59 58
60 Pipeline* 59 Pipeline*
@@ -374,7 +373,7 @@ Stream::filterable( @@ -374,7 +373,7 @@ Stream::filterable(
374 auto s = stream(); 373 auto s = stream();
375 // Check filters 374 // Check filters
376 375
377 - auto filter_obj = s->stream_dict.getKey("/Filter"); 376 + auto const& filter_obj = s->stream_dict["/Filter"];
378 377
379 if (filter_obj.null()) { 378 if (filter_obj.null()) {
380 // No filters 379 // No filters
@@ -387,14 +386,14 @@ Stream::filterable( @@ -387,14 +386,14 @@ Stream::filterable(
387 return false; 386 return false;
388 } 387 }
389 filters.emplace_back(ff()); 388 filters.emplace_back(ff());
390 - } else if (auto array = filter_obj.as_array(strict)) { 389 + } else if (Array array = filter_obj) {
391 // Potentially multiple filters 390 // Potentially multiple filters
392 - for (auto const& item: array) {  
393 - if (!item.isName()) { 391 + for (Name item: array) {
  392 + if (!item) {
394 warn("stream filter type is not name or array"); 393 warn("stream filter type is not name or array");
395 return false; 394 return false;
396 } 395 }
397 - auto ff = s->filter_factory(item.getName()); 396 + auto ff = s->filter_factory(item);
398 if (!ff) { 397 if (!ff) {
399 filters.clear(); 398 filters.clear();
400 return false; 399 return false;