Commit e1560162f034c5087c4a5d5015b1dea95ab9a4d6
1 parent
a3e94eb4
Refactor: replace `isNull` calls with `null` and remove redundant `QTC::TC` call…
…s in `QPDFFormFieldObjectHelper`.
Showing
2 changed files
with
9 additions
and
29 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -25,7 +25,7 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() : | @@ -25,7 +25,7 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() : | ||
| 25 | bool | 25 | bool |
| 26 | QPDFFormFieldObjectHelper::isNull() | 26 | QPDFFormFieldObjectHelper::isNull() |
| 27 | { | 27 | { |
| 28 | - return oh().isNull(); | 28 | + return oh().null(); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | QPDFFormFieldObjectHelper | 31 | QPDFFormFieldObjectHelper |
| @@ -39,7 +39,7 @@ QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) | @@ -39,7 +39,7 @@ QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) | ||
| 39 | { | 39 | { |
| 40 | auto top_field = oh(); | 40 | auto top_field = oh(); |
| 41 | QPDFObjGen::set seen; | 41 | QPDFObjGen::set seen; |
| 42 | - while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").isNull()) { | 42 | + while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").null()) { |
| 43 | top_field = top_field.getKey("/Parent"); | 43 | top_field = top_field.getKey("/Parent"); |
| 44 | if (is_different) { | 44 | if (is_different) { |
| 45 | *is_different = true; | 45 | *is_different = true; |
| @@ -72,13 +72,12 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) | @@ -72,13 +72,12 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) | ||
| 72 | return QPDFObjectHandle::newNull(); | 72 | return QPDFObjectHandle::newNull(); |
| 73 | } | 73 | } |
| 74 | QPDFObjectHandle result(node.getKey(name)); | 74 | QPDFObjectHandle result(node.getKey(name)); |
| 75 | - if (result.isNull()) { | 75 | + if (result.null()) { |
| 76 | QPDFObjGen::set seen; | 76 | QPDFObjGen::set seen; |
| 77 | while (seen.add(node) && node.hasKey("/Parent")) { | 77 | while (seen.add(node) && node.hasKey("/Parent")) { |
| 78 | node = node.getKey("/Parent"); | 78 | node = node.getKey("/Parent"); |
| 79 | result = node.getKey(name); | 79 | result = node.getKey(name); |
| 80 | - if (!result.isNull()) { | ||
| 81 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper non-trivial inheritance"); | 80 | + if (!result.null()) { |
| 82 | return result; | 81 | return result; |
| 83 | } | 82 | } |
| 84 | } | 83 | } |
| @@ -118,10 +117,9 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName() | @@ -118,10 +117,9 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName() | ||
| 118 | std::string result; | 117 | std::string result; |
| 119 | QPDFObjectHandle node = oh(); | 118 | QPDFObjectHandle node = oh(); |
| 120 | QPDFObjGen::set seen; | 119 | QPDFObjGen::set seen; |
| 121 | - while (!node.isNull() && seen.add(node)) { | 120 | + while (!node.null() && seen.add(node)) { |
| 122 | if (node.getKey("/T").isString()) { | 121 | if (node.getKey("/T").isString()) { |
| 123 | if (!result.empty()) { | 122 | if (!result.empty()) { |
| 124 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper non-trivial qualified name"); | ||
| 125 | result = "." + result; | 123 | result = "." + result; |
| 126 | } | 124 | } |
| 127 | result = node.getKey("/T").getUTF8Value() + result; | 125 | result = node.getKey("/T").getUTF8Value() + result; |
| @@ -360,18 +358,17 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | @@ -360,18 +358,17 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | ||
| 360 | // is a member, set /AS to /Off. | 358 | // is a member, set /AS to /Off. |
| 361 | // Note that we never turn on /NeedAppearances when setting a radio button field. | 359 | // Note that we never turn on /NeedAppearances when setting a radio button field. |
| 362 | QPDFObjectHandle parent = oh().getKey("/Parent"); | 360 | QPDFObjectHandle parent = oh().getKey("/Parent"); |
| 363 | - if (parent.isDictionary() && parent.getKey("/Parent").isNull()) { | 361 | + if (parent.isDictionary() && parent.getKey("/Parent").null()) { |
| 364 | QPDFFormFieldObjectHelper ph(parent); | 362 | QPDFFormFieldObjectHelper ph(parent); |
| 365 | if (ph.isRadioButton()) { | 363 | if (ph.isRadioButton()) { |
| 366 | // This is most likely one of the individual buttons. Try calling on the parent. | 364 | // This is most likely one of the individual buttons. Try calling on the parent. |
| 367 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper set parent radio button"); | ||
| 368 | ph.setRadioButtonValue(name); | 365 | ph.setRadioButtonValue(name); |
| 369 | return; | 366 | return; |
| 370 | } | 367 | } |
| 371 | } | 368 | } |
| 372 | 369 | ||
| 373 | QPDFObjectHandle kids = oh().getKey("/Kids"); | 370 | QPDFObjectHandle kids = oh().getKey("/Kids"); |
| 374 | - if (!(isRadioButton() && parent.isNull() && kids.isArray())) { | 371 | + if (!(isRadioButton() && parent.null() && kids.isArray())) { |
| 375 | warn("don't know how to set the value of this field as a radio button"); | 372 | warn("don't know how to set the value of this field as a radio button"); |
| 376 | return; | 373 | return; |
| 377 | } | 374 | } |
| @@ -384,7 +381,6 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | @@ -384,7 +381,6 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | ||
| 384 | for (auto const& grandkid: kid.getKey("/Kids").as_array()) { | 381 | for (auto const& grandkid: kid.getKey("/Kids").as_array()) { |
| 385 | AP = grandkid.getKey("/AP"); | 382 | AP = grandkid.getKey("/AP"); |
| 386 | if (!AP.null()) { | 383 | if (!AP.null()) { |
| 387 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper radio button grandkid"); | ||
| 388 | annot = grandkid; | 384 | annot = grandkid; |
| 389 | break; | 385 | break; |
| 390 | } | 386 | } |
| @@ -393,16 +389,13 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | @@ -393,16 +389,13 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | ||
| 393 | annot = kid; | 389 | annot = kid; |
| 394 | } | 390 | } |
| 395 | if (!annot) { | 391 | if (!annot) { |
| 396 | - QTC::TC("qpdf", "QPDFObjectHandle broken radio button"); | ||
| 397 | warn("unable to set the value of this radio button"); | 392 | warn("unable to set the value of this radio button"); |
| 398 | continue; | 393 | continue; |
| 399 | } | 394 | } |
| 400 | if (AP.isDictionary() && AP.getKey("/N").isDictionary() && | 395 | if (AP.isDictionary() && AP.getKey("/N").isDictionary() && |
| 401 | AP.getKey("/N").hasKey(name.getName())) { | 396 | AP.getKey("/N").hasKey(name.getName())) { |
| 402 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper turn on radio button"); | ||
| 403 | annot.replaceKey("/AS", name); | 397 | annot.replaceKey("/AS", name); |
| 404 | } else { | 398 | } else { |
| 405 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper turn off radio button"); | ||
| 406 | annot.replaceKey("/AS", QPDFObjectHandle::newName("/Off")); | 399 | annot.replaceKey("/AS", QPDFObjectHandle::newName("/Off")); |
| 407 | } | 400 | } |
| 408 | } | 401 | } |
| @@ -749,7 +742,7 @@ void | @@ -749,7 +742,7 @@ void | ||
| 749 | QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) | 742 | QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) |
| 750 | { | 743 | { |
| 751 | QPDFObjectHandle AS = aoh.getAppearanceStream("/N"); | 744 | QPDFObjectHandle AS = aoh.getAppearanceStream("/N"); |
| 752 | - if (AS.isNull()) { | 745 | + if (AS.null()) { |
| 753 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AS from scratch"); | 746 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AS from scratch"); |
| 754 | QPDFObjectHandle::Rectangle rect = aoh.getRect(); | 747 | QPDFObjectHandle::Rectangle rect = aoh.getRect(); |
| 755 | QPDFObjectHandle::Rectangle bbox(0, 0, rect.urx - rect.llx, rect.ury - rect.lly); | 748 | QPDFObjectHandle::Rectangle bbox(0, 0, rect.urx - rect.llx, rect.ury - rect.lly); |
| @@ -759,8 +752,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | @@ -759,8 +752,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | ||
| 759 | AS = QPDFObjectHandle::newStream(oh().getOwningQPDF(), "/Tx BMC\nEMC\n"); | 752 | AS = QPDFObjectHandle::newStream(oh().getOwningQPDF(), "/Tx BMC\nEMC\n"); |
| 760 | AS.replaceDict(dict); | 753 | AS.replaceDict(dict); |
| 761 | QPDFObjectHandle AP = aoh.getAppearanceDictionary(); | 754 | QPDFObjectHandle AP = aoh.getAppearanceDictionary(); |
| 762 | - if (AP.isNull()) { | ||
| 763 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AP from scratch"); | 755 | + if (AP.null()) { |
| 764 | aoh.getObjectHandle().replaceKey("/AP", QPDFObjectHandle::newDictionary()); | 756 | aoh.getObjectHandle().replaceKey("/AP", QPDFObjectHandle::newDictionary()); |
| 765 | AP = aoh.getAppearanceDictionary(); | 757 | AP = aoh.getAppearanceDictionary(); |
| 766 | } | 758 | } |
| @@ -808,7 +800,6 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | @@ -808,7 +800,6 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | ||
| 808 | found_font_in_dr = font.isDictionary(); | 800 | found_font_in_dr = font.isDictionary(); |
| 809 | } | 801 | } |
| 810 | if (found_font_in_dr && resources.isDictionary()) { | 802 | if (found_font_in_dr && resources.isDictionary()) { |
| 811 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper get font from /DR"); | ||
| 812 | if (resources.isIndirect()) { | 803 | if (resources.isIndirect()) { |
| 813 | resources = resources.getQPDF().makeIndirectObject(resources.shallowCopy()); | 804 | resources = resources.getQPDF().makeIndirectObject(resources.shallowCopy()); |
| 814 | AS.getDict().replaceKey("/Resources", resources); | 805 | AS.getDict().replaceKey("/Resources", resources); |
| @@ -821,7 +812,6 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | @@ -821,7 +812,6 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao | ||
| 821 | if (font.isDictionary() && font.getKey("/Encoding").isName()) { | 812 | if (font.isDictionary() && font.getKey("/Encoding").isName()) { |
| 822 | std::string encoding = font.getKey("/Encoding").getName(); | 813 | std::string encoding = font.getKey("/Encoding").getName(); |
| 823 | if (encoding == "/WinAnsiEncoding") { | 814 | if (encoding == "/WinAnsiEncoding") { |
| 824 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper WinAnsi"); | ||
| 825 | encoder = &QUtil::utf8_to_win_ansi; | 815 | encoder = &QUtil::utf8_to_win_ansi; |
| 826 | } else if (encoding == "/MacRomanEncoding") { | 816 | } else if (encoding == "/MacRomanEncoding") { |
| 827 | encoder = &QUtil::utf8_to_mac_roman; | 817 | encoder = &QUtil::utf8_to_mac_roman; |
qpdf/qpdf.testcov
| @@ -300,8 +300,6 @@ QPDFObjectHandle erase array bounds 0 | @@ -300,8 +300,6 @@ QPDFObjectHandle erase array bounds 0 | ||
| 300 | qpdf-c called qpdf_check_pdf 0 | 300 | qpdf-c called qpdf_check_pdf 0 |
| 301 | QPDF xref loop 0 | 301 | QPDF xref loop 0 |
| 302 | QPDFParser too deep 0 | 302 | QPDFParser too deep 0 |
| 303 | -QPDFFormFieldObjectHelper non-trivial inheritance 0 | ||
| 304 | -QPDFFormFieldObjectHelper non-trivial qualified name 0 | ||
| 305 | QPDFFormFieldObjectHelper TU present 0 | 303 | QPDFFormFieldObjectHelper TU present 0 |
| 306 | QPDFFormFieldObjectHelper TM present 0 | 304 | QPDFFormFieldObjectHelper TM present 0 |
| 307 | QPDFFormFieldObjectHelper TU absent 0 | 305 | QPDFFormFieldObjectHelper TU absent 0 |
| @@ -349,12 +347,7 @@ QPDFObjectHandle replace with copy 0 | @@ -349,12 +347,7 @@ QPDFObjectHandle replace with copy 0 | ||
| 349 | QPDFPageDocumentHelper indirect as resources 0 | 347 | QPDFPageDocumentHelper indirect as resources 0 |
| 350 | QPDFAnnotationObjectHelper forbidden flags 0 | 348 | QPDFAnnotationObjectHelper forbidden flags 0 |
| 351 | QPDFAnnotationObjectHelper missing required flags 0 | 349 | QPDFAnnotationObjectHelper missing required flags 0 |
| 352 | -QPDFFormFieldObjectHelper set parent radio button 0 | ||
| 353 | -QPDFFormFieldObjectHelper radio button grandkid 0 | ||
| 354 | -QPDFFormFieldObjectHelper turn on radio button 0 | ||
| 355 | -QPDFFormFieldObjectHelper turn off radio button 0 | ||
| 356 | QPDFFormFieldObjectHelper checkbox kid widget 0 | 350 | QPDFFormFieldObjectHelper checkbox kid widget 0 |
| 357 | -QPDFObjectHandle broken radio button 0 | ||
| 358 | QPDFFormFieldObjectHelper set checkbox AS 0 | 351 | QPDFFormFieldObjectHelper set checkbox AS 0 |
| 359 | QPDFObjectHandle broken checkbox 0 | 352 | QPDFObjectHandle broken checkbox 0 |
| 360 | QPDFFormFieldObjectHelper list not found 0 | 353 | QPDFFormFieldObjectHelper list not found 0 |
| @@ -364,7 +357,6 @@ QPDFFormFieldObjectHelper list last too high 0 | @@ -364,7 +357,6 @@ QPDFFormFieldObjectHelper list last too high 0 | ||
| 364 | QPDFJob image optimize no pipeline 0 | 357 | QPDFJob image optimize no pipeline 0 |
| 365 | QPDFJob image optimize no shrink 0 | 358 | QPDFJob image optimize no shrink 0 |
| 366 | QPDFJob image optimize too small 0 | 359 | QPDFJob image optimize too small 0 |
| 367 | -QPDFFormFieldObjectHelper WinAnsi 0 | ||
| 368 | QPDF pipe foreign encrypted stream 0 | 360 | QPDF pipe foreign encrypted stream 0 |
| 369 | QPDF copy foreign stream with provider 0 | 361 | QPDF copy foreign stream with provider 0 |
| 370 | QPDF copy foreign stream with buffer 0 | 362 | QPDF copy foreign stream with buffer 0 |
| @@ -381,7 +373,6 @@ QPDFJob invalid utf-8 in auto 0 | @@ -381,7 +373,6 @@ QPDFJob invalid utf-8 in auto 0 | ||
| 381 | QPDFJob input password hex-bytes 0 | 373 | QPDFJob input password hex-bytes 0 |
| 382 | QPDFPageDocumentHelper ignore annotation with no appearance 0 | 374 | QPDFPageDocumentHelper ignore annotation with no appearance 0 |
| 383 | QPDFFormFieldObjectHelper create AS from scratch 0 | 375 | QPDFFormFieldObjectHelper create AS from scratch 0 |
| 384 | -QPDFFormFieldObjectHelper create AP from scratch 0 | ||
| 385 | QPDFFormFieldObjectHelper replaced BMC at EOF 0 | 376 | QPDFFormFieldObjectHelper replaced BMC at EOF 0 |
| 386 | QPDFFormFieldObjectHelper fallback Tf 0 | 377 | QPDFFormFieldObjectHelper fallback Tf 0 |
| 387 | QPDFPageObjectHelper non-trivial inheritance 0 | 378 | QPDFPageObjectHelper non-trivial inheritance 0 |
| @@ -508,7 +499,6 @@ QPDFAcroFormDocumentHelper modify ap matrix 0 | @@ -508,7 +499,6 @@ QPDFAcroFormDocumentHelper modify ap matrix 0 | ||
| 508 | QPDFJob pages keeping field from original 0 | 499 | QPDFJob pages keeping field from original 0 |
| 509 | QPDFObjectHandle merge reuse 0 | 500 | QPDFObjectHandle merge reuse 0 |
| 510 | QPDFObjectHandle merge generate 0 | 501 | QPDFObjectHandle merge generate 0 |
| 511 | -QPDFFormFieldObjectHelper get font from /DR 0 | ||
| 512 | QPDFAcroFormDocumentHelper replaced DA token 0 | 502 | QPDFAcroFormDocumentHelper replaced DA token 0 |
| 513 | QPDFAcroFormDocumentHelper /DA parse error 0 | 503 | QPDFAcroFormDocumentHelper /DA parse error 0 |
| 514 | QPDFAcroFormDocumentHelper AP parse error 1 | 504 | QPDFAcroFormDocumentHelper AP parse error 1 |