From d77e3d7fa39427e71595293ab185f4d052cafe03 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 31 Aug 2025 13:40:19 +0100 Subject: [PATCH] Refactor: replace `isNull` calls with `null`, remove redundant `QTC::TC` calls in `QPDFPageDocumentHelper`, `QPDFPageObjectHelper` and `QPDFPageLabelDocumentHelper`. --- libqpdf/QPDFPageDocumentHelper.cc | 3 ++- libqpdf/QPDFPageLabelDocumentHelper.cc | 4 ++-- libqpdf/QPDFPageObjectHelper.cc | 17 +++++++---------- qpdf/qpdf.testcov | 3 --- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/libqpdf/QPDFPageDocumentHelper.cc b/libqpdf/QPDFPageDocumentHelper.cc index 3d0fbdb..154443e 100644 --- a/libqpdf/QPDFPageDocumentHelper.cc +++ b/libqpdf/QPDFPageDocumentHelper.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -127,7 +128,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( ++next_fx; } new_content += content; - } else if (process && !aoh.getAppearanceDictionary().isNull()) { + } else if (process && !aoh.getAppearanceDictionary().null()) { // If an annotation has no selected appearance stream, just drop the annotation when // flattening. This can happen for unchecked checkboxes and radio buttons, popup windows // associated with comments that aren't visible, and other types of annotations that diff --git a/libqpdf/QPDFPageLabelDocumentHelper.cc b/libqpdf/QPDFPageLabelDocumentHelper.cc index 54f8238..878c54e 100644 --- a/libqpdf/QPDFPageLabelDocumentHelper.cc +++ b/libqpdf/QPDFPageLabelDocumentHelper.cc @@ -1,6 +1,6 @@ #include -#include +#include class QPDFPageLabelDocumentHelper::Members { @@ -72,7 +72,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( // prior entry. If there is no entry for the first page, fabricate one that would match how the // page would look in a new file in which it also didn't have an explicit label. QPDFObjectHandle label = getLabelForPage(start_idx); - if (label.isNull()) { + if (label.null()) { label = QPDFObjectHandle::newDictionary(); label.replaceKey("/St", QPDFObjectHandle::newInteger(1 + new_start_idx)); } diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index 1a0098c..530247f 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -238,15 +238,14 @@ QPDFPageObjectHelper::getAttribute( auto dict = is_form_xobject ? oh().getDict() : oh(); auto result = dict.getKey(name); - if (!is_form_xobject && result.isNull() && + if (!is_form_xobject && result.null() && (name == "/MediaBox" || name == "/CropBox" || name == "/Resources" || name == "/Rotate")) { QPDFObjectHandle node = dict; QPDFObjGen::set seen{}; while (seen.add(node) && node.hasKey("/Parent")) { node = node.getKey("/Parent"); result = node.getKey(name); - if (!result.isNull()) { - QTC::TC("qpdf", "QPDFPageObjectHelper non-trivial inheritance"); + if (!result.null()) { inherited = true; break; } @@ -256,10 +255,9 @@ QPDFPageObjectHelper::getAttribute( QTC::TC("qpdf", "QPDFPageObjectHelper copy shared attribute", is_form_xobject ? 0 : 1); result = dict.replaceKeyAndGetNew(name, result.shallowCopy()); } - if (result.isNull() && get_fallback) { + if (result.null() && get_fallback) { result = get_fallback(); - if (copy_if_fallback && !result.isNull()) { - QTC::TC("qpdf", "QPDFPageObjectHelper copied fallback"); + if (copy_if_fallback && !result.null()) { result = dict.replaceKeyAndGetNew(name, result.shallowCopy()); } else { QTC::TC("qpdf", "QPDFPageObjectHelper used fallback without copying"); @@ -670,7 +668,7 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert) } QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false); - if (!(rotate_obj.isNull() && scale_obj.isNull())) { + if (!(rotate_obj.null() && scale_obj.null())) { QPDFObjectHandle::Rectangle rect = bbox.getArrayAsRectangle(); double width = rect.urx - rect.llx; double height = rect.ury - rect.lly; @@ -724,7 +722,7 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) result.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false); - if (handle_transformations && (!(rotate_obj.isNull() && scale_obj.isNull()))) { + if (handle_transformations && !(rotate_obj.null() && scale_obj.null())) { newdict.replaceKey("/Matrix", QPDFObjectHandle::newArray(getMatrixForTransformations())); } @@ -963,8 +961,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) oh().addPageContents(qpdf.newStream("\nQ\n"), false); oh().removeKey("/Rotate"); QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); - if (!rotate_obj.isNull()) { - QTC::TC("qpdf", "QPDFPageObjectHelper flatten inherit rotate"); + if (!rotate_obj.null()) { oh().replaceKey("/Rotate", QPDFObjectHandle::newInteger(0)); } diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index c3beb4e..7296c54 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -374,7 +374,6 @@ QPDFPageDocumentHelper ignore annotation with no appearance 0 QPDFFormFieldObjectHelper create AS from scratch 0 QPDFFormFieldObjectHelper replaced BMC at EOF 0 QPDFFormFieldObjectHelper fallback Tf 0 -QPDFPageObjectHelper non-trivial inheritance 0 QPDFPageObjectHelper copy shared attribute 1 QPDFJob from_nr from repeat_nr 0 QPDF resolve duplicated page object 0 @@ -491,7 +490,6 @@ QPDFPageObjectHelper unresolved names 0 QPDFPageObjectHelper resolving unresolved 0 QPDFFileSpecObjectHelper empty compat_name 0 QPDFFileSpecObjectHelper non-empty compat_name 0 -QPDFPageObjectHelper flatten inherit rotate 0 QPDFAcroFormDocumentHelper copy annotation 3 QPDFAcroFormDocumentHelper field with parent 3 QPDFAcroFormDocumentHelper modify ap matrix 0 @@ -587,7 +585,6 @@ QPDF_json missing json version 0 QPDF_json bad json version 0 QPDF_json bad calledgetallpages 0 QPDF_json bad pushedinheritedpageresources 0 -QPDFPageObjectHelper copied fallback 0 QPDFPageObjectHelper used fallback without copying 0 QPDF skipping cache for known unchecked object 0 QPDF fix dangling triggered xref reconstruction 0 -- libgit2 0.21.4