Clang-format //fpdfsdk Change-Id: Ice2153110672896a78526db973184ed00baf01c6 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130710 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_annot.cpp b/fpdfsdk/cpdfsdk_annot.cpp index b3afac1..b996b3b 100644 --- a/fpdfsdk/cpdfsdk_annot.cpp +++ b/fpdfsdk/cpdfsdk_annot.cpp
@@ -131,8 +131,9 @@ IPDF_Page* CPDFSDK_Annot::GetPage() { #ifdef PDF_ENABLE_XFA IPDF_Page* pXFAPage = GetXFAPage(); - if (pXFAPage) + if (pXFAPage) { return pXFAPage; + } #endif // PDF_ENABLE_XFA return GetPDFPage(); }
diff --git a/fpdfsdk/cpdfsdk_annotiteration.cpp b/fpdfsdk/cpdfsdk_annotiteration.cpp index 0ea37cc..c3460a8 100644 --- a/fpdfsdk/cpdfsdk_annotiteration.cpp +++ b/fpdfsdk/cpdfsdk_annotiteration.cpp
@@ -42,8 +42,9 @@ } list_.reserve(copied_list.size()); - for (auto* pAnnot : copied_list) + for (auto* pAnnot : copied_list) { list_.emplace_back(pAnnot); + } } CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() = default;
diff --git a/fpdfsdk/cpdfsdk_annotiterator.cpp b/fpdfsdk/cpdfsdk_annotiterator.cpp index d578957..6d85a9b 100644 --- a/fpdfsdk/cpdfsdk_annotiterator.cpp +++ b/fpdfsdk/cpdfsdk_annotiterator.cpp
@@ -78,8 +78,9 @@ for (auto* pAnnot : page_view_->GetAnnotList()) { if (pdfium::Contains(subtypes_, pAnnot->GetAnnotSubtype())) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); - if (!pWidget || !pWidget->IsSignatureWidget()) + if (!pWidget || !pWidget->IsSignatureWidget()) { pArray->emplace_back(pAnnot); + } } } } @@ -111,10 +112,12 @@ CPDFSDK_PageView* pPageView) { CPDF_Page* pPDFPage = pPageView->GetPDFPage(); ByteString sTabs = pPDFPage->GetDict()->GetByteStringFor("Tabs"); - if (sTabs == "R") + if (sTabs == "R") { return TabOrder::kRow; - if (sTabs == "C") + } + if (sTabs == "C") { return TabOrder::kColumn; + } return TabOrder::kStructure; } @@ -139,8 +142,9 @@ fTop = rcAnnot.top; } } - if (nLeftTopIndex < 0) + if (nLeftTopIndex < 0) { continue; + } CFX_FloatRect rcLeftTop = AddToAnnotsList(sa, nLeftTopIndex); @@ -148,8 +152,9 @@ for (size_t i = 0; i < sa.size(); ++i) { CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); float fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; - if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) + if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) { aSelect.push_back(i); + } } AddSelectedToAnnots(sa, aSelect); } @@ -174,8 +179,9 @@ fLeft = rcAnnot.left; } } - if (nLeftTopIndex < 0) + if (nLeftTopIndex < 0) { continue; + } CFX_FloatRect rcLeftTop = AddToAnnotsList(sa, nLeftTopIndex); @@ -183,8 +189,9 @@ for (size_t i = 0; i < sa.size(); ++i) { CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); float fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; - if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) + if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) { aSelect.push_back(i); + } } AddSelectedToAnnots(sa, aSelect); }
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp index b7b06ca..ae38af0 100644 --- a/fpdfsdk/cpdfsdk_appstream.cpp +++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -123,8 +123,9 @@ void WriteClosedLoop(fxcrt::ostringstream& stream, pdfium::span<const CFX_PointF> points) { WriteMove(stream, points[0]); - for (const auto& point : points.subspan(1)) + for (const auto& point : points.subspan(1)) { WriteLine(stream, point); + } WriteLine(stream, points[0]); } @@ -591,12 +592,14 @@ ByteString GetFontSetString(IPVT_FontMap* pFontMap, int32_t nFontIndex, float fFontSize) { - if (!pFontMap) + if (!pFontMap) { return ByteString(); + } ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); - if (sFontAlias.GetLength() <= 0 || fFontSize <= 0) + if (sFontAlias.GetLength() <= 0 || fFontSize <= 0) { return ByteString(); + } fxcrt::ostringstream sRet; sRet << "/" << sFontAlias << " " << fFontSize << " " @@ -605,8 +608,9 @@ } ByteString GetWordRenderString(ByteStringView strWords) { - if (strWords.IsEmpty()) + if (strWords.IsEmpty()) { return ByteString(); + } return PDF_EncodeString(strWords) + " " + kShowTextOperator + "\n"; } @@ -690,8 +694,9 @@ } } - if (!sWords.IsEmpty()) + if (!sWords.IsEmpty()) { sEditStream << GetWordRenderString(sWords.AsStringView()); + } fxcrt::ostringstream sAppStream; if (sEditStream.tellp() > 0) { @@ -703,20 +708,23 @@ ByteString GenerateIconAppStream(CPDF_IconFit& fit, RetainPtr<CPDF_Stream> pIconStream, const CFX_FloatRect& rcIcon) { - if (rcIcon.IsEmpty() || !pIconStream) + if (rcIcon.IsEmpty() || !pIconStream) { return ByteString(); + } CPWL_Wnd::CreateParams cp(nullptr, nullptr, nullptr); cp.dwFlags = PWS_VISIBLE; auto pWnd = std::make_unique<CPWL_Wnd>(cp, nullptr); pWnd->Realize(); - if (!pWnd->Move(rcIcon, false, false)) + if (!pWnd->Move(rcIcon, false, false)) { return ByteString(); + } auto pPDFIcon = std::make_unique<CPDF_Icon>(std::move(pIconStream)); ByteString sAlias = pPDFIcon->GetImageAlias(); - if (sAlias.GetLength() <= 0) + if (sAlias.GetLength() <= 0) { return ByteString(); + } const CFX_FloatRect rcPlate = pWnd->GetClientRect(); const CFX_SizeF image_size = pPDFIcon->GetImageSize(); @@ -760,10 +768,11 @@ pEdit->SetAlignmentV(1); pEdit->SetMultiLine(false); pEdit->SetAutoReturn(false); - if (FXSYS_IsFloatZero(fFontSize)) + if (FXSYS_IsFloatZero(fFontSize)) { pEdit->SetAutoFontSize(true); - else + } else { pEdit->SetFontSize(fFontSize); + } pEdit->Initialize(); pEdit->SetText(sLabel); @@ -921,8 +930,9 @@ } } - if (sTemp.tellp() <= 0) + if (sTemp.tellp() <= 0) { return ByteString(); + } fxcrt::ostringstream sAppStream; { @@ -1036,8 +1046,9 @@ } ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { - if (rcBBox.IsEmpty()) + if (rcBBox.IsEmpty()) { return ByteString(); + } fxcrt::ostringstream sAppStream; { @@ -1089,19 +1100,22 @@ } void SetDefaultIconName(CPDF_Stream* pIcon, const char* name) { - if (!pIcon) + if (!pIcon) { return; + } RetainPtr<CPDF_Dictionary> pImageDict = pIcon->GetMutableDict(); - if (pImageDict->KeyExist("Name")) + if (pImageDict->KeyExist("Name")) { return; + } pImageDict->SetNewFor<CPDF_String>("Name", name); } std::optional<CheckStyle> CheckStyleFromCaption(const WideString& caption) { - if (caption.IsEmpty()) + if (caption.IsEmpty()) { return std::nullopt; + } // Character values are ZapfDingbats encodings of named glyphs. switch (caption[0]) { @@ -1193,35 +1207,42 @@ float fFontSize; ByteString csNameTag; std::optional<ByteString> font = da.GetFont(&fFontSize); - if (font.has_value()) + if (font.has_value()) { csNameTag = font.value(); - else + } else { fFontSize = 12.0f; + } WideString csWCaption; WideString csNormalCaption; WideString csRolloverCaption; WideString csDownCaption; - if (pControl->HasMKEntry(pdfium::appearance::kCA)) + if (pControl->HasMKEntry(pdfium::appearance::kCA)) { csNormalCaption = pControl->GetNormalCaption(); + } - if (pControl->HasMKEntry(pdfium::appearance::kRC)) + if (pControl->HasMKEntry(pdfium::appearance::kRC)) { csRolloverCaption = pControl->GetRolloverCaption(); + } - if (pControl->HasMKEntry(pdfium::appearance::kAC)) + if (pControl->HasMKEntry(pdfium::appearance::kAC)) { csDownCaption = pControl->GetDownCaption(); + } RetainPtr<CPDF_Stream> pNormalIcon; RetainPtr<CPDF_Stream> pRolloverIcon; RetainPtr<CPDF_Stream> pDownIcon; - if (pControl->HasMKEntry(pdfium::appearance::kI)) + if (pControl->HasMKEntry(pdfium::appearance::kI)) { pNormalIcon = pControl->GetNormalIcon(); + } - if (pControl->HasMKEntry(pdfium::appearance::kRI)) + if (pControl->HasMKEntry(pdfium::appearance::kRI)) { pRolloverIcon = pControl->GetRolloverIcon(); + } - if (pControl->HasMKEntry(pdfium::appearance::kIX)) + if (pControl->HasMKEntry(pdfium::appearance::kIX)) { pDownIcon = pControl->GetDownIcon(); + } SetDefaultIconName(pNormalIcon.Get(), "ImgA"); SetDefaultIconName(pRolloverIcon.Get(), "ImgB"); @@ -1240,8 +1261,9 @@ crText, fFontSize, nLayout); Write("N", csAP, ByteString()); - if (pNormalIcon) + if (pNormalIcon) { AddImage("N", pNormalIcon.Get()); + } CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); if (eHLM != CPDF_FormControl::kPush && eHLM != CPDF_FormControl::kToggle) { @@ -1267,8 +1289,9 @@ csRolloverCaption, crText, fFontSize, nLayout); Write("R", csAP, ByteString()); - if (pRolloverIcon) + if (pRolloverIcon) { AddImage("R", pRolloverIcon.Get()); + } if (csDownCaption.IsEmpty() && !pDownIcon) { csDownCaption = csNormalCaption; @@ -1303,8 +1326,9 @@ crText, fFontSize, nLayout); Write("D", csAP, ByteString()); - if (pDownIcon) + if (pDownIcon) { AddImage("D", pDownIcon.Get()); + } } } @@ -1383,8 +1407,9 @@ Write("D", csAP_D_OFF, "Off"); ByteString csAS = widget_->GetAppState(); - if (csAS.IsEmpty()) + if (csAS.IsEmpty()) { widget_->SetAppStateOff(); + } } void CPDFSDK_AppStream::SetAsRadioButton() { @@ -1499,8 +1524,9 @@ Write("D", csAP_D_OFF, "Off"); ByteString csAS = widget_->GetAppState(); - if (csAS.IsEmpty()) + if (csAS.IsEmpty()) { widget_->SetAppStateOff(); + } } void CPDFSDK_AppStream::SetAsComboBox(std::optional<WideString> sValue) { @@ -1529,10 +1555,11 @@ pEdit->SetAlignmentV(1); float fFontSize = widget_->GetFontSize(); - if (FXSYS_IsFloatZero(fFontSize)) + if (FXSYS_IsFloatZero(fFontSize)) { pEdit->SetAutoFontSize(true); - else + } else { pEdit->SetFontSize(fFontSize); + } pEdit->Initialize(); if (sValue.has_value()) { @@ -1693,8 +1720,9 @@ float fFontSize = widget_->GetFontSize(); #ifdef PDF_ENABLE_XFA - if (!sValue.has_value() && widget_->GetMixXFAWidget()) + if (!sValue.has_value() && widget_->GetMixXFAWidget()) { sValue = widget_->GetValue(); + } #endif // PDF_ENABLE_XFA if (nMaxLen > 0) { @@ -1705,16 +1733,18 @@ font_map.GetPDFFont(0).Get(), rcClient, nMaxLen); } } else { - if (sValue.has_value()) + if (sValue.has_value()) { nMaxLen = pdfium::checked_cast<int>(sValue.value().GetLength()); + } pEdit->SetLimitChar(nMaxLen); } } - if (FXSYS_IsFloatZero(fFontSize)) + if (FXSYS_IsFloatZero(fFontSize)) { pEdit->SetAutoFontSize(true); - else + } else { pEdit->SetFontSize(fFontSize); + } pEdit->Initialize(); pEdit->SetText(sValue.value_or(pField->GetValue())); @@ -1862,8 +1892,9 @@ ByteString CPDFSDK_AppStream::GetBackgroundAppStream() const { CFX_Color crBackground = widget_->GetFillPWLColor(); - if (crBackground.nColorType != CFX_Color::Type::kTransparent) + if (crBackground.nColorType != CFX_Color::Type::kTransparent) { return GetRectFillAppStream(widget_->GetRotatedRect(), crBackground); + } return ByteString(); }
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp index 8dc763e..9d586cc 100644 --- a/fpdfsdk/cpdfsdk_baannot.cpp +++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -131,12 +131,14 @@ int CPDFSDK_BAAnnot::GetBorderWidth() const { RetainPtr<const CPDF_Array> pBorder = GetAnnotDict()->GetArrayFor(pdfium::annotation::kBorder); - if (pBorder) + if (pBorder) { return pBorder->GetIntegerAt(2); + } RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS"); - if (pBSDict) + if (pBSDict) { return pBSDict->GetIntegerFor("W", 1); + } return 1; } @@ -169,16 +171,21 @@ RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS"); if (pBSDict) { ByteString sBorderStyle = pBSDict->GetByteStringFor("S", "S"); - if (sBorderStyle == "S") + if (sBorderStyle == "S") { return BorderStyle::kSolid; - if (sBorderStyle == "D") + } + if (sBorderStyle == "D") { return BorderStyle::kDash; - if (sBorderStyle == "B") + } + if (sBorderStyle == "B") { return BorderStyle::kBeveled; - if (sBorderStyle == "I") + } + if (sBorderStyle == "I") { return BorderStyle::kInset; - if (sBorderStyle == "U") + } + if (sBorderStyle == "U") { return BorderStyle::kUnderline; + } } RetainPtr<const CPDF_Array> pBorder = @@ -186,8 +193,9 @@ if (pBorder) { if (pBorder->size() >= 4) { RetainPtr<const CPDF_Array> pDP = pBorder->GetArrayAt(3); - if (pDP && pDP->size() > 0) + if (pDP && pDP->size() > 0) { return BorderStyle::kDash; + } } } @@ -211,11 +219,13 @@ CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { CPDF_AAction AAction = GetAAction(); - if (AAction.ActionExist(eAAT)) + if (AAction.ActionExist(eAAT)) { return AAction.GetAction(eAAT); + } - if (eAAT == CPDF_AAction::kButtonUp || eAAT == CPDF_AAction::kKeyStroke) + if (eAAT == CPDF_AAction::kButtonUp || eAAT == CPDF_AAction::kKeyStroke) { return GetAction(); + } return CPDF_Action(nullptr); } @@ -229,20 +239,23 @@ rects.push_back(GetRect()); std::optional<CFX_FloatRect> annot_rect = annot_->GetPopupAnnotRect(); - if (annot_rect.has_value()) + if (annot_rect.has_value()) { rects.push_back(annot_rect.value()); + } // Make the rects round up to avoid https://crbug.com/662804 - for (CFX_FloatRect& rect : rects) + for (CFX_FloatRect& rect : rects) { rect.Inflate(1, 1); + } GetPageView()->UpdateRects(rects); } void CPDFSDK_BAAnnot::InvalidateRect() { CFX_FloatRect view_bounding_box = GetViewBBox(); - if (view_bounding_box.IsEmpty()) + if (view_bounding_box.IsEmpty()) { return; + } view_bounding_box.Inflate(1, 1); view_bounding_box.Normalize(); @@ -261,8 +274,9 @@ void CPDFSDK_BAAnnot::OnDraw(CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device, bool bDrawAnnots) { - if (!IsVisible()) + if (!IsVisible()) { return; + } const CPDF_Annot::Subtype annot_type = GetAnnotSubtype(); if (bDrawAnnots && annot_type == CPDF_Annot::Subtype::POPUP) { @@ -276,8 +290,9 @@ } CFX_FloatRect view_bounding_box = GetViewBBox(); - if (view_bounding_box.IsEmpty()) + if (view_bounding_box.IsEmpty()) { return; + } view_bounding_box.Normalize(); CFX_DrawUtils::DrawFocusRect(pDevice, mtUser2Device, view_bounding_box); @@ -361,8 +376,9 @@ } bool CPDFSDK_BAAnnot::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) { - if (!IsFocusableAnnot(GetAnnotSubtype())) + if (!IsFocusableAnnot(GetAnnotSubtype())) { return false; + } is_focused_ = true; InvalidateRect(); @@ -370,8 +386,9 @@ } bool CPDFSDK_BAAnnot::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) { - if (!IsFocusableAnnot(GetAnnotSubtype())) + if (!IsFocusableAnnot(GetAnnotSubtype())) { return false; + } is_focused_ = false; InvalidateRect();
diff --git a/fpdfsdk/cpdfsdk_customaccess.cpp b/fpdfsdk/cpdfsdk_customaccess.cpp index 3e70bae..3e4cf9d 100644 --- a/fpdfsdk/cpdfsdk_customaccess.cpp +++ b/fpdfsdk/cpdfsdk_customaccess.cpp
@@ -20,8 +20,9 @@ bool CPDFSDK_CustomAccess::ReadBlockAtOffset(pdfium::span<uint8_t> buffer, FX_FILESIZE offset) { - if (buffer.empty() || offset < 0) + if (buffer.empty() || offset < 0) { return false; + } if (!pdfium::IsValueInRangeForNumericType<FX_FILESIZE>(buffer.size())) { return false;
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 07ac1d5..a8fc001 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -93,8 +93,9 @@ void CPDFSDK_FormFillEnvironment::InvalidateRect(CPDFSDK_Widget* widget, const CFX_FloatRect& rect) { IPDF_Page* pPage = widget->GetPage(); - if (!pPage) + if (!pPage) { return; + } CFX_Matrix device2page = widget->GetPageView()->GetCurrentMatrix().GetInverse(); @@ -148,13 +149,15 @@ } int nRequiredLen = info_->FFI_GetLanguage(info_, nullptr, 0); - if (nRequiredLen <= 0) + if (nRequiredLen <= 0) { return WideString(); + } DataVector<uint8_t> pBuff(nRequiredLen); int nActualLen = info_->FFI_GetLanguage(info_, pBuff.data(), nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) + if (nActualLen <= 0 || nActualLen > nRequiredLen) { return WideString(); + } return WideString::FromUTF16LE( pdfium::make_span(pBuff).first(static_cast<size_t>(nActualLen))); @@ -170,13 +173,15 @@ } int nRequiredLen = info_->FFI_GetPlatform(info_, nullptr, 0); - if (nRequiredLen <= 0) + if (nRequiredLen <= 0) { return WideString(); + } DataVector<uint8_t> pBuff(nRequiredLen); int nActualLen = info_->FFI_GetPlatform(info_, pBuff.data(), nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) + if (nActualLen <= 0 || nActualLen > nRequiredLen) { return WideString(); + } return WideString::FromUTF16LE( pdfium::make_span(pBuff).first(static_cast<size_t>(nActualLen))); @@ -190,8 +195,9 @@ int Type, int Icon) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->app_alert) + if (!js_platform || !js_platform->app_alert) { return -1; + } ByteString bsMsg = Msg.ToUTF16LE(); ByteString bsTitle = Title.ToUTF16LE(); @@ -207,8 +213,9 @@ FPDF_BOOL bPassword, pdfium::span<uint8_t> response) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->app_response) + if (!js_platform || !js_platform->app_response) { return -1; + } ByteString bsQuestion = Question.ToUTF16LE(); ByteString bsTitle = Title.ToUTF16LE(); @@ -222,26 +229,30 @@ void CPDFSDK_FormFillEnvironment::JS_appBeep(int nType) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->app_beep) + if (!js_platform || !js_platform->app_beep) { return; + } js_platform->app_beep(js_platform, nType); } WideString CPDFSDK_FormFillEnvironment::JS_fieldBrowse() { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->Field_browse) + if (!js_platform || !js_platform->Field_browse) { return WideString(); + } const int nRequiredLen = js_platform->Field_browse(js_platform, nullptr, 0); - if (nRequiredLen <= 0) + if (nRequiredLen <= 0) { return WideString(); + } DataVector<uint8_t> pBuff(nRequiredLen); const int nActualLen = js_platform->Field_browse(js_platform, pBuff.data(), nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) + if (nActualLen <= 0 || nActualLen > nRequiredLen) { return WideString(); + } // Don't include trailing NUL. pBuff.resize(nActualLen - 1); @@ -259,8 +270,9 @@ const WideString& BCC, const WideString& Msg) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->Doc_mail) + if (!js_platform || !js_platform->Doc_mail) { return; + } ByteString bsTo = To.ToUTF16LE(); ByteString bsSubject = Subject.ToUTF16LE(); @@ -283,8 +295,9 @@ FPDF_BOOL bReverse, FPDF_BOOL bAnnotations) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->Doc_print) + if (!js_platform || !js_platform->Doc_print) { return; + } js_platform->Doc_print(js_platform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); @@ -292,8 +305,9 @@ void CPDFSDK_FormFillEnvironment::JS_docgotoPage(int nPageNum) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->Doc_gotoPage) + if (!js_platform || !js_platform->Doc_gotoPage) { return; + } js_platform->Doc_gotoPage(js_platform, nPageNum); } @@ -305,19 +319,22 @@ WideString CPDFSDK_FormFillEnvironment::GetFilePath() const { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->Doc_getFilePath) + if (!js_platform || !js_platform->Doc_getFilePath) { return WideString(); + } const int nRequiredLen = js_platform->Doc_getFilePath(js_platform, nullptr, 0); - if (nRequiredLen <= 0) + if (nRequiredLen <= 0) { return WideString(); + } DataVector<uint8_t> pBuff(nRequiredLen); const int nActualLen = js_platform->Doc_getFilePath(js_platform, pBuff.data(), nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) + if (nActualLen <= 0 || nActualLen > nRequiredLen) { return WideString(); + } // Don't include trailing NUL. pBuff.resize(nActualLen - 1); @@ -330,8 +347,9 @@ pdfium::span<const uint8_t> form_data, const WideString& URL) { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); - if (!js_platform || !js_platform->Doc_submitForm) + if (!js_platform || !js_platform->Doc_submitForm) { return; + } ByteString bsUrl = URL.ToUTF16LE(); js_platform->Doc_submitForm( @@ -628,8 +646,9 @@ if (it.second->IsValidSDKAnnot(GetFocusAnnot())) { ObservedPtr<CPDFSDK_PageView> pObserved(it.second.get()); KillFocusAnnot({}); - if (!pObserved) + if (!pObserved) { break; + } } } } @@ -637,8 +656,9 @@ CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetOrCreatePageView( IPDF_Page* pUnderlyingPage) { CPDFSDK_PageView* pExisting = GetPageView(pUnderlyingPage); - if (pExisting) + if (pExisting) { return pExisting; + } auto pNew = std::make_unique<CPDFSDK_PageView>(this, pUnderlyingPage); CPDFSDK_PageView* pPageView = pNew.get(); @@ -666,8 +686,9 @@ void CPDFSDK_FormFillEnvironment::ProcJavascriptAction() { auto name_tree = CPDF_NameTree::Create(cpdfdoc_, "JavaScript"); - if (!name_tree) + if (!name_tree) { return; + } size_t count = name_tree->GetCount(); for (size_t i = 0; i < count; ++i) { @@ -679,21 +700,26 @@ bool CPDFSDK_FormFillEnvironment::ProcOpenAction() { const CPDF_Dictionary* pRoot = cpdfdoc_->GetRoot(); - if (!pRoot) + if (!pRoot) { return false; + } RetainPtr<const CPDF_Object> pOpenAction(pRoot->GetDictFor("OpenAction")); - if (!pOpenAction) + if (!pOpenAction) { pOpenAction = pRoot->GetArrayFor("OpenAction"); - if (!pOpenAction) + } + if (!pOpenAction) { return false; + } - if (pOpenAction->IsArray()) + if (pOpenAction->IsArray()) { return true; + } RetainPtr<const CPDF_Dictionary> pDict = ToDictionary(pOpenAction); - if (!pDict) + if (!pDict) { return false; + } DoActionDocOpen(CPDF_Action(std::move(pDict))); return true; @@ -706,8 +732,9 @@ } CPDFSDK_PageView* pPageView = it->second.get(); - if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) + if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) { return; + } // Mark the page view so we do not come into |RemovePageView| a second // time while we're in the process of removing. @@ -718,8 +745,9 @@ // look for this page view in the map, if it doesn't find it a new one will // be created. We then have two page views pointing to the same page and // bad things happen. - if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) + if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) { KillFocusAnnot({}); + } // Remove the page from the map to make sure we don't accidentally attempt // to use the |pPageView| while we're cleaning it up. @@ -746,8 +774,9 @@ ObservedPtr<CPDFSDK_PageView> pObserved(it.second.get()); if (pObserved) { pObserved->UpdateView(pAnnot); - if (!pObserved) + if (!pObserved) { break; + } } } } @@ -767,10 +796,12 @@ if (focus_annot_ && !KillFocusAnnot({})) { return false; } - if (!pAnnot) + if (!pAnnot) { return false; - if (!pAnnot->GetPageView()->IsValid()) + } + if (!pAnnot->GetPageView()->IsValid()) { return false; + } if (focus_annot_) { return false; @@ -778,12 +809,14 @@ #ifdef PDF_ENABLE_XFA CPDFXFA_Widget* pXFAWidget = pAnnot->AsXFAWidget(); - if (pXFAWidget && pXFAWidget->OnChangedFocus()) + if (pXFAWidget && pXFAWidget->OnChangedFocus()) { return false; + } // `pAnnot` may be destroyed in `OnChangedFocus()`. - if (!pAnnot) + if (!pAnnot) { return false; + } #endif // PDF_ENABLE_XFA if (!CPDFSDK_Annot::OnSetFocus(pAnnot, {})) { @@ -814,8 +847,9 @@ } // Might have been destroyed by OnKillFocus(). - if (!pFocusAnnot) + if (!pFocusAnnot) { return false; + } if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { const FormFieldType field_type = @@ -844,16 +878,19 @@ } // TODO(crbug.com/pdfium/1482): Handle XFA case. - if (pAnnot->AsXFAWidget()) + if (pAnnot->AsXFAWidget()) { return; + } CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - if (!pPageView->IsValid()) + if (!pPageView->IsValid()) { return; + } IPDF_Page* page = pAnnot->GetPage(); - if (!page) + if (!page) { return; + } RetainPtr<CPDF_Dictionary> annot_dict = pAnnot->GetPDFAnnot()->GetMutableAnnotDict(); @@ -900,8 +937,9 @@ bool CPDFSDK_FormFillEnvironment::DoActionLink(const CPDF_Action& action, CPDF_AAction::AActionType type, Mask<FWL_EVENTFLAG> modifiers) { - if (!CPDF_AAction::IsUserInput(type)) + if (!CPDF_AAction::IsUserInput(type)) { return false; + } switch (action.GetType()) { case CPDF_Action::Type::kGoTo: @@ -950,16 +988,18 @@ const CPDF_Action& action, std::set<const CPDF_Dictionary*>* visited) { const CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::Contains(*visited, pDict)) + if (pdfium::Contains(*visited, pDict)) { return false; + } visited->insert(pDict); if (action.GetType() == CPDF_Action::Type::kJavaScript) { if (IsJSPlatformPresent()) { WideString swJS = action.GetJavaScript(); - if (!swJS.IsEmpty()) + if (!swJS.IsEmpty()) { RunDocumentOpenJavaScript(WideString(), swJS); + } } } else { DoActionNoJs(action, CPDF_AAction::AActionType::kDocumentOpen); @@ -967,8 +1007,9 @@ for (size_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteDocumentOpenAction(subaction, visited)) + if (!ExecuteDocumentOpenAction(subaction, visited)) { return false; + } } return true; @@ -979,16 +1020,18 @@ CPDF_AAction::AActionType type, std::set<const CPDF_Dictionary*>* visited) { const CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::Contains(*visited, pDict)) + if (pdfium::Contains(*visited, pDict)) { return false; + } visited->insert(pDict); if (action.GetType() == CPDF_Action::Type::kJavaScript) { if (IsJSPlatformPresent()) { WideString swJS = action.GetJavaScript(); - if (!swJS.IsEmpty()) + if (!swJS.IsEmpty()) { RunDocumentPageJavaScript(type, swJS); + } } } else { DoActionNoJs(action, type); @@ -996,8 +1039,9 @@ for (size_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteDocumentPageAction(subaction, type, visited)) + if (!ExecuteDocumentPageAction(subaction, type, visited)) { return false; + } } return true; @@ -1019,8 +1063,9 @@ CFFL_FieldAction* data, std::set<const CPDF_Dictionary*>* visited) { const CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::Contains(*visited, pDict)) + if (pdfium::Contains(*visited, pDict)) { return false; + } visited->insert(pDict); @@ -1029,8 +1074,9 @@ WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { RunFieldJavaScript(pFormField, type, data, swJS); - if (!IsValidField(pFormField->GetFieldDict())) + if (!IsValidField(pFormField->GetFieldDict())) { return false; + } } } } else { @@ -1039,8 +1085,9 @@ for (size_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteFieldAction(subaction, type, pFormField, data, visited)) + if (!ExecuteFieldAction(subaction, type, pFormField, data, visited)) { return false; + } } return true; @@ -1053,8 +1100,9 @@ DoActionGoTo(action); break; case CPDF_Action::Type::kURI: - if (CPDF_AAction::IsUserInput(type)) + if (CPDF_AAction::IsUserInput(type)) { DoActionURI(action, Mask<FWL_EVENTFLAG>{}); + } break; case CPDF_Action::Type::kHide: DoActionHide(action); @@ -1063,8 +1111,9 @@ DoActionNamed(action); break; case CPDF_Action::Type::kSubmitForm: - if (CPDF_AAction::IsUserInput(type)) + if (CPDF_AAction::IsUserInput(type)) { DoActionSubmitForm(action); + } break; case CPDF_Action::Type::kResetForm: DoActionResetForm(action);
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp index ef8d439..359f16b 100644 --- a/fpdfsdk/cpdfsdk_helpers.cpp +++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -45,19 +45,22 @@ UNSUPPORT_INFO* g_unsupport_info = nullptr; bool RaiseUnsupportedError(int nError) { - if (!g_unsupport_info) + if (!g_unsupport_info) { return false; + } - if (g_unsupport_info->FSDK_UnSupport_Handler) + if (g_unsupport_info->FSDK_UnSupport_Handler) { g_unsupport_info->FSDK_UnSupport_Handler(g_unsupport_info, nError); + } return true; } // Use the existence of the XFA array as a signal for XFA forms. bool DocHasXFA(const CPDF_Document* doc) { const CPDF_Dictionary* root = doc->GetRoot(); - if (!root) + if (!root) { return false; + } RetainPtr<const CPDF_Dictionary> form = root->GetDictFor("AcroForm"); return form && form->GetArrayFor("XFA"); @@ -69,10 +72,11 @@ bool decode) { DCHECK(stream); auto stream_acc = pdfium::MakeRetain<CPDF_StreamAcc>(std::move(stream)); - if (decode) + if (decode) { stream_acc->LoadAllDataFiltered(); - else + } else { stream_acc->LoadAllDataRaw(); + } pdfium::span<const uint8_t> stream_data_span = stream_acc->GetSpan(); if (!buffer.empty() && buffer.size() <= stream_data_span.size()) { @@ -314,8 +318,9 @@ DCHECK(quad_points); DCHECK(array); - if (!IsValidQuadPointsIndex(array, quad_index)) + if (!IsValidQuadPointsIndex(array, quad_index)) { return false; + } quad_index *= 8; quad_points->x1 = array->GetFloatAt(quad_index); @@ -384,10 +389,11 @@ switch (policy) { case FPDF_POLICY_MACHINETIME_ACCESS: { uint32_t mask = 1 << policy; - if (enable) + if (enable) { g_sandbox_policy |= mask; - else + } else { g_sandbox_policy &= ~mask; + } } break; default: break; @@ -411,17 +417,20 @@ void ReportUnsupportedFeatures(const CPDF_Document* pDoc) { const CPDF_Dictionary* pRootDict = pDoc->GetRoot(); - if (!pRootDict) + if (!pRootDict) { return; + } // Portfolios and Packages - if (pRootDict->KeyExist("Collection")) + if (pRootDict->KeyExist("Collection")) { RaiseUnsupportedError(FPDF_UNSP_DOC_PORTABLECOLLECTION); + } RetainPtr<const CPDF_Dictionary> pNameDict = pRootDict->GetDictFor("Names"); if (pNameDict) { - if (pNameDict->KeyExist("EmbeddedFiles")) + if (pNameDict->KeyExist("EmbeddedFiles")) { RaiseUnsupportedError(FPDF_UNSP_DOC_ATTACHMENT); + } RetainPtr<const CPDF_Dictionary> pJSDict = pNameDict->GetDictFor("JavaScript"); @@ -443,14 +452,16 @@ RetainPtr<const CPDF_Stream> pStream = pRootDict->GetStreamFor("Metadata"); if (pStream) { CPDF_Metadata metadata(std::move(pStream)); - for (const UnsupportedFeature& feature : metadata.CheckForSharedForm()) + for (const UnsupportedFeature& feature : metadata.CheckForSharedForm()) { RaiseUnsupportedError(static_cast<int>(feature)); + } } } void ReportUnsupportedXFA(const CPDF_Document* pDoc) { - if (!pDoc->GetExtension() && DocHasXFA(pDoc)) + if (!pDoc->GetExtension() && DocHasXFA(pDoc)) { RaiseUnsupportedError(FPDF_UNSP_DOC_XFAFORM); + } } void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot) { @@ -467,8 +478,9 @@ case CPDF_Annot::Subtype::SCREEN: { const CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); ByteString cbString = pAnnotDict->GetByteStringFor("IT"); - if (cbString != "Img") + if (cbString != "Img") { RaiseUnsupportedError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); + } break; } case CPDF_Annot::Subtype::SOUND: @@ -481,8 +493,9 @@ const CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); ByteString cbString = pAnnotDict->GetByteStringFor(pdfium::form_fields::kFT); - if (cbString == pdfium::form_fields::kSig) + if (cbString == pdfium::form_fields::kSig) { RaiseUnsupportedError(FPDF_UNSP_ANNOT_SIG); + } break; } default: @@ -531,8 +544,9 @@ uint32_t nCount) { ByteStringView alphabet(" 0123456789-,"); for (const auto& ch : bsPageRange) { - if (!alphabet.Contains(ch)) + if (!alphabet.Contains(ch)) { return std::vector<uint32_t>(); + } } ByteString bsStrippedPageRange = bsPageRange; @@ -545,22 +559,26 @@ // SAFETY: ByteStrings are always NUL-terminated. uint32_t page_num = pdfium::checked_cast<uint32_t>(UNSAFE_BUFFERS(atoi(args[0].c_str()))); - if (page_num == 0 || page_num > nCount) + if (page_num == 0 || page_num > nCount) { return std::vector<uint32_t>(); + } results.push_back(page_num - 1); } else if (args.size() == 2) { // SAFETY: ByteStrings are always NUL-terminated. uint32_t first_num = pdfium::checked_cast<uint32_t>(UNSAFE_BUFFERS(atoi(args[0].c_str()))); - if (first_num == 0) + if (first_num == 0) { return std::vector<uint32_t>(); + } // SAFETY: ByteStrings are always NUL-terminated. uint32_t last_num = pdfium::checked_cast<uint32_t>(UNSAFE_BUFFERS(atoi(args[1].c_str()))); - if (last_num == 0 || first_num > last_num || last_num > nCount) + if (last_num == 0 || first_num > last_num || last_num > nCount) { return std::vector<uint32_t>(); - for (uint32_t i = first_num; i <= last_num; ++i) + } + for (uint32_t i = first_num; i <= last_num; ++i) { results.push_back(i - 1); + } } else { return std::vector<uint32_t>(); }
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp index c91481c..0310b48 100644 --- a/fpdfsdk/cpdfsdk_interactiveform.cpp +++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -74,31 +74,36 @@ ByteString FDFToURLEncodedData(ByteString buffer) { std::unique_ptr<CFDF_Document> pFDF = CFDF_Document::ParseMemory(buffer.unsigned_span()); - if (!pFDF) + if (!pFDF) { return buffer; + } RetainPtr<const CPDF_Dictionary> pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); - if (!pMainDict) + if (!pMainDict) { return ByteString(); + } RetainPtr<const CPDF_Array> pFields = pMainDict->GetArrayFor("Fields"); - if (!pFields) + if (!pFields) { return ByteString(); + } fxcrt::ostringstream encoded_data; for (uint32_t i = 0; i < pFields->size(); i++) { RetainPtr<const CPDF_Dictionary> pField = pFields->GetDictAt(i); - if (!pField) + if (!pField) { continue; + } WideString name = pField->GetUnicodeTextFor("T"); ByteString name_b = name.ToDefANSI(); ByteString csBValue = pField->GetByteStringFor("V"); WideString csWValue = PDF_DecodeText(csBValue.unsigned_span()); ByteString csValue_b = csWValue.ToDefANSI(); encoded_data << name_b << "=" << csValue_b; - if (i != pFields->size() - 1) + if (i != pFields->size() - 1) { encoded_data << "&"; + } } return ByteString(encoded_data); @@ -119,16 +124,18 @@ CPDFSDK_Widget* CPDFSDK_InteractiveForm::GetWidget( CPDF_FormControl* pControl) const { - if (!pControl) + if (!pControl) { return nullptr; + } CPDFSDK_Widget* pWidget = nullptr; const auto it = map_.find(pControl); if (it != map_.end()) { pWidget = it->second; } - if (pWidget) + if (pWidget) { return pWidget; + } CPDF_Document* pDocument = form_fill_env_->GetPDFDocument(); CPDFSDK_PageView* pPage = nullptr; @@ -136,14 +143,16 @@ RetainPtr<const CPDF_Dictionary> pPageDict = pControlDict->GetDictFor("P"); if (pPageDict) { int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); - if (nPageIndex >= 0) + if (nPageIndex >= 0) { pPage = form_fill_env_->GetPageViewAtIndex(nPageIndex); + } } if (!pPage) { int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); - if (nPageIndex >= 0) + if (nPageIndex >= 0) { pPage = form_fill_env_->GetPageViewAtIndex(nPageIndex); + } } return pPage ? ToCPDFSDKWidget(pPage->GetAnnotByDict(pControlDict)) : nullptr; @@ -167,8 +176,9 @@ CPDF_FormControl* pFormCtrl = pField->GetControl(i); DCHECK(pFormCtrl); CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); - if (pWidget) + if (pWidget) { widgets->emplace_back(pWidget); + } } } @@ -180,17 +190,20 @@ for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { RetainPtr<const CPDF_Dictionary> pPageDict = pDocument->GetPageDictionary(i); - if (!pPageDict) + if (!pPageDict) { continue; + } RetainPtr<const CPDF_Array> pAnnots = pPageDict->GetArrayFor("Annots"); - if (!pAnnots) + if (!pAnnots) { continue; + } for (size_t j = 0, jsz = pAnnots->size(); j < jsz; j++) { RetainPtr<const CPDF_Object> pDict = pAnnots->GetDirectObjectAt(j); - if (pAnnotDict == pDict) + if (pAnnotDict == pDict) { return i; + } } } return -1; @@ -235,8 +248,9 @@ void CPDFSDK_InteractiveForm::SynchronizeField(CPDF_FormField* pFormField) { for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); - if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) + if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { pWidget->Synchronize(false); + } } } #endif // PDF_ENABLE_XFA @@ -253,31 +267,37 @@ AutoRestorer<bool> restorer(&busy_); busy_ = true; - if (!IsCalculateEnabled()) + if (!IsCalculateEnabled()) { return; + } IJS_Runtime* pRuntime = form_fill_env_->GetIJSRuntime(); int nSize = interactive_form_->CountFieldsInCalculationOrder(); for (int i = 0; i < nSize; i++) { CPDF_FormField* pField = interactive_form_->GetFieldInCalculationOrder(i); - if (!pField) + if (!pField) { continue; + } FormFieldType fieldType = pField->GetFieldType(); - if (!IsFormFieldTypeComboOrText(fieldType)) + if (!IsFormFieldTypeComboOrText(fieldType)) { continue; + } CPDF_AAction aAction = pField->GetAdditionalAction(); - if (!aAction.ActionExist(CPDF_AAction::kCalculate)) + if (!aAction.ActionExist(CPDF_AAction::kCalculate)) { continue; + } CPDF_Action action = aAction.GetAction(CPDF_AAction::kCalculate); - if (!action.HasDict()) + if (!action.HasDict()) { continue; + } WideString csJS = action.GetJavaScript(); - if (csJS.IsEmpty()) + if (csJS.IsEmpty()) { continue; + } WideString sOldValue = pField->GetValue(); WideString sValue = sOldValue; @@ -286,8 +306,9 @@ pContext->OnField_Calculate(pFormField, pField, &sValue, &bRC); std::optional<IJS_Runtime::JS_Error> err = pContext->RunScript(csJS); - if (!err.has_value() && bRC && sValue != sOldValue) + if (!err.has_value() && bRC && sValue != sOldValue) { pField->SetValue(sValue, NotificationOption::kNotify); + } } } @@ -302,8 +323,9 @@ if (pFormField->GetFieldType() == FormFieldType::kComboBox && pFormField->CountSelectedItems() > 0) { int index = pFormField->GetSelectedIndex(0); - if (index >= 0) + if (index >= 0) { sValue = pFormField->GetOptionLabel(index); + } } CPDF_AAction aAction = pFormField->GetAdditionalAction(); @@ -315,8 +337,9 @@ IJS_Runtime::ScopedEventContext pContext(pRuntime); pContext->OnField_Format(pFormField, &sValue); std::optional<IJS_Runtime::JS_Error> err = pContext->RunScript(script); - if (!err.has_value()) + if (!err.has_value()) { return sValue; + } } } } @@ -329,8 +352,9 @@ for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); DCHECK(pFormCtrl); - if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) + if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { pWidget->ResetAppearance(sValue, CPDFSDK_Widget::kValueChanged); + } } } @@ -341,8 +365,9 @@ DCHECK(pFormCtrl); CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); - if (!pWidget) + if (!pWidget) { continue; + } IPDF_Page* pPage = pWidget->GetPage(); FX_RECT rect = @@ -354,12 +379,14 @@ bool CPDFSDK_InteractiveForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue) { CPDF_AAction aAction = pFormField->GetAdditionalAction(); - if (!aAction.ActionExist(CPDF_AAction::kKeyStroke)) + if (!aAction.ActionExist(CPDF_AAction::kKeyStroke)) { return true; + } CPDF_Action action = aAction.GetAction(CPDF_AAction::kKeyStroke); - if (!action.HasDict()) + if (!action.HasDict()) { return true; + } CFFL_FieldAction fa; fa.bModifier = false; @@ -373,12 +400,14 @@ bool CPDFSDK_InteractiveForm::OnValidate(CPDF_FormField* pFormField, const WideString& csValue) { CPDF_AAction aAction = pFormField->GetAdditionalAction(); - if (!aAction.ActionExist(CPDF_AAction::kValidate)) + if (!aAction.ActionExist(CPDF_AAction::kValidate)) { return true; + } CPDF_Action action = aAction.GetAction(CPDF_AAction::kValidate); - if (!action.HasDict()) + if (!action.HasDict()) { return true; + } CFFL_FieldAction fa; fa.bModifier = false; @@ -405,10 +434,11 @@ uint32_t nFlags = pWidget->GetFlags(); nFlags &= ~pdfium::annotation_flags::kInvisible; nFlags &= ~pdfium::annotation_flags::kNoView; - if (bHide) + if (bHide) { nFlags |= pdfium::annotation_flags::kHidden; - else + } else { nFlags &= ~pdfium::annotation_flags::kHidden; + } pWidget->SetFlags(nFlags); pWidget->GetPageView()->UpdateView(pWidget); bChanged = true; @@ -421,8 +451,9 @@ bool CPDFSDK_InteractiveForm::DoAction_SubmitForm(const CPDF_Action& action) { WideString sDestination = action.GetFilePath(); - if (sDestination.IsEmpty()) + if (sDestination.IsEmpty()) { return false; + } if (action.HasFields()) { uint32_t dwFlags = action.GetFlags(); @@ -450,13 +481,15 @@ bool bIncludeOrExclude, bool bUrlEncoded) { ByteString text_buf = ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude); - if (text_buf.IsEmpty()) + if (text_buf.IsEmpty()) { return false; + } if (bUrlEncoded) { text_buf = FDFToURLEncodedData(text_buf); - if (text_buf.IsEmpty()) + if (text_buf.IsEmpty()) { return false; + } } form_fill_env_->SubmitForm(text_buf.unsigned_span(), csDestination); @@ -473,17 +506,20 @@ } bool CPDFSDK_InteractiveForm::SubmitForm(const WideString& sDestination) { - if (sDestination.IsEmpty()) + if (sDestination.IsEmpty()) { return false; + } std::unique_ptr<CFDF_Document> pFDFDoc = interactive_form_->ExportToFDF(form_fill_env_->GetFilePath()); - if (!pFDFDoc) + if (!pFDFDoc) { return false; + } ByteString fdf_buffer = pFDFDoc->WriteToString(); - if (fdf_buffer.IsEmpty()) + if (fdf_buffer.IsEmpty()) { return false; + } form_fill_env_->SubmitForm(fdf_buffer.unsigned_span(), sDestination); return true; @@ -512,13 +548,15 @@ const std::vector<RetainPtr<const CPDF_Object>>& objects) const { std::vector<CPDF_FormField*> fields; for (const CPDF_Object* pObject : objects) { - if (!pObject || !pObject->IsString()) + if (!pObject || !pObject->IsString()) { continue; + } WideString csName = pObject->GetUnicodeText(); CPDF_FormField* pField = interactive_form_->GetField(0, csName); - if (pField) + if (pField) { fields.push_back(pField); + } } return fields; } @@ -526,10 +564,12 @@ bool CPDFSDK_InteractiveForm::BeforeValueChange(CPDF_FormField* pField, const WideString& csValue) { FormFieldType fieldType = pField->GetFieldType(); - if (!IsFormFieldTypeComboOrText(fieldType)) + if (!IsFormFieldTypeComboOrText(fieldType)) { return true; - if (!OnKeyStrokeCommit(pField, csValue)) + } + if (!OnKeyStrokeCommit(pField, csValue)) { return false; + } return OnValidate(pField, csValue); } @@ -539,8 +579,9 @@ #endif // PDF_ENABLE_XFA FormFieldType fieldType = pField->GetFieldType(); - if (!IsFormFieldTypeComboOrText(fieldType)) + if (!IsFormFieldTypeComboOrText(fieldType)) { return; + } OnCalculate(pField); ResetFieldAppearance(pField, OnFormat(pField)); @@ -549,16 +590,19 @@ bool CPDFSDK_InteractiveForm::BeforeSelectionChange(CPDF_FormField* pField, const WideString& csValue) { - if (pField->GetFieldType() != FormFieldType::kListBox) + if (pField->GetFieldType() != FormFieldType::kListBox) { return true; - if (!OnKeyStrokeCommit(pField, csValue)) + } + if (!OnKeyStrokeCommit(pField, csValue)) { return false; + } return OnValidate(pField, csValue); } void CPDFSDK_InteractiveForm::AfterSelectionChange(CPDF_FormField* pField) { - if (pField->GetFieldType() != FormFieldType::kListBox) + if (pField->GetFieldType() != FormFieldType::kListBox) { return; + } OnCalculate(pField); ResetFieldAppearance(pField, std::nullopt); @@ -568,8 +612,9 @@ void CPDFSDK_InteractiveForm::AfterCheckedStatusChange(CPDF_FormField* pField) { FormFieldType fieldType = pField->GetFieldType(); if (fieldType != FormFieldType::kCheckBox && - fieldType != FormFieldType::kRadioButton) + fieldType != FormFieldType::kRadioButton) { return; + } OnCalculate(pField); UpdateField(pField); @@ -580,8 +625,9 @@ } bool CPDFSDK_InteractiveForm::IsNeedHighLight(FormFieldType fieldType) const { - if (fieldType == FormFieldType::kUnknown) + if (fieldType == FormFieldType::kUnknown) { return false; + } #ifdef PDF_ENABLE_XFA // For the XFA fields, we need to return if the specific field type has @@ -603,8 +649,9 @@ void CPDFSDK_InteractiveForm::SetHighlightColor(FX_COLORREF clr, FormFieldType fieldType) { - if (fieldType == FormFieldType::kUnknown) + if (fieldType == FormFieldType::kUnknown) { return; + } highlight_color_[static_cast<size_t>(fieldType)] = clr; needs_highlight_[static_cast<size_t>(fieldType)] = true; @@ -619,8 +666,9 @@ FX_COLORREF CPDFSDK_InteractiveForm::GetHighlightColor( FormFieldType fieldType) { - if (fieldType == FormFieldType::kUnknown) + if (fieldType == FormFieldType::kUnknown) { return kWhiteBGR; + } #ifdef PDF_ENABLE_XFA // For the XFA fields, we need to return the specific field type highlight
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index 167be65..331cada 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -41,8 +41,9 @@ CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); pPDFForm->FixPageFields(pPDFPage); - if (!page->AsXFAPage()) + if (!page->AsXFAPage()) { pPDFPage->SetView(this); + } } } @@ -65,8 +66,9 @@ } void CPDFSDK_PageView::ClearPage(CPDF_Page* pPage) { - if (!IsBeingDestroyed()) + if (!IsBeingDestroyed()) { GetFormFillEnv()->RemovePageView(pPage); + } } void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, @@ -100,19 +102,22 @@ CPDF_InteractiveForm* pdf_form = form->GetInteractiveForm(); CPDF_FormControl* form_control = pdf_form->GetControlByDict(annot->GetAnnotDict()); - if (!form_control) + if (!form_control) { return nullptr; + } auto ret = std::make_unique<CPDFSDK_Widget>(annot, this, form); form->AddMap(form_control, ret.get()); - if (pdf_form->NeedConstructAP()) + if (pdf_form->NeedConstructAP()) { ret->ResetAppearance(std::nullopt, CPDFSDK_Widget::kValueUnchanged); + } return ret; } #ifdef PDF_ENABLE_XFA - if (sub_type == CPDF_Annot::Subtype::XFAWIDGET) + if (sub_type == CPDF_Annot::Subtype::XFAWIDGET) { return nullptr; + } #endif // PDF_ENABLE_XFA return std::make_unique<CPDFSDK_BAAnnot>(annot, this); @@ -122,10 +127,12 @@ CPDFSDK_AnnotIteration annot_iteration(this); for (const auto& pSDKAnnot : annot_iteration) { CFX_FloatRect rc = pSDKAnnot->GetViewBBox(); - if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) + if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) { continue; - if (rc.Contains(point)) + } + if (rc.Contains(point)) { return pSDKAnnot.Get(); + } } return nullptr; } @@ -138,8 +145,9 @@ #ifdef PDF_ENABLE_XFA do_hit_test = do_hit_test || sub_type == CPDF_Annot::Subtype::XFAWIDGET; #endif // PDF_ENABLE_XFA - if (do_hit_test && pSDKAnnot->DoHitTest(point)) + if (do_hit_test && pSDKAnnot->DoHitTest(point)) { return pSDKAnnot.Get(); + } } return nullptr; } @@ -147,8 +155,9 @@ #ifdef PDF_ENABLE_XFA CPDFSDK_Annot* CPDFSDK_PageView::AddAnnotForFFWidget(CXFA_FFWidget* pWidget) { CPDFSDK_Annot* pSDKAnnot = GetAnnotForFFWidget(pWidget); - if (pSDKAnnot) + if (pSDKAnnot) { return pSDKAnnot; + } sdkannot_array_.push_back(std::make_unique<CPDFXFA_Widget>(pWidget, this)); return sdkannot_array_.back().get(); @@ -213,21 +222,24 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(const CPDF_Dictionary* pDict) { for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : sdkannot_array_) { CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); - if (pPDFAnnot && pPDFAnnot->GetAnnotDict() == pDict) + if (pPDFAnnot && pPDFAnnot->GetAnnotDict() == pDict) { return pAnnot.get(); + } } return nullptr; } #ifdef PDF_ENABLE_XFA CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotForFFWidget(CXFA_FFWidget* pWidget) { - if (!pWidget) + if (!pWidget) { return nullptr; + } for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : sdkannot_array_) { CPDFXFA_Widget* pCurrentWidget = pAnnot->AsXFAWidget(); - if (pCurrentWidget && pCurrentWidget->GetXFAFFWidget() == pWidget) + if (pCurrentWidget && pCurrentWidget->GetXFAFFWidget() == pWidget) { return pAnnot.get(); + } } return nullptr; } @@ -245,8 +257,9 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetNextAnnot(CPDFSDK_Annot* pAnnot) { #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage(); - if (pXFAPage) + if (pXFAPage) { return pXFAPage->GetNextXFAAnnot(pAnnot); + } #endif // PDF_ENABLE_XFA CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes()); return ai.GetNextAnnot(pAnnot); @@ -255,8 +268,9 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetPrevAnnot(CPDFSDK_Annot* pAnnot) { #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage(); - if (pXFAPage) + if (pXFAPage) { return pXFAPage->GetPrevXFAAnnot(pAnnot); + } #endif // PDF_ENABLE_XFA CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes()); return ai.GetPrevAnnot(pAnnot); @@ -265,8 +279,9 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFirstFocusableAnnot() { #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage(); - if (pXFAPage) + if (pXFAPage) { return pXFAPage->GetFirstXFAAnnot(this); + } #endif // PDF_ENABLE_XFA CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes()); return ai.GetFirstAnnot(); @@ -275,8 +290,9 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetLastFocusableAnnot() { #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage(); - if (pXFAPage) + if (pXFAPage) { return pXFAPage->GetLastXFAAnnot(this); + } #endif // PDF_ENABLE_XFA CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes()); return ai.GetLastAnnot(); @@ -284,21 +300,24 @@ WideString CPDFSDK_PageView::GetSelectedText() { CPDFSDK_Annot* annot = GetFocusAnnot(); - if (!annot) + if (!annot) { return WideString(); + } return annot->GetSelectedText(); } void CPDFSDK_PageView::ReplaceAndKeepSelection(const WideString& text) { CPDFSDK_Annot* annot = GetFocusAnnot(); - if (annot) + if (annot) { annot->ReplaceAndKeepSelection(text); + } } void CPDFSDK_PageView::ReplaceSelection(const WideString& text) { CPDFSDK_Annot* annot = GetFocusAnnot(); - if (annot) + if (annot) { annot->ReplaceSelection(text); + } } bool CPDFSDK_PageView::SelectAllText() { @@ -346,11 +365,13 @@ return false; } - if (!CPDFSDK_Annot::OnLButtonDown(pAnnot, nFlags, point)) + if (!CPDFSDK_Annot::OnLButtonDown(pAnnot, nFlags, point)) { return false; + } - if (!pAnnot) + if (!pAnnot) { return false; + } form_fill_env_->SetFocusAnnot(pAnnot); return true; @@ -362,8 +383,9 @@ ObservedPtr<CPDFSDK_Annot> pFocusAnnot(GetFocusAnnot()); if (pFocusAnnot && pFocusAnnot != pFXAnnot) { // Last focus Annot gets a chance to handle the event. - if (CPDFSDK_Annot::OnLButtonUp(pFocusAnnot, nFlags, point)) + if (CPDFSDK_Annot::OnLButtonUp(pFocusAnnot, nFlags, point)) { return true; + } } return pFXAnnot && CPDFSDK_Annot::OnLButtonUp(pFXAnnot, nFlags, point); } @@ -376,11 +398,13 @@ return false; } - if (!CPDFSDK_Annot::OnLButtonDblClk(pAnnot, nFlags, point)) + if (!CPDFSDK_Annot::OnLButtonDblClk(pAnnot, nFlags, point)) { return false; + } - if (!pAnnot) + if (!pAnnot) { return false; + } form_fill_env_->SetFocusAnnot(pAnnot); return true; @@ -389,15 +413,18 @@ bool CPDFSDK_PageView::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); - if (!pAnnot) + if (!pAnnot) { return false; + } bool ok = CPDFSDK_Annot::OnRButtonDown(pAnnot, nFlags, point); - if (!pAnnot) + if (!pAnnot) { return false; + } - if (ok) + if (ok) { form_fill_env_->SetFocusAnnot(pAnnot); + } return true; } @@ -405,15 +432,18 @@ bool CPDFSDK_PageView::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); - if (!pAnnot) + if (!pAnnot) { return false; + } bool ok = CPDFSDK_Annot::OnRButtonUp(pAnnot, nFlags, point); - if (!pAnnot) + if (!pAnnot) { return false; + } - if (ok) + if (ok) { form_fill_env_->SetFocusAnnot(pAnnot); + } return true; } @@ -428,15 +458,17 @@ } // ExitWidget() may have invalidated objects. - if (!pThis || !pFXAnnot) + if (!pThis || !pFXAnnot) { return false; + } if (!pThis->on_widget_) { pThis->EnterWidget(pFXAnnot, nFlags); // EnterWidget() may have invalidated objects. - if (!pThis) + if (!pThis) { return false; + } if (!pFXAnnot) { pThis->ExitWidget(false, nFlags); @@ -477,8 +509,9 @@ const CFX_PointF& point, const CFX_Vector& delta) { ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); - if (!pAnnot) + if (!pAnnot) { return false; + } return CPDFSDK_Annot::OnMouseWheel(pAnnot, nFlags, point, delta); } @@ -503,12 +536,14 @@ ObservedPtr<CPDFSDK_Annot> pAnnot(GetFocusAnnot()); if (!pAnnot) { // If pressed key is not tab then no action is needed. - if (nKeyCode != FWL_VKEY_Tab) + if (nKeyCode != FWL_VKEY_Tab) { return false; + } // If ctrl key or alt key is pressed, then no action is needed. - if (CPWL_Wnd::IsCTRLKeyDown(nFlags) || CPWL_Wnd::IsALTKeyDown(nFlags)) + if (CPWL_Wnd::IsCTRLKeyDown(nFlags) || CPWL_Wnd::IsALTKeyDown(nFlags)) { return false; + } ObservedPtr<CPDFSDK_Annot> end_annot(CPWL_Wnd::IsSHIFTKeyDown(nFlags) ? GetLastFocusableAnnot() @@ -516,16 +551,18 @@ return end_annot && form_fill_env_->SetFocusAnnot(end_annot); } - if (CPWL_Wnd::IsCTRLKeyDown(nFlags) || CPWL_Wnd::IsALTKeyDown(nFlags)) + if (CPWL_Wnd::IsCTRLKeyDown(nFlags) || CPWL_Wnd::IsALTKeyDown(nFlags)) { return CPDFSDK_Annot::OnKeyDown(pAnnot, nKeyCode, nFlags); + } CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) { ObservedPtr<CPDFSDK_Annot> pNext(CPWL_Wnd::IsSHIFTKeyDown(nFlags) ? GetPrevAnnot(pFocusAnnot) : GetNextAnnot(pFocusAnnot)); - if (!pNext) + if (!pNext) { return false; + } if (pNext.Get() != pFocusAnnot) { GetFormFillEnv()->SetFocusAnnot(pNext); return true; @@ -533,8 +570,9 @@ } // Check |pAnnot| again because JS may have destroyed it in GetNextAnnot(). - if (!pAnnot) + if (!pAnnot) { return false; + } return CPDFSDK_Annot::OnKeyDown(pAnnot, nKeyCode, nFlags); } @@ -574,16 +612,18 @@ CPDF_Annot* pPDFAnnot = annot_list_->GetAt(i); CheckForUnsupportedAnnot(pPDFAnnot); std::unique_ptr<CPDFSDK_Annot> pAnnot = NewAnnot(pPDFAnnot); - if (!pAnnot) + if (!pAnnot) { continue; + } sdkannot_array_.push_back(std::move(pAnnot)); sdkannot_array_.back()->OnLoad(); } } void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { - for (const auto& rc : rects) + for (const auto& rc : rects) { form_fill_env_->Invalidate(page_, rc.GetOuterRect()); + } } void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) {
diff --git a/fpdfsdk/cpdfsdk_renderpage.cpp b/fpdfsdk/cpdfsdk_renderpage.cpp index 0477bfe..b6e57c0 100644 --- a/fpdfsdk/cpdfsdk_renderpage.cpp +++ b/fpdfsdk/cpdfsdk_renderpage.cpp
@@ -29,8 +29,9 @@ const FPDF_COLORSCHEME* color_scheme, bool need_to_restore, CPDFSDK_PauseAdapter* pause) { - if (!pContext->m_pOptions) + if (!pContext->m_pOptions) { pContext->m_pOptions = std::make_unique<CPDF_RenderOptions>(); + } auto& options = pContext->m_pOptions->GetOptions(); options.bClearType = !!(flags & FPDF_LCD_TEXT); @@ -42,8 +43,9 @@ options.bNoPathSmooth = !!(flags & FPDF_RENDER_NO_SMOOTHPATH); // Grayscale output - if (flags & FPDF_GRAYSCALE) + if (flags & FPDF_GRAYSCALE) { pContext->m_pOptions->SetColorMode(CPDF_RenderOptions::kGray); + } if (color_scheme) { pContext->m_pOptions->SetColorMode(CPDF_RenderOptions::kForcedColor); @@ -84,8 +86,9 @@ pContext->m_pContext.get(), pContext->m_pDevice.get(), pContext->m_pOptions.get()); pContext->m_pRenderer->Start(pause); - if (need_to_restore) + if (need_to_restore) { pContext->m_pDevice->RestoreState(false); + } } } // namespace
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index a3c0217..99a4844 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -58,25 +58,29 @@ CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { CPDF_Document::Extension* pContext = GetPageView()->GetFormFillEnv()->GetDocExtension(); - if (!pContext || !pContext->ContainsExtensionForegroundForm()) + if (!pContext || !pContext->ContainsExtensionForegroundForm()) { return nullptr; + } CXFA_FFDocView* pDocView = static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView(); - if (!pDocView) + if (!pDocView) { return nullptr; + } WideString sName; if (GetFieldType() == FormFieldType::kRadioButton) { sName = GetAnnotName(); - if (sName.IsEmpty()) + if (sName.IsEmpty()) { sName = GetName(); + } } else { sName = GetName(); } - if (sName.IsEmpty()) + if (sName.IsEmpty()) { return nullptr; + } return pDocView->GetWidgetByName(sName, nullptr); } @@ -84,13 +88,15 @@ CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() const { CPDF_Document::Extension* pContext = GetPageView()->GetFormFillEnv()->GetDocExtension(); - if (!pContext || !pContext->ContainsExtensionForegroundForm()) + if (!pContext || !pContext->ContainsExtensionForegroundForm()) { return nullptr; + } CXFA_FFDocView* pDocView = static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView(); - if (!pDocView) + if (!pDocView) { return nullptr; + } WideString sName = GetName(); return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr; @@ -99,8 +105,9 @@ CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { CPDF_Document::Extension* pContext = GetPageView()->GetFormFillEnv()->GetDocExtension(); - if (!pContext || !pContext->ContainsExtensionForegroundForm()) + if (!pContext || !pContext->ContainsExtensionForegroundForm()) { return nullptr; + } CXFA_FFDocView* pDocView = static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView(); @@ -157,8 +164,9 @@ case CPDF_AAction::kPageInvisible: break; case CPDF_AAction::kKeyStroke: - if (!bWillCommit) + if (!bWillCommit) { eEventType = XFA_EVENT_Change; + } break; case CPDF_AAction::kValidate: eEventType = XFA_EVENT_Validate; @@ -183,12 +191,14 @@ bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const { CXFA_FFWidget* pWidget = GetMixXFAWidget(); - if (!pWidget) + if (!pWidget) { return false; + } CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); - if (!pXFAWidgetHandler) + if (!pXFAWidgetHandler) { return false; + } XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && @@ -208,20 +218,24 @@ const CPDFSDK_PageView* pPageView) { auto* pContext = static_cast<CPDFXFA_Context*>( GetPageView()->GetFormFillEnv()->GetDocExtension()); - if (!pContext) + if (!pContext) { return false; + } CXFA_FFWidget* pWidget = GetMixXFAWidget(); - if (!pWidget) + if (!pWidget) { return false; + } XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); - if (eEventType == XFA_EVENT_Unknown) + if (eEventType == XFA_EVENT_Unknown) { return false; + } CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); - if (!pXFAWidgetHandler) + if (!pXFAWidgetHandler) { return false; + } CXFA_EventParam param(eEventType); param.change_ = data->sChange; @@ -244,20 +258,23 @@ bool ret = pWidget->ProcessEventUnderHandler(¶m, pXFAWidgetHandler); CXFA_FFDocView* pDocView = pContext->GetXFADocView(); - if (pDocView) + if (pDocView) { pDocView->UpdateDocView(); + } return ret; } void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) { CXFA_FFWidget* hWidget = GetMixXFAWidget(); - if (!hWidget) + if (!hWidget) { return; + } CXFA_Node* node = hWidget->GetNode(); - if (!node->IsWidgetReady()) + if (!node->IsWidgetReady()) { return; + } CPDF_FormField* pFormField = GetFormField(); switch (GetFieldType()) { @@ -282,8 +299,9 @@ node->SetItemState(nIndex, true, false, false); } } - if (GetFieldType() == FormFieldType::kComboBox) + if (GetFieldType() == FormFieldType::kComboBox) { node->SetValue(XFA_ValuePicture::kEdit, pFormField->GetValue()); + } break; } default: @@ -303,20 +321,24 @@ CPDFSDK_FormFillEnvironment* pFormFillEnv) { auto* pContext = static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension()); - if (!pContext) + if (!pContext) { return false; + } CXFA_FFWidget* hWidget = GetMixXFAWidget(); - if (!hWidget) + if (!hWidget) { return false; + } XFA_EVENTTYPE eEventType = GetXFAEventType(type, data->bWillCommit); - if (eEventType == XFA_EVENT_Unknown) + if (eEventType == XFA_EVENT_Unknown) { return false; + } CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); - if (!pXFAWidgetHandler) + if (!pXFAWidgetHandler) { return false; + } CXFA_EventParam param(eEventType); param.change_ = data->sChange; @@ -330,8 +352,9 @@ param.prev_text_ = data->sValue; bool ret = hWidget->ProcessEventUnderHandler(¶m, pXFAWidgetHandler); CXFA_FFDocView* pDocView = pContext->GetXFADocView(); - if (pDocView) + if (pDocView) { pDocView->UpdateDocView(); + } return ret; } @@ -341,22 +364,26 @@ CPDF_Annot::AppearanceMode mode) const { RetainPtr<const CPDF_Dictionary> pAP = GetAnnotDict()->GetDictFor(pdfium::annotation::kAP); - if (!pAP) + if (!pAP) { return false; + } // Choose the right sub-ap const char* ap_entry = "N"; - if (mode == CPDF_Annot::AppearanceMode::kDown) + if (mode == CPDF_Annot::AppearanceMode::kDown) { ap_entry = "D"; - else if (mode == CPDF_Annot::AppearanceMode::kRollover) + } else if (mode == CPDF_Annot::AppearanceMode::kRollover) { ap_entry = "R"; - if (!pAP->KeyExist(ap_entry)) + } + if (!pAP->KeyExist(ap_entry)) { ap_entry = "N"; + } // Get the AP stream or subdirectory RetainPtr<const CPDF_Object> pSub = pAP->GetDirectObjectFor(ap_entry); - if (!pSub) + if (!pSub) { return false; + } FormFieldType fieldType = GetFieldType(); switch (fieldType) { @@ -396,8 +423,9 @@ #ifdef PDF_ENABLE_XFA CPDF_Document::Extension* pContext = GetPageView()->GetFormFillEnv()->GetDocExtension(); - if (pContext && pContext->ContainsExtensionFullForm()) + if (pContext && pContext->ContainsExtensionFullForm()) { return true; + } #endif // PDF_ENABLE_XFA return CPDFSDK_BAAnnot::IsAppearanceValid(); } @@ -440,8 +468,9 @@ CFX_Color::TypeAndARGB type_argb_pair = GetFormControl()->GetColorARGB(pdfium::appearance::kBG); - if (type_argb_pair.color_type == CFX_Color::Type::kTransparent) + if (type_argb_pair.color_type == CFX_Color::Type::kTransparent) { return std::nullopt; + } return ArgbToColorRef(type_argb_pair.argb); } @@ -449,8 +478,9 @@ std::optional<FX_COLORREF> CPDFSDK_Widget::GetBorderColor() const { CFX_Color::TypeAndARGB type_argb_pair = GetFormControl()->GetColorARGB(pdfium::appearance::kBC); - if (type_argb_pair.color_type == CFX_Color::Type::kTransparent) + if (type_argb_pair.color_type == CFX_Color::Type::kTransparent) { return std::nullopt; + } return ArgbToColorRef(type_argb_pair.argb); } @@ -460,11 +490,14 @@ std::optional<CFX_Color::TypeAndARGB> maybe_type_argb_pair = da.GetColorARGB(); - if (!maybe_type_argb_pair.has_value()) + if (!maybe_type_argb_pair.has_value()) { return std::nullopt; + } - if (maybe_type_argb_pair.value().color_type == CFX_Color::Type::kTransparent) + if (maybe_type_argb_pair.value().color_type == + CFX_Color::Type::kTransparent) { return std::nullopt; + } return ArgbToColorRef(maybe_type_argb_pair.value().argb); } @@ -482,8 +515,9 @@ if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { CXFA_Node* node = hWidget->GetNode(); if (node->IsWidgetReady()) { - if (nIndex < node->CountSelectedItems()) + if (nIndex < node->CountSelectedItems()) { return node->GetSelectedItem(nIndex); + } } } #endif // PDF_ENABLE_XFA @@ -495,8 +529,9 @@ #ifdef PDF_ENABLE_XFA if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { CXFA_Node* node = hWidget->GetNode(); - if (node->IsWidgetReady()) + if (node->IsWidgetReady()) { return node->GetValue(XFA_ValuePicture::kDisplay); + } } #endif // PDF_ENABLE_XFA CPDF_FormField* pFormField = GetFormField(); @@ -514,16 +549,19 @@ } WideString CPDFSDK_Widget::GetSelectExportText(int nIndex) const { - if (nIndex < 0) + if (nIndex < 0) { return WideString(); + } CPDF_FormField* pFormField = GetFormField(); - if (!pFormField) + if (!pFormField) { return WideString(); + } WideString swRet = pFormField->GetOptionValue(nIndex); - if (!swRet.IsEmpty()) + if (!swRet.IsEmpty()) { return swRet; + } return pFormField->GetOptionLabel(nIndex); } @@ -559,8 +597,9 @@ #ifdef PDF_ENABLE_XFA if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { CXFA_Node* node = hWidget->GetNode(); - if (node->IsWidgetReady()) + if (node->IsWidgetReady()) { return node->GetCheckState() == XFA_CheckState::kOn; + } } #endif // PDF_ENABLE_XFA CPDF_FormControl* pFormCtrl = GetFormControl(); @@ -583,8 +622,9 @@ pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, NotificationOption::kDoNotNotify); #ifdef PDF_ENABLE_XFA - if (!IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kNormal)) + if (!IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kNormal)) { ResetXFAAppearance(CPDFSDK_Widget::kValueChanged); + } Synchronize(true); #endif // PDF_ENABLE_XFA } @@ -647,8 +687,9 @@ SetAppModified(); appearance_age_++; - if (bValueChanged == kValueChanged) + if (bValueChanged == kValueChanged) { value_age_++; + } CPDFSDK_AppStream appStream(this, GetAPDict().Get()); switch (GetFieldType()) { @@ -702,11 +743,13 @@ } bool CPDFSDK_Widget::DoHitTest(const CFX_PointF& point) { - if (IsSignatureWidget() || !IsVisible()) + if (IsSignatureWidget() || !IsVisible()) { return false; + } - if (GetFieldFlags() & pdfium::form_flags::kReadOnly) + if (GetFieldFlags() & pdfium::form_flags::kReadOnly) { return false; + } bool do_hit_test = GetFieldType() == FormFieldType::kPushButton; if (!do_hit_test) { @@ -719,24 +762,27 @@ } CFX_FloatRect CPDFSDK_Widget::GetViewBBox() { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return CFX_FloatRect(); + } auto* form_filler = GetInteractiveFormFiller(); return CFX_FloatRect(form_filler->GetViewBBox(GetPageView(), this)); } void CPDFSDK_Widget::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return; + } ObservedPtr<CPDFSDK_Widget> observer(this); GetInteractiveFormFiller()->OnMouseEnter(GetPageView(), observer, nFlags); } void CPDFSDK_Widget::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return; + } ObservedPtr<CPDFSDK_Widget> observer(this); GetInteractiveFormFiller()->OnMouseExit(GetPageView(), observer, nFlags); @@ -744,8 +790,9 @@ bool CPDFSDK_Widget::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnLButtonDown(GetPageView(), observer, @@ -754,8 +801,9 @@ bool CPDFSDK_Widget::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnLButtonUp(GetPageView(), observer, @@ -764,8 +812,9 @@ bool CPDFSDK_Widget::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnLButtonDblClk(GetPageView(), observer, @@ -774,8 +823,9 @@ bool CPDFSDK_Widget::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnMouseMove(GetPageView(), observer, @@ -785,8 +835,9 @@ bool CPDFSDK_Widget::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point, const CFX_Vector& delta) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnMouseWheel(GetPageView(), observer, @@ -795,8 +846,9 @@ bool CPDFSDK_Widget::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnRButtonDown(GetPageView(), observer, @@ -805,8 +857,9 @@ bool CPDFSDK_Widget::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return false; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnRButtonUp(GetPageView(), observer, @@ -825,22 +878,26 @@ } bool CPDFSDK_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) { - if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype())) + if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype())) { return false; + } - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return true; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnSetFocus(observer, nFlags); } bool CPDFSDK_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) { - if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype())) + if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype())) { return false; + } - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return true; + } ObservedPtr<CPDFSDK_Widget> observer(this); return GetInteractiveFormFiller()->OnKillFocus(observer, nFlags); @@ -863,27 +920,31 @@ } WideString CPDFSDK_Widget::GetText() { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return WideString(); + } return GetInteractiveFormFiller()->GetText(this); } WideString CPDFSDK_Widget::GetSelectedText() { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return WideString(); + } return GetInteractiveFormFiller()->GetSelectedText(this); } void CPDFSDK_Widget::ReplaceAndKeepSelection(const WideString& text) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return; + } GetInteractiveFormFiller()->ReplaceAndKeepSelection(this, text); } void CPDFSDK_Widget::ReplaceSelection(const WideString& text) { - if (IsSignatureWidget()) + if (IsSignatureWidget()) { return; + } GetInteractiveFormFiller()->ReplaceSelection(this, text); } @@ -1042,8 +1103,9 @@ CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); #ifdef PDF_ENABLE_XFA - if (HandleXFAAAction(type, data, pFormFillEnv)) + if (HandleXFAAAction(type, data, pFormFillEnv)) { return true; + } #endif // PDF_ENABLE_XFA CPDF_Action action = GetAAction(type); @@ -1102,8 +1164,9 @@ case CPDF_AAction::kValidate: case CPDF_AAction::kCalculate: { CPDF_FormField* pField = GetFormField(); - if (pField->GetAdditionalAction().HasDict()) + if (pField->GetAdditionalAction().HasDict()) { return pField->GetAdditionalAction().GetAction(eAAT); + } return CPDFSDK_BAAnnot::GetAAction(eAAT); } default:
diff --git a/fpdfsdk/formfiller/cffl_button.cpp b/fpdfsdk/formfiller/cffl_button.cpp index e9b53f8..1406d96 100644 --- a/fpdfsdk/formfiller/cffl_button.cpp +++ b/fpdfsdk/formfiller/cffl_button.cpp
@@ -31,8 +31,9 @@ CPDFSDK_Widget* pWidget, Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (!pWidget->GetRect().Contains(point)) + if (!pWidget->GetRect().Contains(point)) { return false; + } mouse_down_ = true; valid_ = true; @@ -44,8 +45,9 @@ CPDFSDK_Widget* pWidget, Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { - if (!pWidget->GetRect().Contains(point)) + if (!pWidget->GetRect().Contains(point)) { return false; + } mouse_down_ = false; InvalidateRect(GetViewBBox(pPageView));
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp index a37bc64..03453a3 100644 --- a/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -53,8 +53,9 @@ ObservedPtr<CPDFSDK_Widget> pObserved(widget_); if (form_filler_->OnButtonUp(pObserved, pPageView, nFlags)) { - if (!pObserved) + if (!pObserved) { widget_ = nullptr; + } return true; } if (!pObserved) {
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index 934cfa9..6c91d1a 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -46,10 +46,11 @@ int32_t nCurSel = widget_->GetSelectedIndex(0); WideString swText; - if (nCurSel < 0) + if (nCurSel < 0) { swText = widget_->GetValue(); - else + } else { swText = widget_->GetOptionLabel(nCurSel); + } for (int32_t i = 0, sz = widget_->CountOptions(); i < sz; i++) { pWnd->AddString(widget_->GetOptionLabel(i)); @@ -68,16 +69,18 @@ bool CFFL_ComboBox::IsDataChanged(const CPDFSDK_PageView* pPageView) { auto* pWnd = GetPWLComboBox(pPageView); - if (!pWnd) + if (!pWnd) { return false; + } int32_t nCurSel = pWnd->GetSelect(); if (!(widget_->GetFieldFlags() & pdfium::form_flags::kChoiceEdit)) { return nCurSel != widget_->GetSelectedIndex(0); } - if (nCurSel >= 0) + if (nCurSel >= 0) { return nCurSel != widget_->GetSelectedIndex(0); + } return pWnd->GetText() != widget_->GetValue(); } @@ -170,14 +173,16 @@ void CFFL_ComboBox::SavePWLWindowState(const CPDFSDK_PageView* pPageView) { CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView); - if (!pComboBox) + if (!pComboBox) { return; + } state_.nIndex = pComboBox->GetSelect(); CPWL_Edit* pEdit = pComboBox->GetEdit(); - if (!pEdit) + if (!pEdit) { return; + } std::tie(state_.nStart, state_.nEnd) = pEdit->GetSelection(); state_.sValue = pEdit->GetText(); @@ -186,8 +191,9 @@ void CFFL_ComboBox::RecreatePWLWindowFromSavedState( const CPDFSDK_PageView* pPageView) { CPWL_ComboBox* pComboBox = CreateOrUpdatePWLComboBox(pPageView); - if (!pComboBox) + if (!pComboBox) { return; + } if (state_.nIndex >= 0) { pComboBox->SetSelect(state_.nIndex); @@ -195,32 +201,36 @@ } CPWL_Edit* pEdit = pComboBox->GetEdit(); - if (!pEdit) + if (!pEdit) { return; + } pEdit->SetText(state_.sValue); pEdit->SetSelection(state_.nStart, state_.nEnd); } bool CFFL_ComboBox::SetIndexSelected(int index, bool selected) { - if (!IsValid() || !selected) + if (!IsValid() || !selected) { return false; + } if (index < 0 || index >= widget_->CountOptions()) { return false; } CPWL_ComboBox* pWnd = GetPWLComboBox(GetCurPageView()); - if (!pWnd) + if (!pWnd) { return false; + } pWnd->SetSelect(index); return true; } bool CFFL_ComboBox::IsIndexSelected(int index) { - if (!IsValid()) + if (!IsValid()) { return false; + } if (index < 0 || index >= widget_->CountOptions()) { return false; @@ -233,8 +243,9 @@ #ifdef PDF_ENABLE_XFA bool CFFL_ComboBox::IsFieldFull(const CPDFSDK_PageView* pPageView) { CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView); - if (!pComboBox) + if (!pComboBox) { return false; + } CPWL_Edit* pEdit = pComboBox->GetEdit(); return pEdit && pEdit->IsTextFull();
diff --git a/fpdfsdk/formfiller/cffl_formfield.cpp b/fpdfsdk/formfiller/cffl_formfield.cpp index fd50549..1d16e50 100644 --- a/fpdfsdk/formfiller/cffl_formfield.cpp +++ b/fpdfsdk/formfiller/cffl_formfield.cpp
@@ -43,8 +43,9 @@ CFX_FloatRect rcFocus = GetFocusBox(pPageView); CFX_FloatRect rcWin = rcAnnot; - if (!rcFocus.IsEmpty()) + if (!rcFocus.IsEmpty()) { rcWin.Union(rcFocus); + } if (!rcWin.IsEmpty()) { rcWin.Inflate(1, 1); rcWin.Normalize(); @@ -62,8 +63,9 @@ pWnd->DrawAppearance(pDevice, GetCurMatrix() * mtUser2Device); return; } - if (!CFFL_InteractiveFormFiller::IsVisible(pWidget)) + if (!CFFL_InteractiveFormFiller::IsVisible(pWidget)) { return; + } pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal); @@ -89,14 +91,16 @@ Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView); - if (!pWnd) + if (!pWnd) { return false; + } valid_ = true; FX_RECT rect = GetViewBBox(pPageView); InvalidateRect(rect); - if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y))) + if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y))) { return false; + } return pWnd->OnLButtonDown(nFlags, FFLtoPWL(point)); } @@ -105,8 +109,9 @@ Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { CPWL_Wnd* pWnd = GetPWLWindow(pPageView); - if (!pWnd) + if (!pWnd) { return false; + } InvalidateRect(GetViewBBox(pPageView)); pWnd->OnLButtonUp(nFlags, FFLtoPWL(point)); @@ -117,8 +122,9 @@ Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { CPWL_Wnd* pWnd = GetPWLWindow(pPageView); - if (!pWnd) + if (!pWnd) { return false; + } pWnd->OnLButtonDblClk(nFlags, FFLtoPWL(point)); return true; @@ -128,8 +134,9 @@ Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point) { CPWL_Wnd* pWnd = GetPWLWindow(pPageView); - if (!pWnd) + if (!pWnd) { return false; + } pWnd->OnMouseMove(nFlags, FFLtoPWL(point)); return true; @@ -139,8 +146,9 @@ Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point, const CFX_Vector& delta) { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView); return pWnd && pWnd->OnMouseWheel(nFlags, FFLtoPWL(point), delta); @@ -162,8 +170,9 @@ bool CFFL_FormField::OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->OnKeyDown(nKeyCode, nFlags); @@ -172,8 +181,9 @@ bool CFFL_FormField::OnChar(CPDFSDK_Widget* pWidget, uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->OnChar(nChar, nFlags); @@ -188,78 +198,89 @@ } WideString CFFL_FormField::GetText() { - if (!IsValid()) + if (!IsValid()) { return WideString(); + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd ? pWnd->GetText() : WideString(); } WideString CFFL_FormField::GetSelectedText() { - if (!IsValid()) + if (!IsValid()) { return WideString(); + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd ? pWnd->GetSelectedText() : WideString(); } void CFFL_FormField::ReplaceAndKeepSelection(const WideString& text) { - if (!IsValid()) + if (!IsValid()) { return; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); - if (!pWnd) + if (!pWnd) { return; + } pWnd->ReplaceAndKeepSelection(text); } void CFFL_FormField::ReplaceSelection(const WideString& text) { - if (!IsValid()) + if (!IsValid()) { return; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); - if (!pWnd) + if (!pWnd) { return; + } pWnd->ReplaceSelection(text); } bool CFFL_FormField::SelectAllText() { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->SelectAllText(); } bool CFFL_FormField::CanUndo() { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->CanUndo(); } bool CFFL_FormField::CanRedo() { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->CanRedo(); } bool CFFL_FormField::Undo() { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->Undo(); } bool CFFL_FormField::Redo() { - if (!IsValid()) + if (!IsValid()) { return false; + } CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView()); return pWnd && pWnd->Redo(); @@ -270,22 +291,26 @@ CPDFSDK_PageView* pPageView = form_filler_->GetOrCreatePageView(pWidget->GetPage()); CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView); - if (pWnd) + if (pWnd) { pWnd->SetFocus(); + } valid_ = true; InvalidateRect(GetViewBBox(pPageView)); } void CFFL_FormField::KillFocusForAnnot(Mask<FWL_EVENTFLAG> nFlag) { - if (!IsValid()) + if (!IsValid()) { return; + } CPDFSDK_PageView* pPageView = form_filler_->GetPageView(widget_->GetPage()); - if (!pPageView || !CommitData(pPageView, nFlag)) + if (!pPageView || !CommitData(pPageView, nFlag)) { return; - if (CPWL_Wnd* pWnd = GetPWLWindow(pPageView)) + } + if (CPWL_Wnd* pWnd = GetPWLWindow(pPageView)) { pWnd->KillFocus(); + } bool bDestroyPWLWindow; switch (widget_->GetFieldType()) { @@ -313,21 +338,25 @@ uint32_t dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; uint32_t dwFieldFlag = widget_->GetFieldFlags(); - if (dwFieldFlag & pdfium::form_flags::kReadOnly) + if (dwFieldFlag & pdfium::form_flags::kReadOnly) { dwCreateFlags |= PWS_READONLY; + } std::optional<FX_COLORREF> color = widget_->GetFillColor(); - if (color.has_value()) + if (color.has_value()) { cp.sBackgroundColor = CFX_Color(color.value()); + } color = widget_->GetBorderColor(); - if (color.has_value()) + if (color.has_value()) { cp.sBorderColor = CFX_Color(color.value()); + } cp.sTextColor = CFX_Color(CFX_Color::Type::kGray, 0); color = widget_->GetTextColor(); - if (color.has_value()) + if (color.has_value()) { cp.sTextColor = CFX_Color(color.value()); + } cp.fFontSize = widget_->GetFontSize(); cp.dwBorderWidth = widget_->GetBorderWidth(); @@ -345,8 +374,9 @@ break; } - if (cp.fFontSize <= 0) + if (cp.fFontSize <= 0) { dwCreateFlags |= PWS_AUTOFONTSIZE; + } cp.dwFlags = dwCreateFlags; return cp; @@ -395,12 +425,14 @@ CFX_Matrix CFFL_FormField::GetWindowMatrix( const IPWL_FillerNotify::PerWindowData* pAttached) { const auto* pPrivateData = static_cast<const CFFL_PerWindowData*>(pAttached); - if (!pPrivateData) + if (!pPrivateData) { return CFX_Matrix(); + } const CPDFSDK_PageView* pPageView = pPrivateData->GetPageView(); - if (!pPageView) + if (!pPageView) { return CFX_Matrix(); + } return GetCurMatrix() * pPageView->GetCurrentMatrix(); } @@ -449,8 +481,9 @@ CFX_FloatRect CFFL_FormField::GetFocusBox(const CPDFSDK_PageView* pPageView) { CPWL_Wnd* pWnd = GetPWLWindow(pPageView); - if (!pWnd) + if (!pWnd) { return CFX_FloatRect(); + } CFX_FloatRect rcFocus = PWLtoFFL(pWnd->GetFocusRect()); return pPageView->GetPDFPage()->GetBBox().Contains(rcFocus) ? rcFocus @@ -475,39 +508,47 @@ bool CFFL_FormField::CommitData(const CPDFSDK_PageView* pPageView, Mask<FWL_EVENTFLAG> nFlag) { - if (!IsDataChanged(pPageView)) + if (!IsDataChanged(pPageView)) { return true; + } ObservedPtr<CPDFSDK_Widget> pObserved(widget_); if (!form_filler_->OnKeyStrokeCommit(pObserved, pPageView, nFlag)) { - if (!pObserved) + if (!pObserved) { return false; + } ResetPWLWindow(pPageView); return true; } - if (!pObserved) + if (!pObserved) { return false; + } if (!form_filler_->OnValidate(pObserved, pPageView, nFlag)) { - if (!pObserved) + if (!pObserved) { return false; + } ResetPWLWindow(pPageView); return true; } - if (!pObserved) + if (!pObserved) { return false; + } SaveData(pPageView); // may invoking JS to delete this widget. - if (!pObserved) + if (!pObserved) { return false; + } form_filler_->OnCalculate(pObserved); - if (!pObserved) + if (!pObserved) { return false; + } form_filler_->OnFormat(pObserved); - if (!pObserved) + if (!pObserved) { return false; + } return true; } @@ -546,8 +587,9 @@ CFFL_PerWindowData* CFFL_FormField::GetPerPWLWindowData( const CPDFSDK_PageView* pPageView) { CPWL_Wnd* pWnd = GetPWLWindow(pPageView); - if (!pWnd) + if (!pWnd) { return nullptr; + } return static_cast<CFFL_PerWindowData*>(pWnd->GetAttachedData()); } @@ -583,8 +625,9 @@ valid_ = false; InvalidateRect(GetViewBBox(pPageView)); - if (bDestroyPWLWindow) + if (bDestroyPWLWindow) { DestroyPWLWindow(pPageView); + } } void CFFL_FormField::InvalidateRect(const FX_RECT& rect) {
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index 55a8400..1c6bea9 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -41,8 +41,9 @@ FX_RECT CFFL_InteractiveFormFiller::GetViewBBox( const CPDFSDK_PageView* pPageView, CPDFSDK_Widget* pWidget) { - if (CFFL_FormField* pFormField = GetFormField(pWidget)) + if (CFFL_FormField* pFormField = GetFormField(pWidget)) { return pFormField->GetViewBBox(pPageView); + } DCHECK(pPageView); @@ -60,8 +61,9 @@ CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device) { DCHECK(pPageView); - if (!IsVisible(pWidget)) + if (!IsVisible(pWidget)) { return; + } CFFL_FormField* pFormField = GetFormField(pWidget); if (pFormField && pFormField->IsValid()) { @@ -71,8 +73,9 @@ } CFX_FloatRect rcFocus = pFormField->GetFocusBox(pPageView); - if (rcFocus.IsEmpty()) + if (rcFocus.IsEmpty()) { return; + } CFX_DrawUtils::DrawFocusRect(pDevice, mtUser2Device, rcFocus); @@ -86,8 +89,9 @@ CPDF_Annot::AppearanceMode::kNormal); } - if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) + if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) { pWidget->DrawShadow(pDevice, pPageView); + } } void CFFL_InteractiveFormFiller::OnDelete(CPDFSDK_Widget* pWidget) { @@ -112,19 +116,22 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::kCursorEnter, &fa, pPageView); } - if (!pWidget) + if (!pWidget) { return; + } if (pWidget->IsAppModified()) { CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (pFormField) + if (pFormField) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); + } } } } - if (CFFL_FormField* pFormField = GetOrCreateFormField(pWidget.Get())) + if (CFFL_FormField* pFormField = GetOrCreateFormField(pWidget.Get())) { pFormField->OnMouseEnter(pPageView); + } } void CFFL_InteractiveFormFiller::OnMouseExit( @@ -145,8 +152,9 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::kCursorExit, &fa, pPageView); } - if (!pWidget) + if (!pWidget) { return; + } if (pWidget->IsAppModified()) { CFFL_FormField* pFormField = GetFormField(pWidget.Get()); @@ -157,8 +165,9 @@ } } } - if (CFFL_FormField* pFormField = GetFormField(pWidget.Get())) + if (CFFL_FormField* pFormField = GetFormField(pWidget.Get())) { pFormField->OnMouseExit(pPageView); + } } bool CFFL_InteractiveFormFiller::OnLButtonDown( @@ -181,11 +190,13 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlags); pWidget->OnAAction(CPDF_AAction::kButtonDown, &fa, pPageView); } - if (!pWidget) + if (!pWidget) { return true; + } - if (!IsValidAnnot(pPageView, pWidget.Get())) + if (!IsValidAnnot(pPageView, pWidget.Get())) { return true; + } if (pWidget->IsAppModified()) { CFFL_FormField* pFormField = GetFormField(pWidget.Get()); @@ -231,11 +242,13 @@ if (callback_iface_->GetFocusAnnot() != pWidget.Get()) { return bRet; } - if (OnButtonUp(pWidget, pPageView, nFlags) || !pWidget) + if (OnButtonUp(pWidget, pPageView, nFlags) || !pWidget) { return true; + } #ifdef PDF_ENABLE_XFA - if (OnClick(pWidget, pPageView, nFlags) || !pWidget) + if (OnClick(pWidget, pPageView, nFlags) || !pWidget) { return true; + } #endif // PDF_ENABLE_XFA return bRet; } @@ -248,8 +261,9 @@ return false; } - if (!pWidget->GetAAction(CPDF_AAction::kButtonUp).HasDict()) + if (!pWidget->GetAAction(CPDF_AAction::kButtonUp).HasDict()) { return false; + } uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); @@ -263,14 +277,17 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::kButtonUp, &fa, pPageView); } - if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) + if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) { return true; - if (nAge == pWidget->GetAppearanceAge()) + } + if (nAge == pWidget->GetAppearanceAge()) { return false; + } CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (pFormField) + if (pFormField) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); + } return true; } @@ -346,8 +363,9 @@ bool CFFL_InteractiveFormFiller::OnChar(CPDFSDK_Widget* pWidget, uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) { - if (nChar == pdfium::ascii::kTab) + if (nChar == pdfium::ascii::kTab) { return true; + } CFFL_FormField* pFormField = GetFormField(pWidget); return pFormField && pFormField->OnChar(pWidget, nChar, nFlags); @@ -356,8 +374,9 @@ bool CFFL_InteractiveFormFiller::OnSetFocus( ObservedPtr<CPDFSDK_Widget>& pWidget, Mask<FWL_EVENTFLAG> nFlag) { - if (!pWidget) + if (!pWidget) { return false; + } if (!notifying_) { if (pWidget->GetAAction(CPDF_AAction::kGetFocus).HasDict()) { @@ -365,8 +384,9 @@ pWidget->ClearAppModified(); CFFL_FormField* pFormField = GetOrCreateFormField(pWidget.Get()); - if (!pFormField) + if (!pFormField) { return false; + } CPDFSDK_PageView* pPageView = pWidget->GetPageView(); DCHECK(pPageView); @@ -380,8 +400,9 @@ pFormField->GetActionData(pPageView, CPDF_AAction::kGetFocus, fa); pWidget->OnAAction(CPDF_AAction::kGetFocus, &fa, pPageView); } - if (!pWidget) + if (!pWidget) { return false; + } if (pWidget->IsAppModified()) { CFFL_FormField* pFiller = GetFormField(pWidget.Get()); @@ -393,8 +414,9 @@ } } - if (CFFL_FormField* pFormField = GetOrCreateFormField(pWidget.Get())) + if (CFFL_FormField* pFormField = GetOrCreateFormField(pWidget.Get())) { pFormField->SetFocusForAnnot(pWidget.Get(), nFlag); + } return true; } @@ -402,23 +424,27 @@ bool CFFL_InteractiveFormFiller::OnKillFocus( ObservedPtr<CPDFSDK_Widget>& pWidget, Mask<FWL_EVENTFLAG> nFlag) { - if (!pWidget) + if (!pWidget) { return false; + } CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (!pFormField) + if (!pFormField) { return true; + } pFormField->KillFocusForAnnot(nFlag); - if (!pWidget) + if (!pWidget) { return false; + } if (notifying_) { return true; } - if (!pWidget->GetAAction(CPDF_AAction::kLoseFocus).HasDict()) + if (!pWidget->GetAAction(CPDF_AAction::kLoseFocus).HasDict()) { return true; + } pWidget->ClearAppModified(); @@ -474,8 +500,9 @@ bool CFFL_InteractiveFormFiller::IsFillingAllowed( CPDFSDK_Widget* pWidget) const { - if (pWidget->GetFieldType() == FormFieldType::kPushButton) + if (pWidget->GetFieldType() == FormFieldType::kPushButton) { return false; + } return callback_iface_->HasPermissions( pdfium::access_permissions::kFillForm | @@ -492,8 +519,9 @@ CFFL_FormField* CFFL_InteractiveFormFiller::GetOrCreateFormField( CPDFSDK_Widget* pWidget) { CFFL_FormField* result = GetFormField(pWidget); - if (result) + if (result) { return result; + } std::unique_ptr<CFFL_FormField> pFormField; switch (pWidget->GetFieldType()) { @@ -540,8 +568,9 @@ CPDFSDK_Widget* pWidget, const WideString& text) { CFFL_FormField* pFormField = GetFormField(pWidget); - if (!pFormField) + if (!pFormField) { return; + } pFormField->ReplaceAndKeepSelection(text); } @@ -549,8 +578,9 @@ void CFFL_InteractiveFormFiller::ReplaceSelection(CPDFSDK_Widget* pWidget, const WideString& text) { CFFL_FormField* pFormField = GetFormField(pWidget); - if (!pFormField) + if (!pFormField) { return; + } pFormField->ReplaceSelection(text); } @@ -593,8 +623,9 @@ const CFX_FloatRect& rect) { auto* pPrivateData = static_cast<CFFL_PerWindowData*>(pWidgetData); CPDFSDK_Widget* pWidget = pPrivateData->GetWidget(); - if (!pWidget) + if (!pWidget) { return; + } callback_iface_->InvalidateRect(pWidget, rect); } @@ -602,12 +633,14 @@ void CFFL_InteractiveFormFiller::OutputSelectedRect(PerWindowData* pWidgetData, const CFX_FloatRect& rect) { auto* pPrivateData = static_cast<CFFL_PerWindowData*>(pWidgetData); - if (!pPrivateData) + if (!pPrivateData) { return; + } CFFL_FormField* pFormField = pPrivateData->GetFormField(); - if (!pFormField) + if (!pFormField) { return; + } callback_iface_->OutputSelectedRect(pFormField, rect); } @@ -689,8 +722,9 @@ return true; } - if (!pWidget->GetAAction(CPDF_AAction::kKeyStroke).HasDict()) + if (!pWidget->GetAAction(CPDF_AAction::kKeyStroke).HasDict()) { return true; + } DCHECK(pPageView); pWidget->ClearAppModified(); @@ -710,8 +744,9 @@ pFormField->SavePWLWindowState(pPageView); pWidget->OnAAction(CPDF_AAction::kKeyStroke, &fa, pPageView); - if (!pWidget) + if (!pWidget) { return true; + } return fa.bRC; } @@ -724,8 +759,9 @@ return true; } - if (!pWidget->GetAAction(CPDF_AAction::kValidate).HasDict()) + if (!pWidget->GetAAction(CPDF_AAction::kValidate).HasDict()) { return true; + } DCHECK(pPageView); pWidget->ClearAppModified(); @@ -744,8 +780,9 @@ pFormField->SavePWLWindowState(pPageView); pWidget->OnAAction(CPDF_AAction::kValidate, &fa, pPageView); - if (!pWidget) + if (!pWidget) { return true; + } return fa.bRC; } @@ -778,8 +815,9 @@ return false; } - if (!pWidget->HasXFAAAction(PDFSDK_XFA_Click)) + if (!pWidget->HasXFAAAction(PDFSDK_XFA_Click)) { return false; + } uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); @@ -793,14 +831,17 @@ pWidget->OnXFAAAction(PDFSDK_XFA_Click, &fa, pPageView); } - if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) + if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) { return true; - if (nAge == pWidget->GetAppearanceAge()) + } + if (nAge == pWidget->GetAppearanceAge()) { return false; + } CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (pFormField) + if (pFormField) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); + } return false; } @@ -811,8 +852,9 @@ return false; } - if (!pWidget->HasXFAAAction(PDFSDK_XFA_Full)) + if (!pWidget->HasXFAAAction(PDFSDK_XFA_Full)) { return false; + } uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); @@ -825,14 +867,17 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlag); pWidget->OnXFAAAction(PDFSDK_XFA_Full, &fa, pPageView); } - if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) + if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) { return true; - if (nAge == pWidget->GetAppearanceAge()) + } + if (nAge == pWidget->GetAppearanceAge()) { return false; + } CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (pFormField) + if (pFormField) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); + } return true; } @@ -843,8 +888,9 @@ return false; } - if (!pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) + if (!pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) { return false; + } uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); @@ -857,14 +903,17 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlag); pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, &fa, pPageView); } - if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) + if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) { return true; - if (nAge == pWidget->GetAppearanceAge()) + } + if (nAge == pWidget->GetAppearanceAge()) { return false; + } CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (pFormField) + if (pFormField) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); + } return true; } @@ -876,8 +925,9 @@ return false; } - if (!pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) + if (!pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) { return false; + } uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); @@ -890,15 +940,18 @@ fa.bShift = CPWL_Wnd::IsSHIFTKeyDown(nFlag); pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, &fa, pPageView); } - if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) + if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) { return true; + } - if (nAge == pWidget->GetAppearanceAge()) + if (nAge == pWidget->GetAppearanceAge()) { return false; + } CFFL_FormField* pFormField = GetFormField(pWidget.Get()); - if (pFormField) + if (pFormField) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); + } return true; } #endif // PDF_ENABLE_XFA @@ -928,8 +981,9 @@ #ifdef PDF_ENABLE_XFA if (pFormField->IsFieldFull(pPageView)) { - if (OnFull(pWidget, pPageView, nFlag) || !pWidget) + if (OnFull(pWidget, pPageView, nFlag) || !pWidget) { return {true, true}; + } } #endif // PDF_ENABLE_XFA @@ -962,15 +1016,17 @@ if (!pWidget || !IsValidAnnot(pPageView, pWidget.Get())) { return {true, true}; } - if (!action_status) + if (!action_status) { return {true, false}; + } bool bExit = false; if (nAge != pWidget->GetAppearanceAge()) { pFormField->ResetPWLWindowForValueAge(pPageView, pWidget.Get(), nValueAge); pPrivateData = pFormField->GetPerPWLWindowData(pPageView); - if (!pPrivateData) + if (!pPrivateData) { return {true, true}; + } pWidget.Reset(pPrivateData->GetWidget()); pPageView = pPrivateData->GetPageView();
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index bcd7984..d3bb0e8 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -25,8 +25,9 @@ CPWL_Wnd::CreateParams CFFL_ListBox::GetCreateParam() { CPWL_Wnd::CreateParams cp = CFFL_TextObject::GetCreateParam(); uint32_t dwFieldFlag = widget_->GetFieldFlags(); - if (dwFieldFlag & pdfium::form_flags::kChoiceMultiSelect) + if (dwFieldFlag & pdfium::form_flags::kChoiceMultiSelect) { cp.dwFlags |= PLBS_MULTIPLESEL; + } cp.dwFlags |= PWS_VSCROLL; @@ -85,8 +86,9 @@ bool CFFL_ListBox::IsDataChanged(const CPDFSDK_PageView* pPageView) { CPWL_ListBox* pListBox = GetPWLListBox(pPageView); - if (!pListBox) + if (!pListBox) { return false; + } if (widget_->GetFieldFlags() & pdfium::form_flags::kChoiceMultiSelect) { size_t nSelCount = 0; @@ -160,8 +162,9 @@ CPWL_ListBox* pListBox = GetPWLListBox(pPageView); if (pListBox) { int32_t nCurSel = pListBox->GetCurSel(); - if (nCurSel >= 0) + if (nCurSel >= 0) { fa.sValue = widget_->GetOptionLabel(nCurSel); + } } } break; @@ -171,8 +174,9 @@ fa.sValue.clear(); } else { int32_t nCurSel = widget_->GetSelectedIndex(0); - if (nCurSel >= 0) + if (nCurSel >= 0) { fa.sValue = widget_->GetOptionLabel(nCurSel); + } } break; default: @@ -182,20 +186,23 @@ void CFFL_ListBox::SavePWLWindowState(const CPDFSDK_PageView* pPageView) { CPWL_ListBox* pListBox = GetPWLListBox(pPageView); - if (!pListBox) + if (!pListBox) { return; + } for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { - if (pListBox->IsItemSelected(i)) + if (pListBox->IsItemSelected(i)) { state_.push_back(i); + } } } void CFFL_ListBox::RecreatePWLWindowFromSavedState( const CPDFSDK_PageView* pPageView) { CPWL_ListBox* pListBox = CreateOrUpdatePWLListBox(pPageView); - if (!pListBox) + if (!pListBox) { return; + } for (const auto& item : state_) { pListBox->Select(item); @@ -203,16 +210,18 @@ } bool CFFL_ListBox::SetIndexSelected(int index, bool selected) { - if (!IsValid()) + if (!IsValid()) { return false; + } if (index < 0 || index >= widget_->CountOptions()) { return false; } CPWL_ListBox* pListBox = GetPWLListBox(GetCurPageView()); - if (!pListBox) + if (!pListBox) { return false; + } if (selected) { pListBox->Select(index); @@ -226,8 +235,9 @@ } bool CFFL_ListBox::IsIndexSelected(int index) { - if (!IsValid()) + if (!IsValid()) { return false; + } if (index < 0 || index >= widget_->CountOptions()) { return false;
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp index 5bfd579..5744c84 100644 --- a/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp
@@ -59,8 +59,9 @@ CFFL_FormField::OnChar(pWidget, nChar, nFlags); CPWL_RadioButton* pWnd = CreateOrUpdatePWLRadioButton(pPageView); - if (pWnd && !pWnd->IsReadOnly()) + if (pWnd && !pWnd->IsReadOnly()) { pWnd->SetCheck(true); + } return CommitData(pPageView, nFlags); } default: @@ -74,12 +75,14 @@ const CFX_PointF& point) { CFFL_Button::OnLButtonUp(pPageView, pWidget, nFlags, point); - if (!IsValid()) + if (!IsValid()) { return true; + } CPWL_RadioButton* pWnd = CreateOrUpdatePWLRadioButton(pPageView); - if (pWnd) + if (pWnd) { pWnd->SetCheck(true); + } return CommitData(pPageView, nFlags); }
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index d45df81..c3b5fee 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -42,24 +42,29 @@ CPWL_Wnd::CreateParams CFFL_TextField::GetCreateParam() { CPWL_Wnd::CreateParams cp = CFFL_TextObject::GetCreateParam(); int nFlags = widget_->GetFieldFlags(); - if (nFlags & pdfium::form_flags::kTextPassword) + if (nFlags & pdfium::form_flags::kTextPassword) { cp.dwFlags |= PES_PASSWORD; + } if (nFlags & pdfium::form_flags::kTextMultiline) { cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP; - if (!(nFlags & pdfium::form_flags::kTextDoNotScroll)) + if (!(nFlags & pdfium::form_flags::kTextDoNotScroll)) { cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL; + } } else { cp.dwFlags |= PES_CENTER; - if (!(nFlags & pdfium::form_flags::kTextDoNotScroll)) + if (!(nFlags & pdfium::form_flags::kTextDoNotScroll)) { cp.dwFlags |= PES_AUTOSCROLL; + } } - if (nFlags & pdfium::form_flags::kTextComb) + if (nFlags & pdfium::form_flags::kTextComb) { cp.dwFlags |= PES_CHARARRAY; + } - if (nFlags & pdfium::form_flags::kTextRichText) + if (nFlags & pdfium::form_flags::kTextRichText) { cp.dwFlags |= PES_RICH; + } cp.dwFlags |= PES_UNDO; @@ -115,13 +120,15 @@ form_filler_->Invalidate(pWidget->GetPage(), pWidget->GetRect().GetOuterRect()); if (valid_) { - if (CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView)) + if (CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView)) { pWnd->SetFocus(); + } break; } - if (!CommitData(pPageView, nFlags)) + if (!CommitData(pPageView, nFlags)) { return false; + } DestroyPWLWindow(pPageView); return true; @@ -215,8 +222,9 @@ void CFFL_TextField::SavePWLWindowState(const CPDFSDK_PageView* pPageView) { CPWL_Edit* pWnd = GetPWLEdit(pPageView); - if (!pWnd) + if (!pWnd) { return; + } std::tie(state_.nStart, state_.nEnd) = pWnd->GetSelection(); state_.sValue = pWnd->GetText(); @@ -225,8 +233,9 @@ void CFFL_TextField::RecreatePWLWindowFromSavedState( const CPDFSDK_PageView* pPageView) { CPWL_Edit* pWnd = CreateOrUpdatePWLEdit(pPageView); - if (!pWnd) + if (!pWnd) { return; + } pWnd->SetText(state_.sValue); pWnd->SetSelection(state_.nStart, state_.nEnd);
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp index 0510d1f..5d31041 100644 --- a/fpdfsdk/fpdf_annot.cpp +++ b/fpdfsdk/fpdf_annot.cpp
@@ -236,8 +236,9 @@ if (pStream) { CFX_FloatRect boundingRect = CPDF_Annot::BoundingRectFromQuadPoints(annot_dict); - if (boundingRect.Contains(pStream->GetDict()->GetRectFor("BBox"))) + if (boundingRect.Contains(pStream->GetDict()->GetRectFor("BBox"))) { pStream->GetMutableDict()->SetRectFor("BBox", boundingRect); + } } } @@ -293,12 +294,14 @@ CPDF_FormField* GetFormField(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return nullptr; + } CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) + if (!pForm) { return nullptr; + } CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); return pPDFForm->GetFieldByDict(pAnnotDict); @@ -344,8 +347,9 @@ RetainPtr<const CPDF_Array> GetInkList(FPDF_ANNOTATION annot) { FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); - if (subtype != FPDF_ANNOT_INK) + if (subtype != FPDF_ANNOT_INK) { return nullptr; + } const CPDF_Dictionary* annot_dict = GetAnnotDictFromFPDFAnnotation(annot); return annot_dict ? annot_dict->GetArrayFor(pdfium::annotation::kInkList) @@ -380,8 +384,9 @@ FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage || !FPDFAnnot_IsSupportedSubtype(subtype)) + if (!pPage || !FPDFAnnot_IsSupportedSubtype(subtype)) { return nullptr; + } auto pDict = pPage->GetDocument()->New<CPDF_Dictionary>(); pDict->SetNewFor<CPDF_Name>(pdfium::annotation::kType, "Annot"); @@ -400,8 +405,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotCount(FPDF_PAGE page) { const CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return 0; + } RetainPtr<const CPDF_Array> pAnnots = pPage->GetAnnotsArray(); return pAnnots ? fxcrt::CollectionSize<int>(*pAnnots) : 0; @@ -410,17 +416,20 @@ FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_GetAnnot(FPDF_PAGE page, int index) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage || index < 0) + if (!pPage || index < 0) { return nullptr; + } RetainPtr<CPDF_Array> pAnnots = pPage->GetMutableAnnotsArray(); - if (!pAnnots || static_cast<size_t>(index) >= pAnnots->size()) + if (!pAnnots || static_cast<size_t>(index) >= pAnnots->size()) { return nullptr; + } RetainPtr<CPDF_Dictionary> pDict = ToDictionary(pAnnots->GetMutableDirectObjectAt(index)); - if (!pDict) + if (!pDict) { return nullptr; + } auto pNewAnnot = std::make_unique<CPDF_AnnotContext>( std::move(pDict), IPDFPageFromFPDFPage(page)); @@ -432,16 +441,19 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotIndex(FPDF_PAGE page, FPDF_ANNOTATION annot) { const CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return -1; + } const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return -1; + } RetainPtr<const CPDF_Array> pAnnots = pPage->GetAnnotsArray(); - if (!pAnnots) + if (!pAnnots) { return -1; + } CPDF_ArrayLocker locker(pAnnots); auto it = std::find_if(locker.begin(), locker.end(), @@ -449,8 +461,9 @@ return candidate->GetDirect() == pAnnotDict; }); - if (it == locker.end()) + if (it == locker.end()) { return -1; + } return pdfium::checked_cast<int>(it - locker.begin()); } @@ -462,12 +475,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_RemoveAnnot(FPDF_PAGE page, int index) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage || index < 0) + if (!pPage || index < 0) { return false; + } RetainPtr<CPDF_Array> pAnnots = pPage->GetMutableAnnotsArray(); - if (!pAnnots || static_cast<size_t>(index) >= pAnnots->size()) + if (!pAnnots || static_cast<size_t>(index) >= pAnnots->size()) { return false; + } pAnnots->RemoveAt(index); return true; @@ -476,8 +491,9 @@ FPDF_EXPORT FPDF_ANNOTATION_SUBTYPE FPDF_CALLCONV FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot) { const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return FPDF_ANNOT_UNKNOWN; + } return static_cast<FPDF_ANNOTATION_SUBTYPE>(CPDF_Annot::StringToAnnotSubtype( pAnnotDict->GetNameFor(pdfium::annotation::kSubtype))); @@ -493,25 +509,29 @@ FPDFAnnot_UpdateObject(FPDF_ANNOTATION annot, FPDF_PAGEOBJECT obj) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(obj); - if (!pAnnot || !pAnnot->HasForm() || !pObj) + if (!pAnnot || !pAnnot->HasForm() || !pObj) { return false; + } // Check that the annotation type is supported by this method. - if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) + if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) { return false; + } // Check that the annotation already has an appearance stream, since an // existing object is to be updated. RetainPtr<CPDF_Dictionary> pAnnotDict = pAnnot->GetMutableAnnotDict(); RetainPtr<CPDF_Stream> pStream = GetAnnotAP(pAnnotDict.Get(), CPDF_Annot::AppearanceMode::kNormal); - if (!pStream) + if (!pStream) { return false; + } // Check that the object is already in this annotation's object list. CPDF_Form* pForm = pAnnot->GetForm(); - if (!pdfium::Contains(*pForm, fxcrt::MakeFakeUniquePtr(pObj))) + if (!pdfium::Contains(*pForm, fxcrt::MakeFakeUniquePtr(pObj))) { return false; + } // Update the content stream data in the annotation's AP stream. UpdateContentStream(pForm, pStream.Get()); @@ -532,8 +552,9 @@ RetainPtr<CPDF_Array> inklist = annot_dict->GetOrCreateArrayFor("InkList"); FX_SAFE_SIZE_T safe_ink_size = inklist->size(); safe_ink_size += 1; - if (!safe_ink_size.IsValid<int32_t>()) + if (!safe_ink_size.IsValid<int32_t>()) { return -1; + } // SAFETY: required from caller. auto points_span = UNSAFE_BUFFERS(pdfium::make_span(points, point_count)); @@ -547,8 +568,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_RemoveInkList(FPDF_ANNOTATION annot) { - if (FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_INK) + if (FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_INK) { return false; + } RetainPtr<CPDF_Dictionary> annot_dict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetMutableAnnotDict(); @@ -560,12 +582,14 @@ FPDFAnnot_AppendObject(FPDF_ANNOTATION annot, FPDF_PAGEOBJECT obj) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(obj); - if (!pAnnot || !pObj) + if (!pAnnot || !pObj) { return false; + } // Check that the annotation type is supported by this method. - if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) + if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) { return false; + } // If the annotation does not have an AP stream yet, generate and set it. RetainPtr<CPDF_Dictionary> pAnnotDict = pAnnot->GetMutableAnnotDict(); @@ -575,13 +599,15 @@ CPDF_GenerateAP::GenerateEmptyAP(pAnnot->GetPage()->GetDocument(), pAnnotDict.Get()); pStream = GetAnnotAP(pAnnotDict.Get(), CPDF_Annot::AppearanceMode::kNormal); - if (!pStream) + if (!pStream) { return false; + } } // Get the annotation's corresponding form object for parsing its AP stream. - if (!pAnnot->HasForm()) + if (!pAnnot->HasForm()) { pAnnot->SetForm(pStream); + } // Check that the object did not come from the same annotation. If this check // succeeds, then it is assumed that the object came from @@ -589,8 +615,9 @@ // Note that an object that came from a different annotation must not be // passed here, since an object cannot belong to more than one annotation. CPDF_Form* pForm = pAnnot->GetForm(); - if (pdfium::Contains(*pForm, fxcrt::MakeFakeUniquePtr(pObj))) + if (pdfium::Contains(*pForm, fxcrt::MakeFakeUniquePtr(pObj))) { return false; + } // Append the object to the object list. pForm->AppendPageObject(pdfium::WrapUnique(pObj)); @@ -602,15 +629,17 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetObjectCount(FPDF_ANNOTATION annot) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); - if (!pAnnot) + if (!pAnnot) { return 0; + } if (!pAnnot->HasForm()) { RetainPtr<CPDF_Dictionary> pDict = pAnnot->GetMutableAnnotDict(); RetainPtr<CPDF_Stream> pStream = GetAnnotAP(pDict.Get(), CPDF_Annot::AppearanceMode::kNormal); - if (!pStream) + if (!pStream) { return 0; + } pAnnot->SetForm(std::move(pStream)); } @@ -620,15 +649,17 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFAnnot_GetObject(FPDF_ANNOTATION annot, int index) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); - if (!pAnnot || index < 0) + if (!pAnnot || index < 0) { return nullptr; + } if (!pAnnot->HasForm()) { RetainPtr<CPDF_Dictionary> pAnnotDict = pAnnot->GetMutableAnnotDict(); RetainPtr<CPDF_Stream> pStream = GetAnnotAP(pAnnotDict.Get(), CPDF_Annot::AppearanceMode::kNormal); - if (!pStream) + if (!pStream) { return nullptr; + } pAnnot->SetForm(std::move(pStream)); } @@ -640,23 +671,27 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_RemoveObject(FPDF_ANNOTATION annot, int index) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); - if (!pAnnot || !pAnnot->HasForm() || index < 0) + if (!pAnnot || !pAnnot->HasForm() || index < 0) { return false; + } // Check that the annotation type is supported by this method. - if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) + if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) { return false; + } // Check that the annotation already has an appearance stream, since an // existing object is to be deleted. RetainPtr<CPDF_Dictionary> pAnnotDict = pAnnot->GetMutableAnnotDict(); RetainPtr<CPDF_Stream> pStream = GetAnnotAP(pAnnotDict.Get(), CPDF_Annot::AppearanceMode::kNormal); - if (!pStream) + if (!pStream) { return false; + } - if (!pAnnot->GetForm()->ErasePageObjectAtIndex(index)) + if (!pAnnot->GetForm()->ErasePageObjectAtIndex(index)) { return false; + } UpdateContentStream(pAnnot->GetForm(), pStream.Get()); return true; @@ -671,14 +706,16 @@ RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict || R > 255 || G > 255 || B > 255 || A > 255) + if (!pAnnotDict || R > 255 || G > 255 || B > 255 || A > 255) { return false; + } // For annotations with their appearance streams already defined, the path // stream's own color definitions take priority over the annotation color // definitions set by this method, hence this method will simply fail. - if (HasAPStream(pAnnotDict.Get())) + if (HasAPStream(pAnnotDict.Get())) { return false; + } // Set the opacity of the annotation. pAnnotDict->SetNewFor<CPDF_Number>("CA", A / 255.f); @@ -686,10 +723,11 @@ // Set the color of the annotation. ByteString key = type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C"; RetainPtr<CPDF_Array> pColor = pAnnotDict->GetMutableArrayFor(key); - if (pColor) + if (pColor) { pColor->Clear(); - else + } else { pColor = pAnnotDict->SetNewFor<CPDF_Array>(key); + } pColor->AppendNew<CPDF_Number>(R / 255.f); pColor->AppendNew<CPDF_Number>(G / 255.f); @@ -707,14 +745,16 @@ RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict || !R || !G || !B || !A) + if (!pAnnotDict || !R || !G || !B || !A) { return false; + } // For annotations with their appearance streams already defined, the path // stream's own color definitions take priority over the annotation color // definitions retrieved by this method, hence this method will simply fail. - if (HasAPStream(pAnnotDict.Get())) + if (HasAPStream(pAnnotDict.Get())) { return false; + } RetainPtr<const CPDF_Array> pColor = pAnnotDict->GetArrayFor( type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C"); @@ -763,8 +803,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot) { - if (!annot) + if (!annot) { return false; + } FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); return subtype == FPDF_ANNOT_LINK || subtype == FPDF_ANNOT_HIGHLIGHT || @@ -776,15 +817,17 @@ FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, size_t quad_index, const FS_QUADPOINTSF* quad_points) { - if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points) + if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points) { return false; + } RetainPtr<CPDF_Dictionary> pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetMutableAnnotDict(); RetainPtr<CPDF_Array> pQuadPointsArray = GetMutableQuadPointsArrayFromDictionary(pAnnotDict.Get()); - if (!IsValidQuadPointsIndex(pQuadPointsArray.Get(), quad_index)) + if (!IsValidQuadPointsIndex(pQuadPointsArray.Get(), quad_index)) { return false; + } SetQuadPointsAtIndex(pQuadPointsArray.Get(), quad_index, quad_points); UpdateBBox(pAnnotDict.Get()); @@ -794,15 +837,17 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_AppendAttachmentPoints(FPDF_ANNOTATION annot, const FS_QUADPOINTSF* quad_points) { - if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points) + if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points) { return false; + } RetainPtr<CPDF_Dictionary> pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetMutableAnnotDict(); RetainPtr<CPDF_Array> pQuadPointsArray = GetMutableQuadPointsArrayFromDictionary(pAnnotDict.Get()); - if (!pQuadPointsArray) + if (!pQuadPointsArray) { pQuadPointsArray = AddQuadPointsArrayToDictionary(pAnnotDict.Get()); + } AppendQuadPoints(pQuadPointsArray.Get(), quad_points); UpdateBBox(pAnnotDict.Get()); return true; @@ -810,8 +855,9 @@ FPDF_EXPORT size_t FPDF_CALLCONV FPDFAnnot_CountAttachmentPoints(FPDF_ANNOTATION annot) { - if (!FPDFAnnot_HasAttachmentPoints(annot)) + if (!FPDFAnnot_HasAttachmentPoints(annot)) { return 0; + } const CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); @@ -824,15 +870,17 @@ FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot, size_t quad_index, FS_QUADPOINTSF* quad_points) { - if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points) + if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points) { return false; + } const CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); RetainPtr<const CPDF_Array> pArray = GetQuadPointsArrayFromDictionary(pAnnotDict); - if (!pArray) + if (!pArray) { return false; + } return GetQuadPointsAtIndex(std::move(pArray), quad_index, quad_points); } @@ -841,8 +889,9 @@ const FS_RECTF* rect) { RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict || !rect) + if (!pAnnotDict || !rect) { return false; + } CFX_FloatRect newRect = CFXFloatRectFromFSRectF(*rect); @@ -854,21 +903,24 @@ // the current bounding box, then update the "BBox" entry in the AP // dictionary too, since its "BBox" entry comes from annotation dictionary's // "Rect" entry. - if (FPDFAnnot_HasAttachmentPoints(annot)) + if (FPDFAnnot_HasAttachmentPoints(annot)) { return true; + } RetainPtr<CPDF_Stream> pStream = GetAnnotAP(pAnnotDict.Get(), CPDF_Annot::AppearanceMode::kNormal); - if (pStream && newRect.Contains(pStream->GetDict()->GetRectFor("BBox"))) + if (pStream && newRect.Contains(pStream->GetDict()->GetRectFor("BBox"))) { pStream->GetMutableDict()->SetRectFor("BBox", newRect); + } return true; } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetRect(FPDF_ANNOTATION annot, FS_RECTF* rect) { const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict || !rect) + if (!pAnnotDict || !rect) { return false; + } *rect = FSRectFFromCFXFloatRect( pAnnotDict->GetRectFor(pdfium::annotation::kRect)); @@ -880,17 +932,20 @@ FS_POINTF* buffer, unsigned long length) { FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); - if (subtype != FPDF_ANNOT_POLYGON && subtype != FPDF_ANNOT_POLYLINE) + if (subtype != FPDF_ANNOT_POLYGON && subtype != FPDF_ANNOT_POLYLINE) { return 0; + } const CPDF_Dictionary* annot_dict = GetAnnotDictFromFPDFAnnotation(annot); - if (!annot_dict) + if (!annot_dict) { return 0; + } RetainPtr<const CPDF_Array> vertices = annot_dict->GetArrayFor(pdfium::annotation::kVertices); - if (!vertices) + if (!vertices) { return 0; + } // Truncate to an even number. const unsigned long points_len = @@ -918,12 +973,14 @@ FS_POINTF* buffer, unsigned long length) { RetainPtr<const CPDF_Array> ink_list = GetInkList(annot); - if (!ink_list) + if (!ink_list) { return 0; + } RetainPtr<const CPDF_Array> path = ink_list->GetArrayAt(path_index); - if (!path) + if (!path) { return 0; + } // Truncate to an even number. const unsigned long points_len = @@ -942,21 +999,25 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetLine(FPDF_ANNOTATION annot, FS_POINTF* start, FS_POINTF* end) { - if (!start || !end) + if (!start || !end) { return false; + } FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); - if (subtype != FPDF_ANNOT_LINE) + if (subtype != FPDF_ANNOT_LINE) { return false; + } const CPDF_Dictionary* annot_dict = GetAnnotDictFromFPDFAnnotation(annot); - if (!annot_dict) + if (!annot_dict) { return false; + } RetainPtr<const CPDF_Array> line = annot_dict->GetArrayFor(pdfium::annotation::kL); - if (!line || line->size() < 4) + if (!line || line->size() < 4) { return false; + } start->x = line->GetFloatAt(0); start->y = line->GetFloatAt(1); @@ -971,8 +1032,9 @@ float border_width) { RetainPtr<CPDF_Dictionary> annot_dict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!annot_dict) + if (!annot_dict) { return false; + } // Remove the appearance stream. Otherwise PDF viewers will render that and // not use the border values. @@ -990,17 +1052,20 @@ float* horizontal_radius, float* vertical_radius, float* border_width) { - if (!horizontal_radius || !vertical_radius || !border_width) + if (!horizontal_radius || !vertical_radius || !border_width) { return false; + } const CPDF_Dictionary* annot_dict = GetAnnotDictFromFPDFAnnotation(annot); - if (!annot_dict) + if (!annot_dict) { return false; + } RetainPtr<const CPDF_Array> border = annot_dict->GetArrayFor(pdfium::annotation::kBorder); - if (!border || border->size() < 3) + if (!border || border->size() < 3) { return false; + } *horizontal_radius = border->GetFloatAt(0); *vertical_radius = border->GetFloatAt(1); @@ -1016,8 +1081,9 @@ FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV FPDFAnnot_GetValueType(FPDF_ANNOTATION annot, FPDF_BYTESTRING key) { - if (!FPDFAnnot_HasKey(annot, key)) + if (!FPDFAnnot_HasKey(annot, key)) { return FPDF_OBJECT_UNKNOWN; + } const CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); RetainPtr<const CPDF_Object> pObj = pAnnot->GetAnnotDict()->GetObjectFor(key); @@ -1030,8 +1096,9 @@ FPDF_WIDESTRING value) { RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return false; + } // SAFETY: required from caller. pAnnotDict->SetNewFor<CPDF_String>( @@ -1058,16 +1125,19 @@ FPDFAnnot_GetNumberValue(FPDF_ANNOTATION annot, FPDF_BYTESTRING key, float* value) { - if (!value) + if (!value) { return false; + } const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return false; + } RetainPtr<const CPDF_Object> p = pAnnotDict->GetObjectFor(key); - if (!p || p->GetType() != FPDF_OBJECT_NUMBER) + if (!p || p->GetType() != FPDF_OBJECT_NUMBER) { return false; + } *value = p->GetNumber(); return true; @@ -1079,11 +1149,13 @@ FPDF_WIDESTRING value) { RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return false; + } - if (appearanceMode < 0 || appearanceMode >= FPDF_ANNOT_APPEARANCEMODE_COUNT) + if (appearanceMode < 0 || appearanceMode >= FPDF_ANNOT_APPEARANCEMODE_COUNT) { return false; + } static constexpr auto kModeKeyForMode = fxcrt::ToArray<const char*>({"N", "R", "D"}); @@ -1159,11 +1231,13 @@ unsigned long buflen) { RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return 0; + } - if (appearanceMode < 0 || appearanceMode >= FPDF_ANNOT_APPEARANCEMODE_COUNT) + if (appearanceMode < 0 || appearanceMode >= FPDF_ANNOT_APPEARANCEMODE_COUNT) { return 0; + } CPDF_Annot::AppearanceMode mode = static_cast<CPDF_Annot::AppearanceMode>(appearanceMode); @@ -1178,13 +1252,15 @@ FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFAnnot_GetLinkedAnnot(FPDF_ANNOTATION annot, FPDF_BYTESTRING key) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); - if (!pAnnot) + if (!pAnnot) { return nullptr; + } RetainPtr<CPDF_Dictionary> pLinkedDict = pAnnot->GetMutableAnnotDict()->GetMutableDictFor(key); - if (!pLinkedDict || pLinkedDict->GetNameFor("Type") != "Annot") + if (!pLinkedDict || pLinkedDict->GetNameFor("Type") != "Annot") { return nullptr; + } auto pLinkedAnnot = std::make_unique<CPDF_AnnotContext>( std::move(pLinkedDict), pAnnot->GetPage()); @@ -1203,8 +1279,9 @@ int flags) { RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return false; + } pAnnotDict->SetNewFor<CPDF_Number>(pdfium::annotation::kF, flags); return true; @@ -1220,23 +1297,27 @@ FPDFAnnot_GetFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, const FS_POINTF* point) { - if (!point) + if (!point) { return nullptr; + } const CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) + if (!pForm) { return nullptr; + } const CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return nullptr; + } const CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); int annot_index = -1; const CPDF_FormControl* pFormCtrl = pPDFForm->GetControlAtPoint( pPage, CFXPointFFromFSPointF(*point), &annot_index); - if (!pFormCtrl || annot_index == -1) + if (!pFormCtrl || annot_index == -1) { return nullptr; + } return FPDFPage_GetAnnot(page, annot_index); } @@ -1268,8 +1349,9 @@ FPDF_WCHAR* buffer, unsigned long buflen) { const CPDF_FormField* pFormField = GetFormField(hHandle, annot); - if (!pFormField) + if (!pFormField) { return 0; + } if (event < FPDF_ANNOT_AACTION_KEY_STROKE || event > FPDF_ANNOT_AACTION_CALCULATE) { @@ -1424,11 +1506,13 @@ size_t count) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } - if (count > 0 && !subtypes) + if (count > 0 && !subtypes) { return false; + } // SAFETY: required from caller. auto subtypes_span = UNSAFE_BUFFERS(pdfium::make_span(subtypes, count)); @@ -1447,8 +1531,9 @@ FPDFAnnot_GetFocusableSubtypesCount(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return -1; + } return fxcrt::CollectionSize<int>(pFormFillEnv->GetFocusableAnnotSubtypes()); } @@ -1459,19 +1544,22 @@ size_t count) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } - if (!subtypes) + if (!subtypes) { return false; + } const std::vector<CPDF_Annot::Subtype>& focusable_annot_types = pFormFillEnv->GetFocusableAnnotSubtypes(); // Host should allocate enough memory to get the list of currently supported // focusable subtypes. - if (count < focusable_annot_types.size()) + if (count < focusable_annot_types.size()) { return false; + } // SAFETY: required from caller. auto subtypes_span = UNSAFE_BUFFERS(pdfium::make_span(subtypes, count)); @@ -1483,8 +1571,9 @@ } FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFAnnot_GetLink(FPDF_ANNOTATION annot) { - if (FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_LINK) + if (FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_LINK) { return nullptr; + } // Unretained reference in public API. NOLINTNEXTLINE return FPDFLinkFromCPDFDictionary( @@ -1500,12 +1589,14 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetFormControlIndex(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) + if (!pAnnotDict) { return -1; + } CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) + if (!pForm) { return -1; + } CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); CPDF_FormField* pFormField = pPDFForm->GetFieldByDict(pAnnotDict); @@ -1531,8 +1622,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetURI(FPDF_ANNOTATION annot, const char* uri) { - if (!uri || FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_LINK) + if (!uri || FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_LINK) { return false; + } RetainPtr<CPDF_Dictionary> annot_dict = GetMutableAnnotDictFromFPDFAnnotation(annot);
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp index a4ceeae..ac39ed1 100644 --- a/fpdfsdk/fpdf_annot_embeddertest.cpp +++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -56,8 +56,9 @@ expected_subtypes.size()); ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes( form_handle, actual_subtypes.data(), actual_subtypes.size())); - for (size_t i = 0; i < expected_subtypes.size(); ++i) + for (size_t i = 0; i < expected_subtypes.size(); ++i) { ASSERT_EQ(expected_subtypes[i], actual_subtypes[i]); + } } void SetAndVerifyFocusableAnnotSubtypes( @@ -2239,7 +2240,6 @@ EXPECT_EQ(kData, GetPlatformWString(buf.data())); } - { // Save a copy, open the copy, and check the annotation again. // Note that it renders the rotation.
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp index 63537f9..c5f2515 100644 --- a/fpdfsdk/fpdf_attachment.cpp +++ b/fpdfsdk/fpdf_attachment.cpp
@@ -39,8 +39,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 0; + } auto name_tree = CPDF_NameTree::Create(pDoc, "EmbeddedFiles"); return name_tree ? pdfium::checked_cast<int>(name_tree->GetCount()) : 0; @@ -49,18 +50,21 @@ FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV FPDFDoc_AddAttachment(FPDF_DOCUMENT document, FPDF_WIDESTRING name) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } // SAFETY: required from caller. WideString wsName = UNSAFE_BUFFERS(WideStringFromFPDFWideString(name)); - if (wsName.IsEmpty()) + if (wsName.IsEmpty()) { return nullptr; + } auto name_tree = CPDF_NameTree::CreateWithRootNameArray(pDoc, "EmbeddedFiles"); - if (!name_tree) + if (!name_tree) { return nullptr; + } // Set up the basic entries in the filespec dictionary. auto pFile = pDoc->NewIndirect<CPDF_Dictionary>(); @@ -69,8 +73,9 @@ pFile->SetNewFor<CPDF_String>(pdfium::stream::kF, wsName.AsStringView()); // Add the new attachment name and filespec into the document's EmbeddedFiles. - if (!name_tree->AddValueAndName(pFile->MakeReference(pDoc), wsName)) + if (!name_tree->AddValueAndName(pFile->MakeReference(pDoc), wsName)) { return nullptr; + } // Unretained reference in public API. NOLINTNEXTLINE return FPDFAttachmentFromCPDFObject(pFile); @@ -79,12 +84,14 @@ FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV FPDFDoc_GetAttachment(FPDF_DOCUMENT document, int index) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc || index < 0) + if (!pDoc || index < 0) { return nullptr; + } auto name_tree = CPDF_NameTree::Create(pDoc, "EmbeddedFiles"); - if (!name_tree || static_cast<size_t>(index) >= name_tree->GetCount()) + if (!name_tree || static_cast<size_t>(index) >= name_tree->GetCount()) { return nullptr; + } WideString csName; @@ -96,12 +103,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFDoc_DeleteAttachment(FPDF_DOCUMENT document, int index) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc || index < 0) + if (!pDoc || index < 0) { return false; + } auto name_tree = CPDF_NameTree::Create(pDoc, "EmbeddedFiles"); - if (!name_tree || static_cast<size_t>(index) >= name_tree->GetCount()) + if (!name_tree || static_cast<size_t>(index) >= name_tree->GetCount()) { return false; + } return name_tree->DeleteValueAndName(index); } @@ -111,8 +120,9 @@ FPDF_WCHAR* buffer, unsigned long buflen) { CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); - if (!pFile) + if (!pFile) { return 0; + } CPDF_FileSpec spec(pdfium::WrapRetain(pFile)); // SAFETY: required from caller. @@ -123,8 +133,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, FPDF_BYTESTRING key) { CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); - if (!pFile) + if (!pFile) { return 0; + } CPDF_FileSpec spec(pdfium::WrapRetain(pFile)); RetainPtr<const CPDF_Dictionary> pParamsDict = spec.GetParamsDict(); @@ -133,8 +144,9 @@ FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_BYTESTRING key) { - if (!FPDFAttachment_HasKey(attachment, key)) + if (!FPDFAttachment_HasKey(attachment, key)) { return FPDF_OBJECT_UNKNOWN; + } CPDF_FileSpec spec( pdfium::WrapRetain(CPDFObjectFromFPDFAttachment(attachment))); @@ -147,13 +159,15 @@ FPDF_BYTESTRING key, FPDF_WIDESTRING value) { CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); - if (!pFile) + if (!pFile) { return false; + } CPDF_FileSpec spec(pdfium::WrapRetain(pFile)); RetainPtr<CPDF_Dictionary> pParamsDict = spec.GetMutableParamsDict(); - if (!pParamsDict) + if (!pParamsDict) { return false; + } // SAFETY: required from caller. ByteString bsValue = UNSAFE_BUFFERS(ByteStringFromFPDFWideString(value)); @@ -268,17 +282,20 @@ void* buffer, unsigned long buflen, unsigned long* out_buflen) { - if (!out_buflen) + if (!out_buflen) { return false; + } CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); - if (!pFile) + if (!pFile) { return false; + } CPDF_FileSpec spec(pdfium::WrapRetain(pFile)); RetainPtr<const CPDF_Stream> pFileStream = spec.GetFileStream(); - if (!pFileStream) + if (!pFileStream) { return false; + } // SAFETY: required from caller. *out_buflen = DecodeStreamMaybeCopyAndReturnLength(
diff --git a/fpdfsdk/fpdf_catalog.cpp b/fpdfsdk/fpdf_catalog.cpp index 6153346..287ba1e 100644 --- a/fpdfsdk/fpdf_catalog.cpp +++ b/fpdfsdk/fpdf_catalog.cpp
@@ -13,12 +13,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFCatalog_IsTagged(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return false; + } const CPDF_Dictionary* pCatalog = pDoc->GetRoot(); - if (!pCatalog) + if (!pCatalog) { return false; + } RetainPtr<const CPDF_Dictionary> pMarkInfo = pCatalog->GetDictFor("MarkInfo"); return pMarkInfo && pMarkInfo->GetIntegerFor("Marked") != 0;
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index 4c25a52..b046494 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp
@@ -78,8 +78,9 @@ bool ReadBlockAtOffset(pdfium::span<uint8_t> buffer, FX_FILESIZE offset) override { - if (buffer.empty() || offset < 0) + if (buffer.empty() || offset < 0) { return false; + } if (!pdfium::IsValueInRangeForNumericType<FX_FILESIZE>(buffer.size())) { return false; @@ -163,8 +164,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints) { auto* avail_context = FPDFAvailContextFromFPDFAvail(avail); - if (!avail_context) + if (!avail_context) { return PDF_DATA_ERROR; + } FPDF_DownloadHintsContext hints_context(hints); return avail_context->data_avail()->IsDocAvail(&hints_context); } @@ -197,10 +199,12 @@ int page_index, FX_DOWNLOADHINTS* hints) { auto* avail_context = FPDFAvailContextFromFPDFAvail(avail); - if (!avail_context) + if (!avail_context) { return PDF_DATA_ERROR; - if (page_index < 0) + } + if (page_index < 0) { return PDF_DATA_NOTAVAIL; + } FPDF_DownloadHintsContext hints_context(hints); return avail_context->data_avail()->IsPageAvail(page_index, &hints_context); } @@ -208,15 +212,17 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsFormAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints) { auto* avail_context = FPDFAvailContextFromFPDFAvail(avail); - if (!avail_context) + if (!avail_context) { return PDF_FORM_ERROR; + } FPDF_DownloadHintsContext hints_context(hints); return avail_context->data_avail()->IsFormAvail(&hints_context); } FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsLinearized(FPDF_AVAIL avail) { auto* avail_context = FPDFAvailContextFromFPDFAvail(avail); - if (!avail_context) + if (!avail_context) { return PDF_LINEARIZATION_UNKNOWN; + } return avail_context->data_avail()->IsLinearizedPDF(); }
diff --git a/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/fpdfsdk/fpdf_dataavail_embeddertest.cpp index 438e75f..54b473c 100644 --- a/fpdfsdk/fpdf_dataavail_embeddertest.cpp +++ b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
@@ -108,12 +108,14 @@ } int GetBlockImpl(unsigned long pos, unsigned char* pBuf, unsigned long size) { - if (!IsDataAvailImpl(pos, size)) + if (!IsDataAvailImpl(pos, size)) { return 0; + } const unsigned long end = std::min( pdfium::checked_cast<unsigned long>(file_contents_.size()), pos + size); - if (end <= pos) + if (end <= pos) { return 0; + } const unsigned long bytes_to_copy = end - pos; fxcrt::Copy(file_contents().subspan(pos, bytes_to_copy), UNSAFE_TODO(pdfium::make_span(pBuf, size)));
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp index b16b9b7..44c7108 100644 --- a/fpdfsdk/fpdf_doc.cpp +++ b/fpdfsdk/fpdf_doc.cpp
@@ -42,8 +42,9 @@ const WideString& title, std::set<const CPDF_Dictionary*>* visited) { // Return if already checked to avoid circular calling. - if (pdfium::Contains(*visited, bookmark.GetDict())) + if (pdfium::Contains(*visited, bookmark.GetDict())) { return CPDF_Bookmark(); + } visited->insert(bookmark.GetDict()); if (bookmark.GetDict() && @@ -57,8 +58,9 @@ while (child.GetDict() && !pdfium::Contains(*visited, child.GetDict())) { // Check this item and its children. CPDF_Bookmark found = FindBookmark(tree, child, title, visited); - if (found.GetDict()) + if (found.GetDict()) { return found; + } child = tree.GetNextSibling(child); } return CPDF_Bookmark(); @@ -67,8 +69,9 @@ CPDF_LinkList* GetLinkList(CPDF_Page* page) { CPDF_Document* pDoc = page->GetDocument(); auto* pList = static_cast<CPDF_LinkList*>(pDoc->GetLinksContext()); - if (pList) + if (pList) { return pList; + } auto pNewList = std::make_unique<CPDF_LinkList>(); pList = pNewList.get(); @@ -81,8 +84,9 @@ FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark cBookmark( pdfium::WrapRetain(CPDFDictionaryFromFPDFBookmark(bookmark))); @@ -93,11 +97,13 @@ FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } - if (!bookmark) + if (!bookmark) { return nullptr; + } CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark cBookmark( @@ -110,8 +116,9 @@ FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark, void* buffer, unsigned long buflen) { - if (!bookmark) + if (!bookmark) { return 0; + } CPDF_Bookmark cBookmark( pdfium::WrapRetain(CPDFDictionaryFromFPDFBookmark(bookmark))); WideString title = cBookmark.GetTitle(); @@ -121,8 +128,9 @@ } FPDF_EXPORT int FPDF_CALLCONV FPDFBookmark_GetCount(FPDF_BOOKMARK bookmark) { - if (!bookmark) + if (!bookmark) { return 0; + } CPDF_Bookmark cBookmark( pdfium::WrapRetain(CPDFDictionaryFromFPDFBookmark(bookmark))); return cBookmark.GetCount(); @@ -131,13 +139,15 @@ FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } // SAFETY: required from caller. WideString encodedTitle = UNSAFE_BUFFERS(WideStringFromFPDFWideString(title)); - if (encodedTitle.IsEmpty()) + if (encodedTitle.IsEmpty()) { return nullptr; + } CPDF_BookmarkTree tree(pDoc); std::set<const CPDF_Dictionary*> visited; @@ -148,29 +158,34 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } - if (!bookmark) + if (!bookmark) { return nullptr; + } CPDF_Bookmark cBookmark( pdfium::WrapRetain(CPDFDictionaryFromFPDFBookmark(bookmark))); CPDF_Dest dest = cBookmark.GetDest(pDoc); - if (dest.GetArray()) + if (dest.GetArray()) { return FPDFDestFromCPDFArray(dest.GetArray()); + } // If this bookmark is not directly associated with a dest, we try to get // action CPDF_Action action = cBookmark.GetAction(); - if (!action.HasDict()) + if (!action.HasDict()) { return nullptr; + } return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); } FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark) { - if (!bookmark) + if (!bookmark) { return nullptr; + } CPDF_Bookmark cBookmark( pdfium::WrapRetain(CPDFDictionaryFromFPDFBookmark(bookmark))); @@ -178,8 +193,9 @@ } FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION action) { - if (!action) + if (!action) { return PDFACTION_UNSUPPORTED; + } CPDF_Action cAction(pdfium::WrapRetain(CPDFDictionaryFromFPDFAction(action))); switch (cAction.GetType()) { @@ -201,8 +217,9 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION action) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } unsigned long type = FPDFAction_GetType(action); if (type != PDFACTION_GOTO && type != PDFACTION_REMOTEGOTO && @@ -251,11 +268,13 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return -1; + } - if (!dest) + if (!dest) { return -1; + } CPDF_Dest destination(pdfium::WrapRetain(CPDFArrayFromFPDFDest(dest))); return destination.GetDestPageIndex(pDoc); @@ -286,8 +305,9 @@ FS_FLOAT* x, FS_FLOAT* y, FS_FLOAT* zoom) { - if (!dest) + if (!dest) { return false; + } CPDF_Dest destination(pdfium::WrapRetain(CPDFArrayFromFPDFDest(dest))); @@ -295,8 +315,9 @@ bool bHasX; bool bHasY; bool bHasZoom; - if (!destination.GetXYZ(&bHasX, &bHasY, &bHasZoom, x, y, zoom)) + if (!destination.GetXYZ(&bHasX, &bHasY, &bHasZoom, x, y, zoom)) { return false; + } *hasXVal = bHasX; *hasYVal = bHasY; @@ -308,12 +329,14 @@ double x, double y) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return nullptr; + } CPDF_LinkList* pLinkList = GetLinkList(pPage); - if (!pLinkList) + if (!pLinkList) { return nullptr; + } CPDF_Link link = pLinkList->GetLinkAtPoint( pPage, CFX_PointF(static_cast<float>(x), static_cast<float>(y)), nullptr); @@ -326,12 +349,14 @@ double x, double y) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return -1; + } CPDF_LinkList* pLinkList = GetLinkList(pPage); - if (!pLinkList) + if (!pLinkList) { return -1; + } int z_order = -1; pLinkList->GetLinkAtPoint( @@ -342,25 +367,30 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK link) { - if (!link) + if (!link) { return nullptr; + } CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } CPDF_Link cLink(pdfium::WrapRetain(CPDFDictionaryFromFPDFLink(link))); FPDF_DEST dest = FPDFDestFromCPDFArray(cLink.GetDest(pDoc).GetArray()); - if (dest) + if (dest) { return dest; + } // If this link is not directly associated with a dest, we try to get action CPDF_Action action = cLink.GetAction(); - if (!action.HasDict()) + if (!action.HasDict()) { return nullptr; + } return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); } FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK link) { - if (!link) + if (!link) { return nullptr; + } CPDF_Link cLink(pdfium::WrapRetain(CPDFDictionaryFromFPDFLink(link))); return FPDFActionFromCPDFDictionary(cLink.GetAction().GetDict()); @@ -369,19 +399,23 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page, int* start_pos, FPDF_LINK* link_annot) { - if (!start_pos || !link_annot) + if (!start_pos || !link_annot) { return false; + } CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return false; + } RetainPtr<CPDF_Array> pAnnots = pPage->GetMutableAnnotsArray(); - if (!pAnnots) + if (!pAnnots) { return false; + } for (size_t i = *start_pos; i < pAnnots->size(); i++) { RetainPtr<CPDF_Dictionary> pDict = ToDictionary(pAnnots->GetMutableDirectObjectAt(i)); - if (!pDict) + if (!pDict) { continue; + } if (pDict->GetByteStringFor("Subtype") == "Link") { *start_pos = static_cast<int>(i + 1); *link_annot = FPDFLinkFromCPDFDictionary(pDict.Get()); @@ -395,8 +429,9 @@ FPDFLink_GetAnnot(FPDF_PAGE page, FPDF_LINK link_annot) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); RetainPtr<CPDF_Dictionary> pAnnotDict(CPDFDictionaryFromFPDFLink(link_annot)); - if (!pPage || !pAnnotDict) + if (!pPage || !pAnnotDict) { return nullptr; + } auto pAnnotContext = std::make_unique<CPDF_AnnotContext>( std::move(pAnnotDict), IPDFPageFromFPDFPage(page)); @@ -407,8 +442,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot, FS_RECTF* rect) { - if (!link_annot || !rect) + if (!link_annot || !rect) { return false; + } CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot); *rect = FSRectFFromCFXFloatRect(pAnnotDict->GetRectFor("Rect")); @@ -425,17 +461,20 @@ FPDFLink_GetQuadPoints(FPDF_LINK link_annot, int quad_index, FS_QUADPOINTSF* quad_points) { - if (!quad_points || quad_index < 0) + if (!quad_points || quad_index < 0) { return false; + } const CPDF_Dictionary* pLinkDict = CPDFDictionaryFromFPDFLink(link_annot); - if (!pLinkDict) + if (!pLinkDict) { return false; + } RetainPtr<const CPDF_Array> pArray = GetQuadPointsArrayFromDictionary(pLinkDict); - if (!pArray) + if (!pArray) { return false; + } return GetQuadPointsAtIndex(std::move(pArray), static_cast<size_t>(quad_index), quad_points); @@ -444,20 +483,23 @@ FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDF_GetPageAAction(FPDF_PAGE page, int aa_type) { CPDF_Page* pdf_page = CPDFPageFromFPDFPage(page); - if (!pdf_page) + if (!pdf_page) { return nullptr; + } CPDF_AAction aa(pdf_page->GetDict()->GetDictFor(pdfium::form_fields::kAA)); CPDF_AAction::AActionType type; - if (aa_type == FPDFPAGE_AACTION_OPEN) + if (aa_type == FPDFPAGE_AACTION_OPEN) { type = CPDF_AAction::kOpenPage; - else if (aa_type == FPDFPAGE_AACTION_CLOSE) + } else if (aa_type == FPDFPAGE_AACTION_CLOSE) { type = CPDF_AAction::kClosePage; - else + } else { return nullptr; + } - if (!aa.ActionExist(type)) + if (!aa.ActionExist(type)) { return nullptr; + } CPDF_Action action = aa.GetAction(type); return FPDFActionFromCPDFDictionary(action.GetDict()); @@ -469,22 +511,26 @@ void* buffer, unsigned long buflen) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 0; + } // Check if |id_type| is valid. - if (id_type != FILEIDTYPE_PERMANENT && id_type != FILEIDTYPE_CHANGING) + if (id_type != FILEIDTYPE_PERMANENT && id_type != FILEIDTYPE_CHANGING) { return 0; + } RetainPtr<const CPDF_Array> pFileId = pDoc->GetFileIdentifier(); - if (!pFileId) + if (!pFileId) { return 0; + } size_t nIndex = id_type == FILEIDTYPE_PERMANENT ? 0 : 1; RetainPtr<const CPDF_String> pValue = ToString(pFileId->GetDirectObjectAt(nIndex)); - if (!pValue) + if (!pValue) { return 0; + } // SAFETY: required from caller. return NulTerminateMaybeCopyAndReturnLength( @@ -495,15 +541,18 @@ FPDF_BYTESTRING tag, void* buffer, unsigned long buflen) { - if (!tag) + if (!tag) { return 0; + } CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 0; + } RetainPtr<const CPDF_Dictionary> pInfo = pDoc->GetInfo(); - if (!pInfo) + if (!pInfo) { return 0; + } // SAFETY: required from caller. return Utf16EncodeMaybeCopyAndReturnLength( @@ -516,8 +565,9 @@ int page_index, void* buffer, unsigned long buflen) { - if (page_index < 0) + if (page_index < 0) { return 0; + } // CPDF_PageLabel can deal with NULL |document|. CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document));
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp index 5baf512..6e39ac0 100644 --- a/fpdfsdk/fpdf_editimg.cpp +++ b/fpdfsdk/fpdf_editimg.cpp
@@ -89,11 +89,13 @@ FPDF_FILEACCESS* file_access, bool inline_jpeg) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj) + if (!pImgObj) { return false; + } - if (!file_access) + if (!file_access) { return false; + } if (pages) { for (int index = 0; index < count; index++) { @@ -105,10 +107,11 @@ } RetainPtr<IFX_SeekableReadStream> pFile = MakeSeekableReadStream(file_access); - if (inline_jpeg) + if (inline_jpeg) { pImgObj->GetImage()->SetJpegImageInline(std::move(pFile)); - else + } else { pImgObj->GetImage()->SetJpegImage(std::move(pFile)); + } pImgObj->SetDirty(true); return true; @@ -119,8 +122,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_NewImageObj(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } auto pImageObj = std::make_unique<CPDF_ImageObject>(); pImageObj->SetImage(pdfium::MakeRetain<CPDF_Image>(pDoc)); @@ -154,8 +158,9 @@ double e, double f) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj) + if (!pImgObj) { return false; + } pImgObj->SetImageMatrix(CFX_Matrix( static_cast<float>(a), static_cast<float>(b), static_cast<float>(c), @@ -198,16 +203,19 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj) + if (!pImgObj) { return nullptr; + } RetainPtr<CPDF_Image> pImg = pImgObj->GetImage(); - if (!pImg) + if (!pImg) { return nullptr; + } RetainPtr<CFX_DIBBase> pSource = pImg->LoadDIBBase(); - if (!pSource) + if (!pSource) { return nullptr; + } // If the source image has a representation of 1 bit per pixel, or if the // source image has a color palette, convert it to a representation that does @@ -291,16 +299,19 @@ FPDF_PAGE page, FPDF_PAGEOBJECT image_object) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return nullptr; + } CPDF_Page* optional_page = CPDFPageFromFPDFPage(page); - if (optional_page && optional_page->GetDocument() != doc) + if (optional_page && optional_page->GetDocument() != doc) { return nullptr; + } CPDF_ImageObject* image = CPDFImageObjectFromFPDFPageObject(image_object); - if (!image) + if (!image) { return nullptr; + } // Create |result_bitmap|. const CFX_Matrix& image_matrix = image->matrix(); @@ -365,16 +376,19 @@ void* buffer, unsigned long buflen) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj) + if (!pImgObj) { return 0; + } RetainPtr<CPDF_Image> pImg = pImgObj->GetImage(); - if (!pImg) + if (!pImg) { return 0; + } RetainPtr<const CPDF_Stream> pImgStream = pImg->GetStream(); - if (!pImgStream) + if (!pImgStream) { return 0; + } // SAFETY: caller ensures `buffer` points to at least `buflen` bytes. return DecodeStreamMaybeCopyAndReturnLength( @@ -388,16 +402,19 @@ void* buffer, unsigned long buflen) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj) + if (!pImgObj) { return 0; + } RetainPtr<CPDF_Image> pImg = pImgObj->GetImage(); - if (!pImg) + if (!pImg) { return 0; + } RetainPtr<const CPDF_Stream> pImgStream = pImg->GetStream(); - if (!pImgStream) + if (!pImgStream) { return 0; + } // SAFETY: caller ensures `buffer` points to at least `buflen` bytes. return GetRawStreamMaybeCopyAndReturnLength( @@ -409,26 +426,32 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFImageObj_GetImageFilterCount(FPDF_PAGEOBJECT image_object) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj) + if (!pImgObj) { return 0; + } RetainPtr<CPDF_Image> pImg = pImgObj->GetImage(); - if (!pImg) + if (!pImg) { return 0; + } RetainPtr<const CPDF_Dictionary> pDict = pImg->GetDict(); - if (!pDict) + if (!pDict) { return 0; + } RetainPtr<const CPDF_Object> pFilter = pDict->GetDirectObjectFor("Filter"); - if (!pFilter) + if (!pFilter) { return 0; + } - if (pFilter->IsArray()) + if (pFilter->IsArray()) { return fxcrt::CollectionSize<int>(*pFilter->AsArray()); + } - if (pFilter->IsName()) + if (pFilter->IsName()) { return 1; + } return 0; } @@ -438,8 +461,9 @@ int index, void* buffer, unsigned long buflen) { - if (index < 0 || index >= FPDFImageObj_GetImageFilterCount(image_object)) + if (index < 0 || index >= FPDFImageObj_GetImageFilterCount(image_object)) { return 0; + } CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object); RetainPtr<const CPDF_Dictionary> pDict = @@ -459,12 +483,14 @@ FPDF_PAGE page, FPDF_IMAGEOBJ_METADATA* metadata) { CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); - if (!pImgObj || !metadata) + if (!pImgObj || !metadata) { return false; + } RetainPtr<CPDF_Image> pImg = pImgObj->GetImage(); - if (!pImg) + if (!pImg) { return false; + } metadata->marked_content_id = pImgObj->GetContentMarks()->GetMarkedContentID(); @@ -486,19 +512,22 @@ metadata->colorspace = FPDF_COLORSPACE_UNKNOWN; CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage || !pPage->GetDocument() || !pImg->GetStream()) + if (!pPage || !pPage->GetDocument() || !pImg->GetStream()) { return true; + } // A cross-document image may have come from the embedder. - if (pPage->GetDocument() != pImg->GetDocument()) + if (pPage->GetDocument() != pImg->GetDocument()) { return false; + } RetainPtr<CPDF_DIB> pSource = pImg->CreateNewDIB(); CPDF_DIB::LoadState ret = pSource->StartLoadDIBBase( false, nullptr, pPage->GetPageResources().Get(), false, CPDF_ColorSpace::Family::kUnknown, false, {0, 0}); - if (ret == CPDF_DIB::LoadState::kFail) + if (ret == CPDF_DIB::LoadState::kFail) { return true; + } metadata->bits_per_pixel = pSource->GetBPP(); if (pSource->GetColorSpace()) {
diff --git a/fpdfsdk/fpdf_editimg_embeddertest.cpp b/fpdfsdk/fpdf_editimg_embeddertest.cpp index 52f1eba..0e6b749 100644 --- a/fpdfsdk/fpdf_editimg_embeddertest.cpp +++ b/fpdfsdk/fpdf_editimg_embeddertest.cpp
@@ -220,7 +220,6 @@ kExpectedChecksum); } - VerifySavedDocument(kExpectedWidth, kExpectedHeight, kExpectedChecksum); } @@ -288,6 +287,5 @@ kExpectedChecksum); } - VerifySavedDocument(kExpectedWidth, kExpectedHeight, kExpectedChecksum); }
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 68f3af5..51bcd6a 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp
@@ -68,12 +68,14 @@ "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch"); bool IsPageObject(CPDF_Page* pPage) { - if (!pPage) + if (!pPage) { return false; + } RetainPtr<const CPDF_Dictionary> pFormDict = pPage->GetDict(); - if (!pFormDict->KeyExist(pdfium::page_object::kType)) + if (!pFormDict->KeyExist(pdfium::page_object::kType)) { return false; + } RetainPtr<const CPDF_Name> pName = ToName(pFormDict->GetObjectFor(pdfium::page_object::kType)->GetDirect()); @@ -117,13 +119,15 @@ RetainPtr<CPDF_Dictionary> GetOrCreateMarkParamsDict(FPDF_DOCUMENT document, FPDF_PAGEOBJECTMARK mark) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } CPDF_ContentMarkItem* pMarkItem = CPDFContentMarkItemFromFPDFPageObjectMark(mark); - if (!pMarkItem) + if (!pMarkItem) { return nullptr; + } RetainPtr<CPDF_Dictionary> pParams = pMarkItem->GetParam(); if (!pParams) { @@ -174,8 +178,9 @@ RetainPtr<CPDF_Dictionary> pInfoDict = pDoc->GetInfo(); if (pInfoDict) { - if (IsPDFSandboxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) + if (IsPDFSandboxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr); + } pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium"); } @@ -186,8 +191,9 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { auto* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return; + } CPDF_Document::Extension* pExtension = pDoc->GetExtension(); const uint32_t page_obj_num = pExtension ? pExtension->DeletePage(page_index) @@ -217,13 +223,15 @@ double width, double height) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } page_index = std::clamp(page_index, 0, pDoc->GetPageCount()); RetainPtr<CPDF_Dictionary> pPageDict(pDoc->CreateNewPage(page_index)); - if (!pPageDict) + if (!pPageDict) { return nullptr; + } pPageDict->SetRectFor(pdfium::page_object::kMediaBox, CFX_FloatRect(0, 0, width, height)); @@ -253,13 +261,15 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_object) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return; + } std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj); CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) + if (!IsPageObject(pPage)) { return; + } pPageObj->SetDirty(true); pPage->AppendPageObject(std::move(pPageObjHolder)); @@ -269,12 +279,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_RemoveObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_object) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) + if (!IsPageObject(pPage)) { return false; + } // Caller takes ownership. return !!pPage->RemovePageObject(pPageObj).release(); @@ -282,8 +294,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_CountObjects(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) + if (!IsPageObject(pPage)) { return -1; + } return pdfium::checked_cast<int>(pPage->GetPageObjectCount()); } @@ -291,8 +304,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page, int index) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) + if (!IsPageObject(pPage)) { return nullptr; + } return FPDFPageObjectFromCPDFPageObject(pPage->GetPageObjectByIndex(index)); } @@ -320,8 +334,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPageObj_CountMarks(FPDF_PAGEOBJECT page_object) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return -1; + } return pdfium::checked_cast<int>(pPageObj->GetContentMarks()->CountItems()); } @@ -329,12 +344,14 @@ FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return nullptr; + } CPDF_ContentMarks* pMarks = pPageObj->GetContentMarks(); - if (index >= pMarks->CountItems()) + if (index >= pMarks->CountItems()) { return nullptr; + } return FPDFPageObjectMarkFromCPDFContentMarkItem(pMarks->GetItem(index)); } @@ -342,8 +359,9 @@ FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV FPDFPageObj_AddMark(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING name) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return nullptr; + } CPDF_ContentMarks* pMarks = pPageObj->GetContentMarks(); pMarks->AddMark(name); @@ -358,11 +376,13 @@ CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); CPDF_ContentMarkItem* pMarkItem = CPDFContentMarkItemFromFPDFPageObjectMark(mark); - if (!pPageObj || !pMarkItem) + if (!pPageObj || !pMarkItem) { return false; + } - if (!pPageObj->GetContentMarks()->RemoveMark(pMarkItem)) + if (!pPageObj->GetContentMarks()->RemoveMark(pMarkItem)) { return false; + } pPageObj->SetDirty(true); return true; @@ -389,8 +409,9 @@ FPDFPageObjMark_CountParams(FPDF_PAGEOBJECTMARK mark) { const CPDF_ContentMarkItem* pMarkItem = CPDFContentMarkItemFromFPDFPageObjectMark(mark); - if (!pMarkItem) + if (!pMarkItem) { return -1; + } RetainPtr<const CPDF_Dictionary> pParams = pMarkItem->GetParam(); return pParams ? fxcrt::CollectionSize<int>(*pParams) : 0; @@ -402,12 +423,14 @@ FPDF_WCHAR* buffer, unsigned long buflen, unsigned long* out_buflen) { - if (!out_buflen) + if (!out_buflen) { return false; + } RetainPtr<const CPDF_Dictionary> pParams = GetMarkParamDict(mark); - if (!pParams) + if (!pParams) { return false; + } CPDF_DictionaryLocker locker(pParams); for (auto& it : locker) { @@ -428,8 +451,9 @@ FPDFPageObjMark_GetParamValueType(FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key) { RetainPtr<const CPDF_Dictionary> pParams = GetMarkParamDict(mark); - if (!pParams) + if (!pParams) { return FPDF_OBJECT_UNKNOWN; + } RetainPtr<const CPDF_Object> pObject = pParams->GetObjectFor(key); return pObject ? pObject->GetType() : FPDF_OBJECT_UNKNOWN; @@ -439,16 +463,19 @@ FPDFPageObjMark_GetParamIntValue(FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key, int* out_value) { - if (!out_value) + if (!out_value) { return false; + } RetainPtr<const CPDF_Dictionary> pParams = GetMarkParamDict(mark); - if (!pParams) + if (!pParams) { return false; + } RetainPtr<const CPDF_Object> pObj = pParams->GetObjectFor(key); - if (!pObj || !pObj->IsNumber()) + if (!pObj || !pObj->IsNumber()) { return false; + } *out_value = pObj->GetInteger(); return true; @@ -460,16 +487,19 @@ FPDF_WCHAR* buffer, unsigned long buflen, unsigned long* out_buflen) { - if (!out_buflen) + if (!out_buflen) { return false; + } RetainPtr<const CPDF_Dictionary> pParams = GetMarkParamDict(mark); - if (!pParams) + if (!pParams) { return false; + } RetainPtr<const CPDF_Object> pObj = pParams->GetObjectFor(key); - if (!pObj || !pObj->IsString()) + if (!pObj || !pObj->IsString()) { return false; + } // SAFETY: required from caller. *out_buflen = Utf16EncodeMaybeCopyAndReturnLength( @@ -484,16 +514,19 @@ unsigned char* buffer, unsigned long buflen, unsigned long* out_buflen) { - if (!out_buflen) + if (!out_buflen) { return false; + } RetainPtr<const CPDF_Dictionary> pParams = GetMarkParamDict(mark); - if (!pParams) + if (!pParams) { return false; + } RetainPtr<const CPDF_Object> pObj = pParams->GetObjectFor(key); - if (!pObj || !pObj->IsString()) + if (!pObj || !pObj->IsString()) { return false; + } // SAFETY: required from caller. auto result_span = UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, buflen)); @@ -542,13 +575,15 @@ FPDF_BYTESTRING key, int value) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || !PageObjectContainsMark(pPageObj, mark)) + if (!pPageObj || !PageObjectContainsMark(pPageObj, mark)) { return false; + } RetainPtr<CPDF_Dictionary> pParams = GetOrCreateMarkParamsDict(document, mark); - if (!pParams) + if (!pParams) { return false; + } pParams->SetNewFor<CPDF_Number>(key, value); pPageObj->SetDirty(true); @@ -562,13 +597,15 @@ FPDF_BYTESTRING key, FPDF_BYTESTRING value) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || !PageObjectContainsMark(pPageObj, mark)) + if (!pPageObj || !PageObjectContainsMark(pPageObj, mark)) { return false; + } RetainPtr<CPDF_Dictionary> pParams = GetOrCreateMarkParamsDict(document, mark); - if (!pParams) + if (!pParams) { return false; + } pParams->SetNewFor<CPDF_String>(key, value); pPageObj->SetDirty(true); @@ -610,16 +647,19 @@ FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } RetainPtr<CPDF_Dictionary> pParams = GetMarkParamDict(mark); - if (!pParams) + if (!pParams) { return false; + } auto removed = pParams->RemoveFor(key); - if (!removed) + if (!removed) { return false; + } pPageObj->SetDirty(true); return true; @@ -659,8 +699,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GenerateContent(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) + if (!IsPageObject(pPage)) { return false; + } CPDF_PageContentGenerator CG(pPage); CG.GenerateContent(); @@ -699,8 +740,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetMatrix(FPDF_PAGEOBJECT page_object, FS_MATRIX* matrix) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || !matrix) + if (!pPageObj || !matrix) { return false; + } switch (pPageObj->GetType()) { case CPDF_PageObject::Type::kText: @@ -755,8 +797,9 @@ FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING blend_mode) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return; + } pPageObj->mutable_general_state().SetBlendMode(blend_mode); pPageObj->SetDirty(true); @@ -770,8 +813,9 @@ double e, double f) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return; + } CPDF_AnnotList AnnotList(pPage); for (size_t i = 0; i < AnnotList.Count(); ++i) { @@ -782,10 +826,11 @@ RetainPtr<CPDF_Dictionary> pAnnotDict = pAnnot->GetMutableAnnotDict(); RetainPtr<CPDF_Array> pRectArray = pAnnotDict->GetMutableArrayFor("Rect"); - if (pRectArray) + if (pRectArray) { pRectArray->Clear(); - else + } else { pRectArray = pAnnotDict->SetNewFor<CPDF_Array>("Rect"); + } pRectArray->AppendNew<CPDF_Number>(rect.left); pRectArray->AppendNew<CPDF_Number>(rect.bottom); @@ -799,8 +844,9 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!IsPageObject(pPage)) + if (!IsPageObject(pPage)) { return; + } rotate %= 4; pPage->GetMutableDict()->SetNewFor<CPDF_Number>(pdfium::page_object::kRotate, @@ -814,8 +860,9 @@ unsigned int B, unsigned int A) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || R > 255 || G > 255 || B > 255 || A > 255) + if (!pPageObj || R > 255 || G > 255 || B > 255 || A > 255) { return false; + } std::vector<float> rgb = {R / 255.f, G / 255.f, B / 255.f}; pPageObj->mutable_general_state().SetFillAlpha(A / 255.f); @@ -833,8 +880,9 @@ unsigned int* B, unsigned int* A) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || !R || !G || !B || !A) + if (!pPageObj || !R || !G || !B || !A) { return false; + } if (!pPageObj->color_state().HasRef()) { return false; @@ -855,8 +903,9 @@ float* right, float* top) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } const CFX_FloatRect& bbox = pPageObj->GetRect(); *left = bbox.left; @@ -870,8 +919,9 @@ FPDFPageObj_GetRotatedBounds(FPDF_PAGEOBJECT page_object, FS_QUADPOINTSF* quad_points) { CPDF_PageObject* cpage_object = CPDFPageObjectFromFPDFPageObject(page_object); - if (!cpage_object || !quad_points) + if (!cpage_object || !quad_points) { return false; + } CFX_Matrix matrix; switch (cpage_object->GetType()) { @@ -911,8 +961,9 @@ unsigned int B, unsigned int A) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || R > 255 || G > 255 || B > 255 || A > 255) + if (!pPageObj || R > 255 || G > 255 || B > 255 || A > 255) { return false; + } std::vector<float> rgb = {R / 255.f, G / 255.f, B / 255.f}; pPageObj->mutable_general_state().SetStrokeAlpha(A / 255.f); @@ -948,8 +999,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetStrokeWidth(FPDF_PAGEOBJECT page_object, float width) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || width < 0.0f) + if (!pPageObj || width < 0.0f) { return false; + } pPageObj->mutable_graph_state().SetLineWidth(width); pPageObj->SetDirty(true); @@ -959,8 +1011,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetStrokeWidth(FPDF_PAGEOBJECT page_object, float* width) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || !width) + if (!pPageObj || !width) { return false; + } *width = pPageObj->graph_state().GetLineWidth(); return true; @@ -976,11 +1029,13 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetLineJoin(FPDF_PAGEOBJECT page_object, int line_join) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } - if (line_join < FPDF_LINEJOIN_MITER || line_join > FPDF_LINEJOIN_BEVEL) + if (line_join < FPDF_LINEJOIN_MITER || line_join > FPDF_LINEJOIN_BEVEL) { return false; + } pPageObj->mutable_graph_state().SetLineJoin( static_cast<CFX_GraphStateData::LineJoin>(line_join)); @@ -997,8 +1052,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } if (line_cap < FPDF_LINECAP_BUTT || line_cap > FPDF_LINECAP_PROJECTING_SQUARE) { @@ -1013,8 +1069,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetDashPhase(FPDF_PAGEOBJECT page_object, float* phase) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj || !phase) + if (!pPageObj || !phase) { return false; + } *phase = pPageObj->graph_state().GetLineDashPhase(); return true; @@ -1023,8 +1080,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetDashPhase(FPDF_PAGEOBJECT page_object, float phase) { auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } pPageObj->mutable_graph_state().SetLineDashPhase(phase); pPageObj->SetDirty(true); @@ -1062,12 +1120,14 @@ const float* dash_array, size_t dash_count, float phase) { - if (dash_count > 0 && !dash_array) + if (dash_count > 0 && !dash_array) { return false; + } auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return false; + } std::vector<float> dashes; if (dash_count > 0) { @@ -1090,8 +1150,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index) { const auto* pObjectList = CPDFPageObjHolderFromFPDFFormObject(form_object); - if (!pObjectList) + if (!pObjectList) { return nullptr; + } return FPDFPageObjectFromCPDFPageObject( pObjectList->GetPageObjectByIndex(index));
diff --git a/fpdfsdk/fpdf_editpage_embeddertest.cpp b/fpdfsdk/fpdf_editpage_embeddertest.cpp index b578550..c561e3e 100644 --- a/fpdfsdk/fpdf_editpage_embeddertest.cpp +++ b/fpdfsdk/fpdf_editpage_embeddertest.cpp
@@ -58,7 +58,6 @@ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get()); CompareBitmap(bitmap.get(), page_width, page_height, rotated_checksum); } - } {
diff --git a/fpdfsdk/fpdf_editpath.cpp b/fpdfsdk/fpdf_editpath.cpp index f09744d..4d6bdf6 100644 --- a/fpdfsdk/fpdf_editpath.cpp +++ b/fpdfsdk/fpdf_editpath.cpp
@@ -78,20 +78,23 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountSegments(FPDF_PAGEOBJECT path) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return -1; + } return fxcrt::CollectionSize<int>(pPathObj->path().GetPoints()); } FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV FPDFPath_GetPathSegment(FPDF_PAGEOBJECT path, int index) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return nullptr; + } pdfium::span<const CFX_Path::Point> points = pPathObj->path().GetPoints(); - if (!fxcrt::IndexInBounds(points, index)) + if (!fxcrt::IndexInBounds(points, index)) { return nullptr; + } return FPDFPathSegmentFromFXPathPoint(&points[index]); } @@ -100,8 +103,9 @@ float x, float y) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return false; + } pPathObj->path().AppendPoint(CFX_PointF(x, y), CFX_Path::Point::Type::kMove); pPathObj->SetDirty(true); @@ -112,8 +116,9 @@ float x, float y) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return false; + } pPathObj->path().AppendPoint(CFX_PointF(x, y), CFX_Path::Point::Type::kLine); pPathObj->SetDirty(true); @@ -128,8 +133,9 @@ float x3, float y3) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return false; + } CPDF_Path& cpath = pPathObj->path(); cpath.AppendPoint(CFX_PointF(x1, y1), CFX_Path::Point::Type::kBezier); @@ -141,12 +147,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return false; + } CPDF_Path& cpath = pPathObj->path(); - if (cpath.GetPoints().empty()) + if (cpath.GetPoints().empty()) { return false; + } cpath.ClosePath(); pPathObj->SetDirty(true); @@ -157,16 +165,18 @@ int fillmode, FPDF_BOOL stroke) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj) + if (!pPathObj) { return false; + } pPathObj->set_stroke(!!stroke); - if (fillmode == FPDF_FILLMODE_ALTERNATE) + if (fillmode == FPDF_FILLMODE_ALTERNATE) { pPathObj->set_alternate_filltype(); - else if (fillmode == FPDF_FILLMODE_WINDING) + } else if (fillmode == FPDF_FILLMODE_WINDING) { pPathObj->set_winding_filltype(); - else + } else { pPathObj->set_no_filltype(); + } pPathObj->SetDirty(true); return true; } @@ -175,15 +185,17 @@ int* fillmode, FPDF_BOOL* stroke) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); - if (!pPathObj || !fillmode || !stroke) + if (!pPathObj || !fillmode || !stroke) { return false; + } - if (pPathObj->has_alternate_filltype()) + if (pPathObj->has_alternate_filltype()) { *fillmode = FPDF_FILLMODE_ALTERNATE; - else if (pPathObj->has_winding_filltype()) + } else if (pPathObj->has_winding_filltype()) { *fillmode = FPDF_FILLMODE_WINDING; - else + } else { *fillmode = FPDF_FILLMODE_NONE; + } *stroke = pPathObj->stroke(); return true; @@ -192,8 +204,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPathSegment_GetPoint(FPDF_PATHSEGMENT segment, float* x, float* y) { auto* pPathPoint = FXPathPointFromFPDFPathSegment(segment); - if (!pPathPoint || !x || !y) + if (!pPathPoint || !x || !y) { return false; + } *x = pPathPoint->m_Point.x; *y = pPathPoint->m_Point.y;
diff --git a/fpdfsdk/fpdf_editpath_embeddertest.cpp b/fpdfsdk/fpdf_editpath_embeddertest.cpp index fff2f8b..791cc62 100644 --- a/fpdfsdk/fpdf_editpath_embeddertest.cpp +++ b/fpdfsdk/fpdf_editpath_embeddertest.cpp
@@ -130,7 +130,6 @@ kExpectedRectangleHeight, RectanglesChecksum()); } - VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight, RectanglesChecksum()); } @@ -194,7 +193,6 @@ kExpectedRectangleHeight, RectanglesChecksum()); } - VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight, RectanglesChecksum()); } @@ -229,7 +227,6 @@ kExpectedRectangleHeight, RectanglesAndTriangleChecksum()); } - VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight, RectanglesAndTriangleChecksum()); } @@ -264,7 +261,6 @@ kExpectedRectangleHeight, RectanglesAndTriangleChecksum()); } - VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight, RectanglesAndTriangleChecksum()); }
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp index 99953c8..8ad0c32 100644 --- a/fpdfsdk/fpdf_edittext.cpp +++ b/fpdfsdk/fpdf_edittext.cpp
@@ -139,8 +139,9 @@ if (font->GetFace()->IsFixedWidth()) { flags |= pdfium::kFontStyleFixedPitch; } - if (font_name.Contains("Serif")) + if (font_name.Contains("Serif")) { flags |= pdfium::kFontStyleSerif; + } if (font->GetFace()->IsItalic()) { flags |= pdfium::kFontStyleItalic; } @@ -602,13 +603,15 @@ FPDF_BYTESTRING font, float font_size) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } RetainPtr<CPDF_Font> pFont = CPDF_Font::GetStockFont(pDoc, ByteStringView(font)); - if (!pFont) + if (!pFont) { return nullptr; + } auto pTextObj = std::make_unique<CPDF_TextObject>(); pTextObj->mutable_text_state().SetFont(std::move(pFont)); @@ -676,8 +679,9 @@ // TODO(npm): Maybe use FT_Get_X11_Font_Format to check format? Otherwise, we // are allowing giving any font that can be loaded on freetype and setting it // as any font type. - if (!pFont->LoadEmbedded(span, /*force_vertical=*/false, /*object_tag=*/0)) + if (!pFont->LoadEmbedded(span, /*force_vertical=*/false, /*object_tag=*/0)) { return nullptr; + } // Caller takes ownership. return FPDFFontFromCPDFFont( @@ -688,8 +692,9 @@ FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFText_LoadStandardFont(FPDF_DOCUMENT document, FPDF_BYTESTRING font) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } // Caller takes ownership. return FPDFFontFromCPDFFont( @@ -736,12 +741,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text, float* size) { - if (!size) + if (!size) { return false; + } CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text); - if (!pTextObj) + if (!pTextObj) { return false; + } *size = pTextObj->GetFontSize(); return true; @@ -753,12 +760,14 @@ FPDF_WCHAR* buffer, unsigned long length) { CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text_object); - if (!pTextObj) + if (!pTextObj) { return 0; + } CPDF_TextPage* pTextPage = CPDFTextPageFromFPDFTextPage(text_page); - if (!pTextPage) + if (!pTextPage) { return 0; + } // SAFETY: required from caller. return Utf16EncodeMaybeCopyAndReturnLength( @@ -772,19 +781,23 @@ FPDF_PAGEOBJECT text_object, float scale) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return nullptr; + } CPDF_Page* optional_page = CPDFPageFromFPDFPage(page); - if (optional_page && optional_page->GetDocument() != doc) + if (optional_page && optional_page->GetDocument() != doc) { return nullptr; + } CPDF_TextObject* text = CPDFTextObjectFromFPDFPageObject(text_object); - if (!text) + if (!text) { return nullptr; + } - if (scale <= 0) + if (scale <= 0) { return nullptr; + } const CFX_Matrix scale_matrix(scale, 0, 0, scale, 0, 0); const CFX_FloatRect& text_rect = text->GetRect(); @@ -792,8 +805,9 @@ // `rect` has to use integer values. Round up as needed. const FX_RECT rect = scaled_text_rect.GetOuterRect(); - if (rect.IsEmpty()) + if (rect.IsEmpty()) { return nullptr; + } // TODO(crbug.com/42271020): Consider adding support for // `FXDIB_Format::kBgraPremul` @@ -806,8 +820,9 @@ auto render_context = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* render_context_ptr = render_context.get(); CPDF_Page::RenderContextClearer clearer(optional_page); - if (optional_page) + if (optional_page) { optional_page->SetRenderContext(std::move(render_context)); + } RetainPtr<CPDF_Dictionary> page_resources = optional_page ? optional_page->GetMutablePageResources() : nullptr; @@ -847,8 +862,9 @@ float font_size) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); CPDF_Font* pFont = CPDFFontFromFPDFFont(font); - if (!pDoc || !pFont) + if (!pDoc || !pFont) { return nullptr; + } auto pTextObj = std::make_unique<CPDF_TextObject>(); pTextObj->mutable_text_state().SetFont( @@ -862,8 +878,9 @@ FPDF_EXPORT FPDF_TEXT_RENDERMODE FPDF_CALLCONV FPDFTextObj_GetTextRenderMode(FPDF_PAGEOBJECT text) { CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text); - if (!pTextObj) + if (!pTextObj) { return FPDF_TEXTRENDERMODE_UNKNOWN; + } return static_cast<FPDF_TEXT_RENDERMODE>(pTextObj->GetTextRenderMode()); } @@ -876,8 +893,9 @@ } CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text); - if (!pTextObj) + if (!pTextObj) { return false; + } pTextObj->SetTextRenderMode(static_cast<TextRenderingMode>(render_mode)); return true; @@ -885,8 +903,9 @@ FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFTextObj_GetFont(FPDF_PAGEOBJECT text) { CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text); - if (!pTextObj) + if (!pTextObj) { return nullptr; + } // Unretained reference in public API. NOLINTNEXTLINE return FPDFFontFromCPDFFont(pTextObj->GetFont()); @@ -929,8 +948,9 @@ size_t buflen, size_t* out_buflen) { auto* cfont = CPDFFontFromFPDFFont(font); - if (!cfont || !out_buflen) + if (!cfont || !out_buflen) { return false; + } // SAFETY: required from caller. auto result_span = UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, buflen)); @@ -942,15 +962,17 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetIsEmbedded(FPDF_FONT font) { auto* cfont = CPDFFontFromFPDFFont(font); - if (!cfont) + if (!cfont) { return -1; + } return cfont->IsEmbedded() ? 1 : 0; } FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetFlags(FPDF_FONT font) { auto* pFont = CPDFFontFromFPDFFont(font); - if (!pFont) + if (!pFont) { return -1; + } // Return only flags from ISO 32000-1:2008, table 123. return pFont->GetFontFlags() & 0x7ffff; @@ -967,8 +989,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFFont_GetItalicAngle(FPDF_FONT font, int* angle) { auto* pFont = CPDFFontFromFPDFFont(font); - if (!pFont || !angle) + if (!pFont || !angle) { return false; + } *angle = pFont->GetItalicAngle(); return true; @@ -978,8 +1001,9 @@ float font_size, float* ascent) { auto* pFont = CPDFFontFromFPDFFont(font); - if (!pFont || !ascent) + if (!pFont || !ascent) { return false; + } *ascent = pFont->GetTypeAscent() * font_size / 1000.f; return true; @@ -989,8 +1013,9 @@ float font_size, float* descent) { auto* pFont = CPDFFontFromFPDFFont(font); - if (!pFont || !descent) + if (!pFont || !descent) { return false; + } *descent = pFont->GetTypeDescent() * font_size / 1000.f; return true; @@ -1001,8 +1026,9 @@ float font_size, float* width) { auto* pFont = CPDFFontFromFPDFFont(font); - if (!pFont || !width) + if (!pFont || !width) { return false; + } uint32_t charcode = pFont->CharCodeFromUnicode(static_cast<wchar_t>(glyph)); @@ -1020,8 +1046,9 @@ FPDF_EXPORT FPDF_GLYPHPATH FPDF_CALLCONV FPDFFont_GetGlyphPath(FPDF_FONT font, uint32_t glyph, float font_size) { auto* pFont = CPDFFontFromFPDFFont(font); - if (!pFont) + if (!pFont) { return nullptr; + } if (!pdfium::IsValueInRangeForNumericType<wchar_t>(glyph)) { return nullptr; @@ -1031,8 +1058,9 @@ std::vector<TextCharPos> pos = GetCharPosList(pdfium::span_from_ref(charcode), pdfium::span<const float>(), pFont, font_size); - if (pos.empty()) + if (pos.empty()) { return nullptr; + } CFX_Font* pCfxFont; if (pos[0].m_FallbackFontPosition == -1) { @@ -1040,8 +1068,9 @@ DCHECK(pCfxFont); // Never null. } else { pCfxFont = pFont->GetFontFallback(pos[0].m_FallbackFontPosition); - if (!pCfxFont) + if (!pCfxFont) { return nullptr; + } } const CFX_Path* pPath = @@ -1053,8 +1082,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFGlyphPath_CountGlyphSegments(FPDF_GLYPHPATH glyphpath) { auto* pPath = CFXPathFromFPDFGlyphPath(glyphpath); - if (!pPath) + if (!pPath) { return -1; + } return fxcrt::CollectionSize<int>(pPath->GetPoints()); } @@ -1062,12 +1092,14 @@ FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV FPDFGlyphPath_GetGlyphPathSegment(FPDF_GLYPHPATH glyphpath, int index) { auto* pPath = CFXPathFromFPDFGlyphPath(glyphpath); - if (!pPath) + if (!pPath) { return nullptr; + } pdfium::span<const CFX_Path::Point> points = pPath->GetPoints(); - if (!fxcrt::IndexInBounds(points, index)) + if (!fxcrt::IndexInBounds(points, index)) { return nullptr; + } return FPDFPathSegmentFromFXPathPoint(&points[index]); }
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp index 44f329f..81e5c46 100644 --- a/fpdfsdk/fpdf_ext.cpp +++ b/fpdfsdk/fpdf_ext.cpp
@@ -65,8 +65,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) { - if (!unsp_info || unsp_info->version != 1) + if (!unsp_info || unsp_info->version != 1) { return false; + } SetPDFUnsupportInfo(unsp_info); return true; @@ -83,30 +84,39 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFDoc_GetPageMode(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return PAGEMODE_UNKNOWN; + } const CPDF_Dictionary* pRoot = pDoc->GetRoot(); - if (!pRoot) + if (!pRoot) { return PAGEMODE_UNKNOWN; + } RetainPtr<const CPDF_Object> pName = pRoot->GetObjectFor("PageMode"); - if (!pName) + if (!pName) { return PAGEMODE_USENONE; + } ByteString strPageMode = pName->GetString(); - if (strPageMode.IsEmpty() || strPageMode.EqualNoCase("UseNone")) + if (strPageMode.IsEmpty() || strPageMode.EqualNoCase("UseNone")) { return PAGEMODE_USENONE; - if (strPageMode.EqualNoCase("UseOutlines")) + } + if (strPageMode.EqualNoCase("UseOutlines")) { return PAGEMODE_USEOUTLINES; - if (strPageMode.EqualNoCase("UseThumbs")) + } + if (strPageMode.EqualNoCase("UseThumbs")) { return PAGEMODE_USETHUMBS; - if (strPageMode.EqualNoCase("FullScreen")) + } + if (strPageMode.EqualNoCase("FullScreen")) { return PAGEMODE_FULLSCREEN; - if (strPageMode.EqualNoCase("UseOC")) + } + if (strPageMode.EqualNoCase("UseOC")) { return PAGEMODE_USEOC; - if (strPageMode.EqualNoCase("UseAttachments")) + } + if (strPageMode.EqualNoCase("UseAttachments")) { return PAGEMODE_USEATTACHMENTS; + } return PAGEMODE_UNKNOWN; }
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index aeb01e8..5a5b970 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp
@@ -41,11 +41,13 @@ bool IsValidRect(const CFX_FloatRect& rect, const CFX_FloatRect& rcPage) { static constexpr float kMinSize = 0.000001f; - if (rect.IsEmpty() || rect.Width() < kMinSize || rect.Height() < kMinSize) + if (rect.IsEmpty() || rect.Width() < kMinSize || rect.Height() < kMinSize) { return false; + } - if (rcPage.IsEmpty()) + if (rcPage.IsEmpty()) { return true; + } static constexpr float kMinBorderSize = 10.000001f; return rect.left - rcPage.left >= -kMinBorderSize && @@ -66,8 +68,9 @@ } const CFX_FloatRect& rc = pPageObject->GetRect(); - if (IsValidRect(rc, pDict->GetRectFor(pdfium::page_object::kMediaBox))) + if (IsValidRect(rc, pDict->GetRectFor(pdfium::page_object::kMediaBox))) { pRectArray->push_back(rc); + } } } @@ -75,16 +78,19 @@ CPDF_Dictionary* pStream, std::vector<CFX_FloatRect>* pRectArray, std::vector<CPDF_Dictionary*>* pObjectArray) { - if (!pStream) + if (!pStream) { return; + } CFX_FloatRect rect; - if (pStream->KeyExist("Rect")) + if (pStream->KeyExist("Rect")) { rect = pStream->GetRectFor("Rect"); - else if (pStream->KeyExist("BBox")) + } else if (pStream->KeyExist("BBox")) { rect = pStream->GetRectFor("BBox"); + } - if (IsValidRect(rect, pPageDic->GetRectFor(pdfium::page_object::kMediaBox))) + if (IsValidRect(rect, pPageDic->GetRectFor(pdfium::page_object::kMediaBox))) { pRectArray->push_back(rect); + } pObjectArray->push_back(pStream); } @@ -94,37 +100,44 @@ std::vector<CFX_FloatRect>* pRectArray, std::vector<CPDF_Dictionary*>* pObjectArray, int nUsage) { - if (!pSourceDoc) + if (!pSourceDoc) { return FLATTEN_FAIL; + } GetContentsRect(pSourceDoc, pPageDic, pRectArray); RetainPtr<const CPDF_Array> pAnnots = pPageDic->GetArrayFor("Annots"); - if (!pAnnots) + if (!pAnnots) { return FLATTEN_NOTHINGTODO; + } CPDF_ArrayLocker locker(pAnnots); for (const auto& pAnnot : locker) { RetainPtr<CPDF_Dictionary> pAnnotDict = ToDictionary(pAnnot->GetMutableDirect()); - if (!pAnnotDict) + if (!pAnnotDict) { continue; + } ByteString sSubtype = pAnnotDict->GetByteStringFor(pdfium::annotation::kSubtype); - if (sSubtype == "Popup") + if (sSubtype == "Popup") { continue; + } int nAnnotFlag = pAnnotDict->GetIntegerFor("F"); - if (nAnnotFlag & pdfium::annotation_flags::kHidden) + if (nAnnotFlag & pdfium::annotation_flags::kHidden) { continue; + } bool bParseStream; - if (nUsage == FLAT_NORMALDISPLAY) + if (nUsage == FLAT_NORMALDISPLAY) { bParseStream = !(nAnnotFlag & pdfium::annotation_flags::kInvisible); - else + } else { bParseStream = !!(nAnnotFlag & pdfium::annotation_flags::kPrint); - if (bParseStream) + } + if (bParseStream) { ParserStream(pPageDic.Get(), pAnnotDict.Get(), pRectArray, pObjectArray); + } } return FLATTEN_SUCCESS; } @@ -132,37 +145,44 @@ float GetMinMaxValue(const std::vector<CFX_FloatRect>& array, FPDF_TYPE type, FPDF_VALUE value) { - if (array.empty()) + if (array.empty()) { return 0.0f; + } size_t nRects = array.size(); std::vector<float> pArray(nRects); switch (value) { case LEFT: - for (size_t i = 0; i < nRects; i++) + for (size_t i = 0; i < nRects; i++) { pArray[i] = array[i].left; + } break; case TOP: - for (size_t i = 0; i < nRects; i++) + for (size_t i = 0; i < nRects; i++) { pArray[i] = array[i].top; + } break; case RIGHT: - for (size_t i = 0; i < nRects; i++) + for (size_t i = 0; i < nRects; i++) { pArray[i] = array[i].right; + } break; case BOTTOM: - for (size_t i = 0; i < nRects; i++) + for (size_t i = 0; i < nRects; i++) { pArray[i] = array[i].bottom; + } break; } float fRet = pArray[0]; if (type == MAX) { - for (size_t i = 1; i < nRects; i++) + for (size_t i = 1; i < nRects; i++) { fRet = std::max(fRet, pArray[i]); + } } else { - for (size_t i = 1; i < nRects; i++) + for (size_t i = 1; i < nRects; i++) { fRet = std::min(fRet, pArray[i]); + } } return fRet; } @@ -236,8 +256,9 @@ CFX_Matrix GetMatrix(const CFX_FloatRect& rcAnnot, const CFX_FloatRect& rcStream, const CFX_Matrix& matrix) { - if (rcStream.IsEmpty()) + if (rcStream.IsEmpty()) { return CFX_Matrix(); + } CFX_FloatRect rcTransformed = matrix.TransformRect(rcStream); rcTransformed.Normalize(); @@ -298,38 +319,44 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!page) + if (!page) { return FLATTEN_FAIL; + } CPDF_Document* pDocument = pPage->GetDocument(); RetainPtr<CPDF_Dictionary> pPageDict = pPage->GetMutableDict(); - if (!pDocument) + if (!pDocument) { return FLATTEN_FAIL; + } std::vector<CPDF_Dictionary*> ObjectArray; std::vector<CFX_FloatRect> RectArray; int iRet = ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag); - if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) + if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) { return iRet; + } CFX_FloatRect rcMerger = CalculateRect(&RectArray); CFX_FloatRect rcOriginalMB = pPageDict->GetRectFor(pdfium::page_object::kMediaBox); - if (pPageDict->KeyExist(pdfium::page_object::kCropBox)) + if (pPageDict->KeyExist(pdfium::page_object::kCropBox)) { rcOriginalMB = pPageDict->GetRectFor(pdfium::page_object::kCropBox); + } rcOriginalMB.Normalize(); - if (rcOriginalMB.IsEmpty()) + if (rcOriginalMB.IsEmpty()) { rcOriginalMB = CFX_FloatRect(0.0f, 0.0f, 612.0f, 792.0f); + } CFX_FloatRect rcOriginalCB; if (pPageDict->KeyExist(pdfium::page_object::kCropBox)) { rcOriginalCB = pPageDict->GetRectFor(pdfium::page_object::kCropBox); rcOriginalCB.Normalize(); } - if (rcOriginalCB.IsEmpty()) + if (rcOriginalCB.IsEmpty()) { rcOriginalCB = rcOriginalMB; + } rcMerger.left = std::max(rcMerger.left, rcOriginalMB.left); rcMerger.right = std::min(rcMerger.right, rcOriginalMB.right); @@ -375,8 +402,9 @@ for (size_t i = 0; i < ObjectArray.size(); ++i) { CPDF_Dictionary* pAnnotDict = ObjectArray[i]; - if (!pAnnotDict) + if (!pAnnotDict) { continue; + } CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor(pdfium::annotation::kRect); rcAnnot.Normalize(); @@ -384,8 +412,9 @@ ByteString sAnnotState = pAnnotDict->GetByteStringFor("AS"); RetainPtr<CPDF_Dictionary> pAnnotAP = pAnnotDict->GetMutableDictFor(pdfium::annotation::kAP); - if (!pAnnotAP) + if (!pAnnotAP) { continue; + } RetainPtr<CPDF_Stream> original_ap_stream = pAnnotAP->GetMutableStreamFor("N"); @@ -403,10 +432,12 @@ CPDF_DictionaryLocker locker(original_ap_dict); RetainPtr<CPDF_Object> pFirstObj = locker.begin()->second; if (pFirstObj) { - if (pFirstObj->IsReference()) + if (pFirstObj->IsReference()) { pFirstObj = pFirstObj->GetMutableDirect(); - if (!pFirstObj->IsStream()) + } + if (!pFirstObj->IsStream()) { continue; + } original_ap_stream.Reset(pFirstObj->AsMutableStream()); } } @@ -426,8 +457,9 @@ } rcStream.Normalize(); - if (rcStream.IsEmpty()) + if (rcStream.IsEmpty()) { continue; + } RetainPtr<CPDF_Stream> ap_stream; if (original_ap_stream->IsInline()) {
diff --git a/fpdfsdk/fpdf_flatten_embeddertest.cpp b/fpdfsdk/fpdf_flatten_embeddertest.cpp index a209ed9..5c6a6b1 100644 --- a/fpdfsdk/fpdf_flatten_embeddertest.cpp +++ b/fpdfsdk/fpdf_flatten_embeddertest.cpp
@@ -92,7 +92,6 @@ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - // TODO(crbug.com/861842): This should not render blank. static constexpr char kBlankPageHash[] = "48400809c3862dae64b0cd00d51057a4"; VerifySavedDocument(100, 120, kBlankPageHash); @@ -143,7 +142,6 @@ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - VerifySavedDocument(300, 400, flattened_page_checksum); } @@ -164,7 +162,6 @@ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - VerifySavedDocument(200, 200, checksum); } @@ -185,6 +182,5 @@ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - VerifySavedDocument(612, 792, checksum); }
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp index 5b7bc30..6b8e58e 100644 --- a/fpdfsdk/fpdf_formfill.cpp +++ b/fpdfsdk/fpdf_formfill.cpp
@@ -169,8 +169,9 @@ CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, FPDF_PAGE fpdf_page) { IPDF_Page* pPage = IPDFPageFromFPDFPage(fpdf_page); - if (!pPage) + if (!pPage) { return nullptr; + } CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); @@ -250,27 +251,31 @@ options.GetOptions().bClearType = !!(flags & FPDF_LCD_TEXT); // Grayscale output - if (flags & FPDF_GRAYSCALE) + if (flags & FPDF_GRAYSCALE) { options.SetColorMode(CPDF_RenderOptions::kGray); + } options.SetDrawAnnots(flags & FPDF_ANNOT); options.SetOCContext( pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::kView)); - if (pPageView) + if (pPageView) { pPageView->PageView_OnDraw(pDevice.get(), matrix, &options, rect); + } } } // Returns true if formfill version is correctly set. See |version| in // FPDF_FORMFILLINFO for details regarding correct version. bool CheckFormfillVersion(FPDF_FORMFILLINFO* formInfo) { - if (!formInfo || formInfo->version < 1 || formInfo->version > 2) + if (!formInfo || formInfo->version < 1 || formInfo->version > 2) { return false; + } #ifdef PDF_ENABLE_XFA - if (formInfo->version != 2) + if (formInfo->version != 2) { return false; + } #endif // PDF_ENABLE_XFA return true; @@ -286,16 +291,18 @@ const CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (pPage) { CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) + if (!pForm) { return -1; + } const CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); const CPDF_FormControl* pFormCtrl = pPDFForm->GetControlAtPoint( pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), nullptr); - if (!pFormCtrl) + if (!pFormCtrl) { return -1; + } const CPDF_FormField* pFormField = pFormCtrl->GetField(); return pFormField ? static_cast<int>(pFormField->GetFieldType()) : -1; } @@ -317,12 +324,14 @@ double page_x, double page_y) { CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) + if (!pForm) { return -1; + } CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return -1; + } CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); int z_order = -1; @@ -335,12 +344,14 @@ FPDF_EXPORT FPDF_FORMHANDLE FPDF_CALLCONV FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo) { - if (!CheckFormfillVersion(formInfo)) + if (!CheckFormfillVersion(formInfo)) { return nullptr; + } auto* pDocument = CPDFDocumentFromFPDFDocument(document); - if (!pDocument) + if (!pDocument) { return nullptr; + } #ifdef PDF_ENABLE_XFA CPDFXFA_Context* pContext = nullptr; @@ -364,8 +375,9 @@ std::make_unique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo); #ifdef PDF_ENABLE_XFA - if (pContext) + if (pContext) { pContext->SetFormFillEnv(pFormFillEnv.get()); + } #endif // PDF_ENABLE_XFA ReportUnsupportedXFA(pDocument); @@ -376,8 +388,9 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { - if (!hHandle) + if (!hHandle) { return; + } // Take back ownership of the form fill environment. This is the inverse of // FPDFDOC_InitFormFillEnvironment() above. @@ -392,8 +405,9 @@ // is now a nullptr. auto* pContext = static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension()); - if (pContext) + if (pContext) { pContext->SetFormFillEnv(nullptr); + } #endif // PDF_ENABLE_XFA } @@ -416,8 +430,9 @@ const FS_POINTF* page_coord, int delta_x, int delta_y) { - if (!page_coord) + if (!page_coord) { return false; + } CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); return pPageView && @@ -611,32 +626,36 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanUndo(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); - if (!pPageView) + if (!pPageView) { return false; + } return pPageView->CanUndo(); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanRedo(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); - if (!pPageView) + if (!pPageView) { return false; + } return pPageView->CanRedo(); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Undo(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); - if (!pPageView) + if (!pPageView) { return false; + } return pPageView->Undo(); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_Redo(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); - if (!pPageView) + if (!pPageView) { return false; + } return pPageView->Redo(); } @@ -644,8 +663,9 @@ FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } return pFormFillEnv->KillFocusAnnot({}); } @@ -653,13 +673,15 @@ FORM_GetFocusedAnnot(FPDF_FORMHANDLE handle, int* page_index, FPDF_ANNOTATION* annot) { - if (!page_index || !annot) + if (!page_index || !annot) { return false; + } CPDFSDK_FormFillEnvironment* form_fill_env = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(handle); - if (!form_fill_env) + if (!form_fill_env) { return false; + } // Set |page_index| and |annot| to default values. This is returned when there // is no focused annotation. @@ -667,20 +689,24 @@ *annot = nullptr; CPDFSDK_Annot* cpdfsdk_annot = form_fill_env->GetFocusAnnot(); - if (!cpdfsdk_annot) + if (!cpdfsdk_annot) { return true; + } // TODO(crbug.com/pdfium/1482): Handle XFA case. - if (cpdfsdk_annot->AsXFAWidget()) + if (cpdfsdk_annot->AsXFAWidget()) { return true; + } CPDFSDK_PageView* page_view = cpdfsdk_annot->GetPageView(); - if (!page_view->IsValid()) + if (!page_view->IsValid()) { return true; + } IPDF_Page* page = cpdfsdk_annot->GetPage(); - if (!page) + if (!page) { return true; + } RetainPtr<CPDF_Dictionary> annot_dict = cpdfsdk_annot->GetPDFAnnot()->GetMutableAnnotDict(); @@ -697,23 +723,27 @@ FORM_SetFocusedAnnot(FPDF_FORMHANDLE handle, FPDF_ANNOTATION annot) { CPDFSDK_FormFillEnvironment* form_fill_env = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(handle); - if (!form_fill_env) + if (!form_fill_env) { return false; + } CPDF_AnnotContext* annot_context = CPDFAnnotContextFromFPDFAnnotation(annot); - if (!annot_context) + if (!annot_context) { return false; + } CPDFSDK_PageView* page_view = form_fill_env->GetOrCreatePageView(annot_context->GetPage()); - if (!page_view->IsValid()) + if (!page_view->IsValid()) { return false; + } RetainPtr<CPDF_Dictionary> annot_dict = annot_context->GetMutableAnnotDict(); ObservedPtr<CPDFSDK_Annot> cpdfsdk_annot( page_view->GetAnnotByDict(annot_dict.Get())); - if (!cpdfsdk_annot) + if (!cpdfsdk_annot) { return false; + } return form_fill_env->SetFocusAnnot(cpdfsdk_annot); } @@ -765,13 +795,15 @@ int fieldType, unsigned long color) { CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) + if (!pForm) { return; + } std::optional<FormFieldType> cast_input = CPDF_FormField::IntToFormFieldType(fieldType); - if (!cast_input.has_value()) + if (!cast_input.has_value()) { return; + } if (cast_input.value() == FormFieldType::kUnknown) { pForm->SetAllHighlightColors(static_cast<FX_COLORREF>(color)); @@ -783,32 +815,37 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha) { - if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) + if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) { pForm->SetHighlightAlpha(alpha); + } } FPDF_EXPORT void FPDF_CALLCONV FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { - if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) + if (CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle)) { pForm->RemoveAllHighLights(); + } } FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle) { - if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) + if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) { pPageView->SetValid(true); + } } FPDF_EXPORT void FPDF_CALLCONV FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } IPDF_Page* pPage = IPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return; + } CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage); if (pPageView) { @@ -822,34 +859,39 @@ FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) + if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent()) { pFormFillEnv->ProcJavascriptAction(); + } } FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (pFormFillEnv) + if (pFormFillEnv) { pFormFillEnv->ProcOpenAction(); + } } FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); const CPDF_Dictionary* pDict = pDoc->GetRoot(); - if (!pDict) + if (!pDict) { return; + } CPDF_AAction aa(pDict->GetDictFor(pdfium::form_fields::kAA)); auto type = static_cast<CPDF_AAction::AActionType>(aaType); - if (aa.ActionExist(type)) + if (aa.ActionExist(type)) { pFormFillEnv->DoActionDocument(aa.GetAction(type), type); + } } FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, @@ -857,23 +899,27 @@ int aaType) { CPDFSDK_FormFillEnvironment* pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } IPDF_Page* pPage = IPDFPageFromFPDFPage(page); CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); - if (!pPDFPage) + if (!pPDFPage) { return; + } - if (!pFormFillEnv->GetPageView(pPage)) + if (!pFormFillEnv->GetPageView(pPage)) { return; + } CPDF_AAction aa(pPDFPage->GetDict()->GetDictFor(pdfium::form_fields::kAA)); CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN ? CPDF_AAction::kOpenPage : CPDF_AAction::kClosePage; - if (aa.ActionExist(type)) + if (aa.ActionExist(type)) { pFormFillEnv->DoActionPage(aa.GetAction(type), type); + } } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp index 1973f44..9614498 100644 --- a/fpdfsdk/fpdf_formfill_embeddertest.cpp +++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -930,8 +930,9 @@ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0)); // Subsequent tabs should move focus over annotations. - for (size_t i = 0; i < 9; ++i) + for (size_t i = 0; i < 9; ++i) { ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0)); + } // Tab should not be handled as the last annotation of the page is in focus. ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0)); @@ -1405,7 +1406,6 @@ CompareBitmap(bitmap.get(), 300, 300, checksum); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - } VerifySavedDocument(300, 300, checksum); } @@ -1445,7 +1445,6 @@ CompareBitmap(bitmap.get(), 300, 300, checksum); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - } VerifySavedDocument(300, 300, checksum); } @@ -1485,7 +1484,6 @@ CompareBitmap(bitmap.get(), 300, 300, checksum); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - } VerifySavedDocument(300, 300, checksum); } @@ -1533,7 +1531,6 @@ CompareBitmap(bitmap.get(), 300, 300, checksum); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - } VerifySavedDocument(300, 300, checksum); } @@ -3442,8 +3439,9 @@ FORM_OnMouseMove(form_handle(), page(), /*modifier=*/0, 100, 680); FORM_OnLButtonDown(form_handle(), page(), /*modifier=*/0, 100, 680); FORM_OnLButtonUp(form_handle(), page(), /*modifier=*/0, 100, 680); - for (size_t i = 1; i < n; i++) + for (size_t i = 1; i < n; i++) { ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Tab, 0)); + } } FPDF_PAGE page() { return page_; }
diff --git a/fpdfsdk/fpdf_javascript.cpp b/fpdfsdk/fpdf_javascript.cpp index 00a6632..c5a9555 100644 --- a/fpdfsdk/fpdf_javascript.cpp +++ b/fpdfsdk/fpdf_javascript.cpp
@@ -23,8 +23,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFDoc_GetJavaScriptActionCount(FPDF_DOCUMENT document) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return -1; + } auto name_tree = CPDF_NameTree::Create(doc, "JavaScript"); return name_tree ? pdfium::checked_cast<int>(name_tree->GetCount()) : 0; @@ -33,27 +34,32 @@ FPDF_EXPORT FPDF_JAVASCRIPT_ACTION FPDF_CALLCONV FPDFDoc_GetJavaScriptAction(FPDF_DOCUMENT document, int index) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc || index < 0) + if (!doc || index < 0) { return nullptr; + } auto name_tree = CPDF_NameTree::Create(doc, "JavaScript"); - if (!name_tree || static_cast<size_t>(index) >= name_tree->GetCount()) + if (!name_tree || static_cast<size_t>(index) >= name_tree->GetCount()) { return nullptr; + } WideString name; RetainPtr<CPDF_Dictionary> obj = ToDictionary(name_tree->LookupValueAndName(index, &name)); - if (!obj) + if (!obj) { return nullptr; + } // Validate |obj|. Type is optional, but must be valid if present. CPDF_Action action(std::move(obj)); - if (action.GetType() != CPDF_Action::Type::kJavaScript) + if (action.GetType() != CPDF_Action::Type::kJavaScript) { return nullptr; + } std::optional<WideString> script = action.MaybeGetJavaScript(); - if (!script.has_value()) + if (!script.has_value()) { return nullptr; + } auto js = std::make_unique<CPDF_JavaScript>(); js->name = name;
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index 7e67782..80aa475 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp
@@ -43,7 +43,6 @@ return page_indices; } - // Make sure arrays only contain objects of basic types. bool IsValidViewerPreferencesArray(const CPDF_Array* array) { CPDF_ArrayLocker locker(array); @@ -126,8 +125,9 @@ } std::vector<uint32_t> page_indices = GetPageIndices(*csrc_doc, pagerange); - if (page_indices.empty()) + if (page_indices.empty()) { return false; + } CPDF_PageExporter exporter(cdest_doc, csrc_doc); return exporter.ExportPages(page_indices, index); @@ -150,15 +150,17 @@ } ScopedFPDFDocument output_doc(FPDF_CreateNewDocument()); - if (!output_doc) + if (!output_doc) { return nullptr; + } CPDF_Document* dest_doc = CPDFDocumentFromFPDFDocument(output_doc.get()); DCHECK(dest_doc); std::vector<uint32_t> page_indices = GetPageIndices(*csrc_doc, ByteString()); - if (page_indices.empty()) + if (page_indices.empty()) { return nullptr; + } if (pages_on_x_axis == 1 && pages_on_y_axis == 1) { CPDF_PageExporter exporter(dest_doc, csrc_doc); @@ -182,12 +184,14 @@ FPDF_DOCUMENT src_doc, int src_page_index) { CPDF_Document* dest = CPDFDocumentFromFPDFDocument(dest_doc); - if (!dest) + if (!dest) { return nullptr; + } CPDF_Document* src = CPDFDocumentFromFPDFDocument(src_doc); - if (!src) + if (!src) { return nullptr; + } CPDF_NPageToOneExporter exporter(dest, src); std::unique_ptr<XObjectContext> xobject = @@ -203,8 +207,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDF_NewFormObjectFromXObject(FPDF_XOBJECT xobject) { XObjectContext* xobj = XObjectContextFromFPDFXObject(xobject); - if (!xobj) + if (!xobj) { return nullptr; + } auto form = std::make_unique<CPDF_Form>(xobj->dest_doc, nullptr, xobj->xobject, nullptr);
diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp index 1064cef..e672da9 100644 --- a/fpdfsdk/fpdf_ppo_embeddertest.cpp +++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp
@@ -244,35 +244,36 @@ } } - for (int i = 0; i < kExpectedPageCount; ++i) { - float left; - float bottom; - float right; - float top; - ASSERT_TRUE( - FPDFPageObj_GetBounds(xobjects[i], &left, &bottom, &right, &top)); - EXPECT_FLOAT_EQ(-1.0f, left); - EXPECT_FLOAT_EQ(-1.0f, bottom); - EXPECT_FLOAT_EQ(201.0f, right); - EXPECT_FLOAT_EQ(301.0f, top); - } + for (int i = 0; i < kExpectedPageCount; ++i) { + float left; + float bottom; + float right; + float top; + ASSERT_TRUE( + FPDFPageObj_GetBounds(xobjects[i], &left, &bottom, &right, &top)); + EXPECT_FLOAT_EQ(-1.0f, left); + EXPECT_FLOAT_EQ(-1.0f, bottom); + EXPECT_FLOAT_EQ(201.0f, right); + EXPECT_FLOAT_EQ(301.0f, top); + } - // Peek at object internals to make sure the two XObjects use the same - // stream. - EXPECT_NE(xobjects[0], xobjects[1]); - CPDF_PageObject* obj1 = CPDFPageObjectFromFPDFPageObject(xobjects[0]); - ASSERT_TRUE(obj1->AsForm()); - ASSERT_TRUE(obj1->AsForm()->form()); - ASSERT_TRUE(obj1->AsForm()->form()->GetStream()); - CPDF_PageObject* obj2 = CPDFPageObjectFromFPDFPageObject(xobjects[1]); - ASSERT_TRUE(obj2->AsForm()); - ASSERT_TRUE(obj2->AsForm()->form()); - ASSERT_TRUE(obj2->AsForm()->form()->GetStream()); - EXPECT_EQ(obj1->AsForm()->form()->GetStream(), - obj2->AsForm()->form()->GetStream()); + // Peek at object internals to make sure the two XObjects use the same + // stream. + EXPECT_NE(xobjects[0], xobjects[1]); + CPDF_PageObject* obj1 = CPDFPageObjectFromFPDFPageObject(xobjects[0]); + ASSERT_TRUE(obj1->AsForm()); + ASSERT_TRUE(obj1->AsForm()->form()); + ASSERT_TRUE(obj1->AsForm()->form()->GetStream()); + CPDF_PageObject* obj2 = CPDFPageObjectFromFPDFPageObject(xobjects[1]); + ASSERT_TRUE(obj2->AsForm()); + ASSERT_TRUE(obj2->AsForm()->form()); + ASSERT_TRUE(obj2->AsForm()->form()->GetStream()); + EXPECT_EQ(obj1->AsForm()->form()->GetStream(), + obj2->AsForm()->form()->GetStream()); - for (FPDF_PAGE saved_page : saved_pages) + for (FPDF_PAGE saved_page : saved_pages) { CloseSavedPage(saved_page); + } CloseSavedDocument(); }
diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp index 2af73ce..e74a2c5 100644 --- a/fpdfsdk/fpdf_progressive.cpp +++ b/fpdfsdk/fpdf_progressive.cpp
@@ -132,17 +132,20 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPage_Continue(FPDF_PAGE page, IFSDK_PAUSE* pause) { - if (!pause || pause->version != 1) + if (!pause || pause->version != 1) { return FPDF_RENDER_FAILED; + } CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return FPDF_RENDER_FAILED; + } auto* pContext = static_cast<CPDF_PageRenderContext*>(pPage->GetRenderContext()); - if (!pContext || !pContext->m_pRenderer) + if (!pContext || !pContext->m_pRenderer) { return FPDF_RENDER_FAILED; + } CPDFSDK_PauseAdapter pause_adapter(pause); pContext->m_pRenderer->Continue(&pause_adapter); @@ -162,6 +165,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage_Close(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (pPage) + if (pPage) { pPage->ClearRenderContext(); + } }
diff --git a/fpdfsdk/fpdf_save.cpp b/fpdfsdk/fpdf_save.cpp index 8dee668..597b5ae 100644 --- a/fpdfsdk/fpdf_save.cpp +++ b/fpdfsdk/fpdf_save.cpp
@@ -36,43 +36,52 @@ #ifdef PDF_ENABLE_XFA bool SaveXFADocumentData(CPDFXFA_Context* pContext, std::vector<RetainPtr<IFX_SeekableStream>>* fileList) { - if (!pContext) + if (!pContext) { return false; + } - if (!pContext->ContainsExtensionForm()) + if (!pContext->ContainsExtensionForm()) { return true; + } CPDF_Document* pPDFDocument = pContext->GetPDFDoc(); - if (!pPDFDocument) + if (!pPDFDocument) { return false; + } RetainPtr<CPDF_Dictionary> pRoot = pPDFDocument->GetMutableRoot(); - if (!pRoot) + if (!pRoot) { return false; + } RetainPtr<CPDF_Dictionary> pAcroForm = pRoot->GetMutableDictFor("AcroForm"); - if (!pAcroForm) + if (!pAcroForm) { return false; + } RetainPtr<CPDF_Object> pXFA = pAcroForm->GetMutableObjectFor("XFA"); - if (!pXFA) + if (!pXFA) { return true; + } CPDF_Array* pArray = pXFA->AsMutableArray(); - if (!pArray) + if (!pArray) { return false; + } int size = fxcrt::CollectionSize<int>(*pArray); int iFormIndex = -1; int iDataSetsIndex = -1; for (int i = 0; i < size - 1; i++) { RetainPtr<const CPDF_Object> pPDFObj = pArray->GetObjectAt(i); - if (!pPDFObj->IsString()) + if (!pPDFObj->IsString()) { continue; - if (pPDFObj->GetString() == "form") + } + if (pPDFObj->GetString() == "form") { iFormIndex = i + 1; - else if (pPDFObj->GetString() == "datasets") + } else if (pPDFObj->GetString() == "datasets") { iDataSetsIndex = i + 1; + } } RetainPtr<CPDF_Stream> pFormStream; @@ -155,8 +164,9 @@ FPDF_DWORD flags, std::optional<int> version) { CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document); - if (!pPDFDoc) + if (!pPDFDoc) { return false; + } #ifdef PDF_ENABLE_XFA auto* pContext = static_cast<CPDFXFA_Context*>(pPDFDoc->GetExtension()); @@ -167,13 +177,15 @@ } #endif // PDF_ENABLE_XFA - if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) + if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { flags = 0; + } CPDF_Creator fileMaker( pPDFDoc, pdfium::MakeRetain<CPDFSDK_FileWriteAdapter>(pFileWrite)); - if (version.has_value()) + if (version.has_value()) { fileMaker.SetFileVersion(version.value()); + } if (flags == FPDF_REMOVE_SECURITY) { flags = 0; fileMaker.RemoveSecurity(); @@ -182,8 +194,9 @@ bool bRet = fileMaker.Create(static_cast<uint32_t>(flags)); #ifdef PDF_ENABLE_XFA - if (pContext) + if (pContext) { pContext->SendPostSaveToXFADoc(); + } #endif // PDF_ENABLE_XFA return bRet;
diff --git a/fpdfsdk/fpdf_save_embeddertest.cpp b/fpdfsdk/fpdf_save_embeddertest.cpp index 16dc4ae..d3b679f 100644 --- a/fpdfsdk/fpdf_save_embeddertest.cpp +++ b/fpdfsdk/fpdf_save_embeddertest.cpp
@@ -90,7 +90,6 @@ EXPECT_TRUE(output_doc); EXPECT_TRUE(FPDF_ImportPages(output_doc.get(), document(), "1", 0)); EXPECT_TRUE(FPDF_SaveAsCopy(output_doc.get(), this, 0)); - } TEST_F(FPDFSaveEmbedderTest, Bug42271133) {
diff --git a/fpdfsdk/fpdf_searchex.cpp b/fpdfsdk/fpdf_searchex.cpp index 74cdff1..7c9e61d 100644 --- a/fpdfsdk/fpdf_searchex.cpp +++ b/fpdfsdk/fpdf_searchex.cpp
@@ -11,16 +11,18 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetCharIndexFromTextIndex(FPDF_TEXTPAGE text_page, int nTextIndex) { - if (!text_page) + if (!text_page) { return -1; + } return CPDFTextPageFromFPDFTextPage(text_page)->CharIndexFromTextIndex( nTextIndex); } FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextIndexFromCharIndex(FPDF_TEXTPAGE text_page, int nCharIndex) { - if (!text_page) + if (!text_page) { return -1; + } return CPDFTextPageFromFPDFTextPage(text_page)->TextIndexFromCharIndex( nCharIndex); }
diff --git a/fpdfsdk/fpdf_signature.cpp b/fpdfsdk/fpdf_signature.cpp index 25c0983..99c5147 100644 --- a/fpdfsdk/fpdf_signature.cpp +++ b/fpdfsdk/fpdf_signature.cpp
@@ -25,16 +25,19 @@ CPDF_Document* doc) { std::vector<RetainPtr<const CPDF_Dictionary>> signatures; const CPDF_Dictionary* root = doc->GetRoot(); - if (!root) + if (!root) { return signatures; + } RetainPtr<const CPDF_Dictionary> acro_form = root->GetDictFor("AcroForm"); - if (!acro_form) + if (!acro_form) { return signatures; + } RetainPtr<const CPDF_Array> fields = acro_form->GetArrayFor("Fields"); - if (!fields) + if (!fields) { return signatures; + } CPDF_ArrayLocker locker(std::move(fields)); for (auto& field : locker) { @@ -51,8 +54,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetSignatureCount(FPDF_DOCUMENT document) { auto* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return -1; + } return fxcrt::CollectionSize<int>(CollectSignatures(doc)); } @@ -60,13 +64,15 @@ FPDF_EXPORT FPDF_SIGNATURE FPDF_CALLCONV FPDF_GetSignatureObject(FPDF_DOCUMENT document, int index) { auto* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return nullptr; + } std::vector<RetainPtr<const CPDF_Dictionary>> signatures = CollectSignatures(doc); - if (!fxcrt::IndexInBounds(signatures, index)) + if (!fxcrt::IndexInBounds(signatures, index)) { return nullptr; + } return FPDFSignatureFromCPDFDictionary(signatures[index].Get()); } @@ -98,17 +104,20 @@ unsigned long length) { const CPDF_Dictionary* signature_dict = CPDFDictionaryFromFPDFSignature(signature); - if (!signature_dict) + if (!signature_dict) { return 0; + } RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor(pdfium::form_fields::kV); - if (!value_dict) + if (!value_dict) { return 0; + } RetainPtr<const CPDF_Array> byte_range = value_dict->GetArrayFor("ByteRange"); - if (!byte_range) + if (!byte_range) { return 0; + } const unsigned long byte_range_len = fxcrt::CollectionSize<unsigned long>(*byte_range); @@ -128,13 +137,15 @@ unsigned long length) { const CPDF_Dictionary* signature_dict = CPDFDictionaryFromFPDFSignature(signature); - if (!signature_dict) + if (!signature_dict) { return 0; + } RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor(pdfium::form_fields::kV); - if (!value_dict || !value_dict->KeyExist("SubFilter")) + if (!value_dict || !value_dict->KeyExist("SubFilter")) { return 0; + } ByteString sub_filter = value_dict->GetNameFor("SubFilter"); @@ -149,17 +160,20 @@ unsigned long length) { const CPDF_Dictionary* signature_dict = CPDFDictionaryFromFPDFSignature(signature); - if (!signature_dict) + if (!signature_dict) { return 0; + } RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor(pdfium::form_fields::kV); - if (!value_dict) + if (!value_dict) { return 0; + } RetainPtr<const CPDF_Object> obj = value_dict->GetObjectFor("Reason"); - if (!obj || !obj->IsString()) + if (!obj || !obj->IsString()) { return 0; + } // SAFETY: required from caller. return Utf16EncodeMaybeCopyAndReturnLength( @@ -173,17 +187,20 @@ unsigned long length) { const CPDF_Dictionary* signature_dict = CPDFDictionaryFromFPDFSignature(signature); - if (!signature_dict) + if (!signature_dict) { return 0; + } RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor(pdfium::form_fields::kV); - if (!value_dict) + if (!value_dict) { return 0; + } RetainPtr<const CPDF_Object> obj = value_dict->GetObjectFor("M"); - if (!obj || !obj->IsString()) + if (!obj || !obj->IsString()) { return 0; + } // SAFETY: required from caller. return NulTerminateMaybeCopyAndReturnLength( @@ -195,37 +212,44 @@ int permission = 0; const CPDF_Dictionary* signature_dict = CPDFDictionaryFromFPDFSignature(signature); - if (!signature_dict) + if (!signature_dict) { return permission; + } RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor(pdfium::form_fields::kV); - if (!value_dict) + if (!value_dict) { return permission; + } RetainPtr<const CPDF_Array> references = value_dict->GetArrayFor("Reference"); - if (!references) + if (!references) { return permission; + } CPDF_ArrayLocker locker(std::move(references)); for (auto& reference : locker) { RetainPtr<const CPDF_Dictionary> reference_dict = reference->GetDict(); - if (!reference_dict) + if (!reference_dict) { continue; + } ByteString transform_method = reference_dict->GetNameFor("TransformMethod"); - if (transform_method != "DocMDP") + if (transform_method != "DocMDP") { continue; + } RetainPtr<const CPDF_Dictionary> transform_params = reference_dict->GetDictFor("TransformParams"); - if (!transform_params) + if (!transform_params) { continue; + } // Valid values are 1, 2 and 3; 2 is the default. permission = transform_params->GetIntegerFor("P", 2); - if (permission < 1 || permission > 3) + if (permission < 1 || permission > 3) { permission = 0; + } return permission; }
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp index 41778cd..ab37c6a 100644 --- a/fpdfsdk/fpdf_structtree.cpp +++ b/fpdfsdk/fpdf_structtree.cpp
@@ -34,8 +34,9 @@ int GetMcidFromDict(const CPDF_Dictionary* dict) { if (dict && dict->GetNameFor("Type") == "MCR") { RetainPtr<const CPDF_Object> obj = dict->GetObjectFor("MCID"); - if (obj && obj->IsNumber()) + if (obj && obj->IsNumber()) { return obj->GetInteger(); + } } return -1; } @@ -45,8 +46,9 @@ FPDF_EXPORT FPDF_STRUCTTREE FPDF_CALLCONV FPDF_StructTree_GetForPage(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return nullptr; + } // Caller takes onwership. return FPDFStructTreeFromCPDFStructTree( @@ -63,8 +65,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) { CPDF_StructTree* tree = CPDFStructTreeFromFPDFStructTree(struct_tree); - if (!tree) + if (!tree) { return -1; + } FX_SAFE_INT32 tmp_size = tree->CountTopElements(); return tmp_size.ValueOrDefault(-1); @@ -148,17 +151,20 @@ FPDF_StructElement_GetAttributeCount(FPDF_STRUCTELEMENT struct_element) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return -1; + } RetainPtr<const CPDF_Object> attr_obj = elem->GetA(); if (!attr_obj) { return -1; } attr_obj = attr_obj->GetDirect(); - if (!attr_obj) + if (!attr_obj) { return -1; - if (attr_obj->IsArray()) + } + if (attr_obj->IsArray()) { return fxcrt::CollectionSize<int>(*attr_obj->AsArray()); + } return attr_obj->IsDictionary() ? 1 : -1; } @@ -167,12 +173,14 @@ int index) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return nullptr; + } RetainPtr<const CPDF_Object> attr_obj = elem->GetA(); - if (!attr_obj) + if (!attr_obj) { return nullptr; + } attr_obj = attr_obj->GetDirect(); if (!attr_obj) { @@ -185,8 +193,9 @@ } if (attr_obj->IsArray()) { const CPDF_Array* array = attr_obj->AsArray(); - if (index < 0 || static_cast<size_t>(index) >= array->size()) + if (index < 0 || static_cast<size_t>(index) >= array->size()) { return nullptr; + } // TODO(tsepez): should embedder take a reference here? // Unretained reference in public API. NOLINTNEXTLINE @@ -202,11 +211,13 @@ unsigned long buflen) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return 0; + } RetainPtr<const CPDF_Array> array = ToArray(elem->GetA()); - if (!array) + if (!array) { return 0; + } CPDF_ArrayLocker locker(array); for (const RetainPtr<CPDF_Object>& obj : locker) { const CPDF_Dictionary* obj_dict = obj->AsDictionary(); @@ -229,8 +240,9 @@ FPDF_StructElement_GetMarkedContentID(FPDF_STRUCTELEMENT struct_element) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return -1; + } RetainPtr<const CPDF_Object> p = elem->GetK(); return p && p->IsNumber() ? p->GetInteger() : -1; } @@ -280,8 +292,9 @@ FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return -1; + } FX_SAFE_INT32 tmp_size = elem->CountKids(); return tmp_size.ValueOrDefault(-1); @@ -292,8 +305,9 @@ int index) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem || index < 0 || static_cast<size_t>(index) >= elem->CountKids()) + if (!elem || index < 0 || static_cast<size_t>(index) >= elem->CountKids()) { return nullptr; + } return FPDFStructElementFromCPDFStructElement(elem->GetKidIfElement(index)); } @@ -325,8 +339,9 @@ FPDF_StructElement_Attr_GetCount(FPDF_STRUCTELEMENT_ATTR struct_attribute) { const CPDF_Dictionary* dict = CPDFDictionaryFromFPDFStructElementAttr(struct_attribute); - if (!dict) + if (!dict) { return -1; + } return fxcrt::CollectionSize<int>(*dict); } @@ -342,8 +357,9 @@ const CPDF_Dictionary* dict = CPDFDictionaryFromFPDFStructElementAttr(struct_attribute); - if (!dict) + if (!dict) { return false; + } CPDF_DictionaryLocker locker(dict); for (auto& it : locker) { @@ -477,14 +493,17 @@ FPDF_StructElement_GetMarkedContentIdCount(FPDF_STRUCTELEMENT struct_element) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return -1; + } RetainPtr<const CPDF_Object> p = elem->GetK(); - if (!p) + if (!p) { return -1; + } - if (p->IsNumber() || p->IsDictionary()) + if (p->IsNumber() || p->IsDictionary()) { return 1; + } return p->IsArray() ? fxcrt::CollectionSize<int>(*p->AsArray()) : -1; } @@ -494,25 +513,31 @@ int index) { CPDF_StructElement* elem = CPDFStructElementFromFPDFStructElement(struct_element); - if (!elem) + if (!elem) { return -1; + } RetainPtr<const CPDF_Object> p = elem->GetK(); - if (!p) + if (!p) { return -1; + } - if (p->IsNumber()) + if (p->IsNumber()) { return index == 0 ? p->GetInteger() : -1; + } - if (p->IsDictionary()) + if (p->IsDictionary()) { return GetMcidFromDict(p->GetDict().Get()); + } if (p->IsArray()) { const CPDF_Array* array = p->AsArray(); - if (index < 0 || static_cast<size_t>(index) >= array->size()) + if (index < 0 || static_cast<size_t>(index) >= array->size()) { return -1; + } RetainPtr<const CPDF_Object> array_elem = array->GetObjectAt(index); - if (array_elem->IsNumber()) + if (array_elem->IsNumber()) { return array_elem->GetInteger(); + } if (array_elem->IsDictionary()) { return GetMcidFromDict(array_elem->GetDict().Get()); }
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index 9f2d6a6..7dc1e71 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -115,8 +115,9 @@ return false; } unsigned long size = info_->GetFaceName(info_, hFont, nullptr, 0); - if (size == 0) + if (size == 0) { return false; + } ByteString result; auto result_span = result.GetBuffer(size); size = info_->GetFaceName(info_, hFont, result_span.data(), size); @@ -160,8 +161,9 @@ return; } - if (pFontInfoExt->version != 1) + if (pFontInfoExt->version != 1) { return; + } mapper->SetSystemFontInfo( std::make_unique<CFX_ExternalFontInfo>(pFontInfoExt)); @@ -270,8 +272,9 @@ FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo() { std::unique_ptr<SystemFontInfoIface> pFontInfo = CFX_GEModule::Get()->GetPlatform()->CreateDefaultSystemFontInfo(); - if (!pFontInfo) + if (!pFontInfo) { return nullptr; + } FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt = FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1);
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp index 9148cb2..d1aaf66 100644 --- a/fpdfsdk/fpdf_text.cpp +++ b/fpdfsdk/fpdf_text.cpp
@@ -31,8 +31,9 @@ namespace { CPDF_TextPage* GetTextPageForValidIndex(FPDF_TEXTPAGE text_page, int index) { - if (!text_page || index < 0) + if (!text_page || index < 0) { return nullptr; + } CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); return static_cast<size_t>(index) < textpage->size() ? textpage : nullptr; @@ -42,8 +43,9 @@ FPDF_EXPORT FPDF_TEXTPAGE FPDF_CALLCONV FPDFText_LoadPage(FPDF_PAGE page) { CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); - if (!pPDFPage) + if (!pPDFPage) { return nullptr; + } CPDF_ViewerPreferences viewRef(pPDFPage->GetDocument()); auto textpage = @@ -67,8 +69,9 @@ FPDF_EXPORT unsigned int FPDF_CALLCONV FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, int index) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return 0; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); return charinfo.unicode(); @@ -88,8 +91,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_IsGenerated(FPDF_TEXTPAGE text_page, int index) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return -1; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); return charinfo.char_type() == CPDF_TextPage::CharType::kGenerated ? 1 : 0; @@ -109,8 +113,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_HasUnicodeMapError(FPDF_TEXTPAGE text_page, int index) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return -1; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); return charinfo.char_type() == CPDF_TextPage::CharType::kNotUnicode; @@ -119,8 +124,9 @@ FPDF_EXPORT double FPDF_CALLCONV FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, int index) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return 0; + } return textpage->GetCharFontSize(index); } @@ -132,8 +138,9 @@ unsigned long buflen, int* flags) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return 0; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); if (!charinfo.text_object()) { @@ -141,8 +148,9 @@ } RetainPtr<CPDF_Font> font = charinfo.text_object()->GetFont(); - if (flags) + if (flags) { *flags = font->GetFontFlags(); + } // SAFETY: required from caller. auto result_span = UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, buflen)); @@ -175,8 +183,9 @@ unsigned int* B, unsigned int* A) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage || !R || !G || !B || !A) + if (!textpage || !R || !G || !B || !A) { return false; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); if (!charinfo.text_object()) { @@ -201,8 +210,9 @@ unsigned int* B, unsigned int* A) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage || !R || !G || !B || !A) + if (!textpage || !R || !G || !B || !A) { return false; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); if (!charinfo.text_object()) { @@ -222,8 +232,9 @@ FPDF_EXPORT float FPDF_CALLCONV FPDFText_GetCharAngle(FPDF_TEXTPAGE text_page, int index) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return -1.0f; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); // On the left is our current Matrix and on the right a generic rotation @@ -233,8 +244,9 @@ // | e f 1 | | 0 0 1 | // Calculate the angle of the vector float angle = atan2f(charinfo.matrix().c, charinfo.matrix().a); - if (angle < 0) + if (angle < 0) { angle = 2 * FXSYS_PI + angle; + } return angle; } @@ -245,12 +257,14 @@ double* right, double* bottom, double* top) { - if (!left || !right || !bottom || !top) + if (!left || !right || !bottom || !top) { return false; + } CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return false; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); *left = charinfo.char_box().left; @@ -262,12 +276,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetLooseCharBox(FPDF_TEXTPAGE text_page, int index, FS_RECTF* rect) { - if (!rect) + if (!rect) { return false; + } CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return false; + } *rect = FSRectFFromCFXFloatRect(textpage->GetCharLooseBounds(index)); return true; @@ -276,12 +292,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetMatrix(FPDF_TEXTPAGE text_page, int index, FS_MATRIX* matrix) { - if (!matrix) + if (!matrix) { return false; + } CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return false; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); *matrix = FSMatrixFromCFXMatrix(charinfo.matrix()); @@ -294,8 +312,9 @@ double* x, double* y) { CPDF_TextPage* textpage = GetTextPageForValidIndex(text_page, index); - if (!textpage) + if (!textpage) { return false; + } const CPDF_TextPage::CharInfo& charinfo = textpage->GetCharInfo(index); *x = charinfo.origin().x; @@ -310,8 +329,9 @@ double xTolerance, double yTolerance) { CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); - if (!textpage) + if (!textpage) { return -3; + } return textpage->GetIndexAtPos( CFX_PointF(static_cast<float>(x), static_cast<float>(y)), @@ -367,8 +387,9 @@ double* right, double* bottom) { CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); - if (!textpage) + if (!textpage) { return false; + } CFX_FloatRect rect; bool result = textpage->GetRect(rect_index, &rect); @@ -417,8 +438,9 @@ unsigned long flags, int start_index) { CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); - if (!textpage) + if (!textpage) { return nullptr; + } CPDF_TextPageFind::Options options; options.bMatchCase = !!(flags & FPDF_MATCHCASE); @@ -435,16 +457,18 @@ } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_FindNext(FPDF_SCHHANDLE handle) { - if (!handle) + if (!handle) { return false; + } CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); return textpageFind->FindNext(); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_FindPrev(FPDF_SCHHANDLE handle) { - if (!handle) + if (!handle) { return false; + } CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); return textpageFind->FindPrev(); @@ -452,24 +476,27 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetSchResultIndex(FPDF_SCHHANDLE handle) { - if (!handle) + if (!handle) { return 0; + } CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); return textpageFind->GetCurOrder(); } FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetSchCount(FPDF_SCHHANDLE handle) { - if (!handle) + if (!handle) { return 0; + } CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); return textpageFind->GetMatchedCount(); } FPDF_EXPORT void FPDF_CALLCONV FPDFText_FindClose(FPDF_SCHHANDLE handle) { - if (!handle) + if (!handle) { return; + } // Take ownership back from caller and destroy. std::unique_ptr<CPDF_TextPageFind> textpageFind( @@ -480,8 +507,9 @@ FPDF_EXPORT FPDF_PAGELINK FPDF_CALLCONV FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) { CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); - if (!textpage) + if (!textpage) { return nullptr; + } auto pagelink = std::make_unique<CPDF_LinkExtract>(textpage); pagelink->ExtractLinks(); @@ -491,8 +519,9 @@ } FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountWebLinks(FPDF_PAGELINK link_page) { - if (!link_page) + if (!link_page) { return 0; + } CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); return pdfium::checked_cast<int>(pageLink->CountLinks()); @@ -525,8 +554,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountRects(FPDF_PAGELINK link_page, int link_index) { - if (!link_page || link_index < 0) + if (!link_page || link_index < 0) { return 0; + } CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); return fxcrt::CollectionSize<int>(pageLink->GetRects(link_index)); @@ -539,13 +569,15 @@ double* top, double* right, double* bottom) { - if (!link_page || link_index < 0 || rect_index < 0) + if (!link_page || link_index < 0 || rect_index < 0) { return false; + } CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); std::vector<CFX_FloatRect> rectArray = pageLink->GetRects(link_index); - if (rect_index >= fxcrt::CollectionSize<int>(rectArray)) + if (rect_index >= fxcrt::CollectionSize<int>(rectArray)) { return false; + } *left = rectArray[rect_index].left; *right = rectArray[rect_index].right; @@ -559,13 +591,15 @@ int link_index, int* start_char_index, int* char_count) { - if (!link_page || link_index < 0) + if (!link_page || link_index < 0) { return false; + } CPDF_LinkExtract* page_link = CPDFLinkExtractFromFPDFPageLink(link_page); auto maybe_range = page_link->GetTextRange(link_index); - if (!maybe_range.has_value()) + if (!maybe_range.has_value()) { return false; + } *start_char_index = pdfium::checked_cast<int>(maybe_range.value().m_Start); *char_count = pdfium::checked_cast<int>(maybe_range.value().m_Count);
diff --git a/fpdfsdk/fpdf_thumbnail.cpp b/fpdfsdk/fpdf_thumbnail.cpp index 4fb7965..547c7b0 100644 --- a/fpdfsdk/fpdf_thumbnail.cpp +++ b/fpdfsdk/fpdf_thumbnail.cpp
@@ -21,12 +21,14 @@ RetainPtr<const CPDF_Stream> CPDFStreamForThumbnailFromPage(FPDF_PAGE page) { const CPDF_Page* pdf_page = CPDFPageFromFPDFPage(page); - if (!pdf_page) + if (!pdf_page) { return nullptr; + } RetainPtr<const CPDF_Dictionary> page_dict = pdf_page->GetDict(); - if (!page_dict->KeyExist("Type")) + if (!page_dict->KeyExist("Type")) { return nullptr; + } return page_dict->GetStreamFor("Thumb"); } @@ -39,8 +41,9 @@ unsigned long buflen) { RetainPtr<const CPDF_Stream> thumb_stream = CPDFStreamForThumbnailFromPage(page); - if (!thumb_stream) + if (!thumb_stream) { return 0u; + } // SAFETY: caller ensures `buffer` points to at least `buflen` bytes. return DecodeStreamMaybeCopyAndReturnLength( @@ -55,8 +58,9 @@ unsigned long buflen) { RetainPtr<const CPDF_Stream> thumb_stream = CPDFStreamForThumbnailFromPage(page); - if (!thumb_stream) + if (!thumb_stream) { return 0u; + } // SAFETY: caller ensures `buffer` points to at least `buflen` bytes. return GetRawStreamMaybeCopyAndReturnLength( @@ -69,8 +73,9 @@ FPDFPage_GetThumbnailAsBitmap(FPDF_PAGE page) { RetainPtr<const CPDF_Stream> thumb_stream = CPDFStreamForThumbnailFromPage(page); - if (!thumb_stream) + if (!thumb_stream) { return nullptr; + } const CPDF_Page* pdf_page = CPDFPageFromFPDFPage(page); auto dib_source = pdfium::MakeRetain<CPDF_DIB>(pdf_page->GetDocument(), @@ -78,8 +83,9 @@ const CPDF_DIB::LoadState start_status = dib_source->StartLoadDIBBase( false, nullptr, pdf_page->GetPageResources().Get(), false, CPDF_ColorSpace::Family::kUnknown, false, {0, 0}); - if (start_status == CPDF_DIB::LoadState::kFail) + if (start_status == CPDF_DIB::LoadState::kFail) { return nullptr; + } auto thumb_bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); if (!thumb_bitmap->Copy(std::move(dib_source))) {
diff --git a/fpdfsdk/fpdf_thumbnail_embeddertest.cpp b/fpdfsdk/fpdf_thumbnail_embeddertest.cpp index 8566b5f..bad42a4 100644 --- a/fpdfsdk/fpdf_thumbnail_embeddertest.cpp +++ b/fpdfsdk/fpdf_thumbnail_embeddertest.cpp
@@ -37,7 +37,6 @@ EXPECT_EQ(kExpectedSize, FPDFPage_GetDecodedThumbnailData( page.get(), thumb_buf.data(), length_bytes)); EXPECT_EQ(kHashedDecodedData, GenerateMD5Base16(thumb_buf)); - } { @@ -55,7 +54,6 @@ EXPECT_EQ(kExpectedSize, FPDFPage_GetDecodedThumbnailData( page.get(), thumb_buf.data(), length_bytes)); EXPECT_EQ(kHashedDecodedData, GenerateMD5Base16(thumb_buf)); - } } @@ -109,7 +107,6 @@ EXPECT_EQ(kExpectedSize, FPDFPage_GetRawThumbnailData( page.get(), thumb_buf.data(), length_bytes)); EXPECT_EQ(kSimpleThumbnailChecksum, GenerateMD5Base16(thumb_buf)); - } { @@ -127,7 +124,6 @@ EXPECT_EQ(kExpectedSize, FPDFPage_GetRawThumbnailData( page.get(), thumb_buf.data(), length_bytes)); EXPECT_EQ(kHashedRawData, GenerateMD5Base16(thumb_buf)); - } } @@ -176,7 +172,6 @@ EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(thumb_bitmap.get())); CompareBitmap(thumb_bitmap.get(), 50, 50, "52b75451e396f55e95d1cb68e6018226"); - } { @@ -190,7 +185,6 @@ EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(thumb_bitmap.get())); CompareBitmap(thumb_bitmap.get(), 50, 50, "1f448be08c6e6043ccd0bad8ecc2a351"); - } }
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index de1ffe5..cc712b8 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -34,8 +34,9 @@ void SetBoundingBox(CPDF_Page* page, const ByteString& key, const CFX_FloatRect& rect) { - if (!page) + if (!page) { return; + } page->GetMutableDict()->SetRectFor(key, rect); page->UpdateDimensions(); @@ -47,12 +48,14 @@ float* bottom, float* right, float* top) { - if (!page || !left || !bottom || !right || !top) + if (!page || !left || !bottom || !right || !top) { return false; + } RetainPtr<const CPDF_Array> pArray = page->GetDict()->GetArrayFor(key); - if (!pArray) + if (!pArray) { return false; + } *left = pArray->GetFloatAt(0); *bottom = pArray->GetFloatAt(1); @@ -67,8 +70,9 @@ void OutputPath(fxcrt::ostringstream& buf, CPDF_Path path) { const CFX_Path* pPath = path.GetObject(); - if (!pPath) + if (!pPath) { return; + } pdfium::span<const CFX_Path::Point> points = pPath->GetPoints(); if (path.IsRect()) { @@ -87,15 +91,17 @@ buf << " " << points[i + 1].m_Point.x << " " << points[i + 1].m_Point.y << " " << points[i + 2].m_Point.x << " " << points[i + 2].m_Point.y; buf << " c"; - if (points[i + 2].m_CloseFigure) + if (points[i + 2].m_CloseFigure) { buf << " h"; + } buf << "\n"; i += 2; } else if (point_type == CFX_Path::Point::Type::kLine) { buf << " l"; - if (points[i].m_CloseFigure) + if (points[i].m_CloseFigure) { buf << " h"; + } buf << "\n"; } } @@ -201,21 +207,25 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, const FS_MATRIX* matrix, const FS_RECTF* clipRect) { - if (!matrix && !clipRect) + if (!matrix && !clipRect) { return false; + } CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return false; + } RetainPtr<CPDF_Dictionary> pPageDict = pPage->GetMutableDict(); RetainPtr<CPDF_Object> pContentObj = GetPageContent(pPageDict.Get()); - if (!pContentObj) + if (!pContentObj) { return false; + } CPDF_Document* pDoc = pPage->GetDocument(); - if (!pDoc) + if (!pDoc) { return false; + } fxcrt::ostringstream text_buf; text_buf << "q "; @@ -225,8 +235,9 @@ rect.Normalize(); WriteRect(text_buf, rect) << " re W* n "; } - if (matrix) + if (matrix) { WriteMatrix(text_buf, CFXMatrixFromFSMatrix(*matrix)) << " cm "; + } auto pStream = pDoc->NewIndirect<CPDF_Stream>(pDoc->New<CPDF_Dictionary>()); pStream->SetDataFromStringstream(&text_buf); @@ -251,26 +262,30 @@ // Need to transform the patterns as well. RetainPtr<const CPDF_Dictionary> pRes = pPageDict->GetDictFor(pdfium::page_object::kResources); - if (!pRes) + if (!pRes) { return true; + } RetainPtr<const CPDF_Dictionary> pPatternDict = pRes->GetDictFor("Pattern"); - if (!pPatternDict) + if (!pPatternDict) { return true; + } CPDF_DictionaryLocker locker(pPatternDict); for (const auto& it : locker) { RetainPtr<CPDF_Object> pObj = it.second; - if (pObj->IsReference()) + if (pObj->IsReference()) { pObj = pObj->GetMutableDirect(); + } RetainPtr<CPDF_Dictionary> pDict; - if (pObj->IsDictionary()) + if (pObj->IsDictionary()) { pDict.Reset(pObj->AsMutableDictionary()); - else if (CPDF_Stream* pObjStream = pObj->AsMutableStream()) + } else if (CPDF_Stream* pObjStream = pObj->AsMutableStream()) { pDict = pObjStream->GetMutableDict(); - else + } else { continue; + } if (matrix) { CFX_Matrix m = CFXMatrixFromFSMatrix(*matrix); @@ -290,30 +305,34 @@ double e, double f) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return; + } CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f); // Special treatment to shading object, because the ClipPath for shading // object is already transformed. - if (!pPageObj->IsShading()) + if (!pPageObj->IsShading()) { pPageObj->TransformClipPath(matrix); + } } FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV FPDFPageObj_GetClipPath(FPDF_PAGEOBJECT page_object) { CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) + if (!pPageObj) { return nullptr; + } return FPDFClipPathFromCPDFClipPath(&pPageObj->mutable_clip_path()); } FPDF_EXPORT int FPDF_CALLCONV FPDFClipPath_CountPaths(FPDF_CLIPPATH clip_path) { CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clip_path); - if (!pClipPath || !pClipPath->HasRef()) + if (!pClipPath || !pClipPath->HasRef()) { return -1; + } return pdfium::checked_cast<int>(pClipPath->GetPathCount()); } @@ -321,8 +340,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFClipPath_CountPathSegments(FPDF_CLIPPATH clip_path, int path_index) { CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clip_path); - if (!pClipPath || !pClipPath->HasRef()) + if (!pClipPath || !pClipPath->HasRef()) { return -1; + } if (path_index < 0 || static_cast<size_t>(path_index) >= pClipPath->GetPathCount()) { @@ -337,8 +357,9 @@ int path_index, int segment_index) { CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clip_path); - if (!pClipPath || !pClipPath->HasRef()) + if (!pClipPath || !pClipPath->HasRef()) { return nullptr; + } if (path_index < 0 || static_cast<size_t>(path_index) >= pClipPath->GetPathCount()) { @@ -347,8 +368,9 @@ pdfium::span<const CFX_Path::Point> points = pClipPath->GetPath(path_index).GetPoints(); - if (!fxcrt::IndexInBounds(points, segment_index)) + if (!fxcrt::IndexInBounds(points, segment_index)) { return nullptr; + } return FPDFPathSegmentFromFXPathPoint(&points[segment_index]); } @@ -375,13 +397,15 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, FPDF_CLIPPATH clipPath) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return; + } RetainPtr<CPDF_Dictionary> pPageDict = pPage->GetMutableDict(); RetainPtr<CPDF_Object> pContentObj = GetPageContent(pPageDict.Get()); - if (!pContentObj) + if (!pContentObj) { return; + } fxcrt::ostringstream strClip; CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clipPath); @@ -401,8 +425,9 @@ } } CPDF_Document* pDoc = pPage->GetDocument(); - if (!pDoc) + if (!pDoc) { return; + } auto pStream = pDoc->NewIndirect<CPDF_Stream>(pDoc->New<CPDF_Dictionary>()); pStream->SetDataFromStringstream(&strClip);
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 8bd14aa..58a42e2 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp
@@ -151,8 +151,9 @@ RetainPtr<const CPDF_Object> GetXFAEntryFromDocument(const CPDF_Document* doc) { const CPDF_Dictionary* root = doc->GetRoot(); - if (!root) + if (!root) { return nullptr; + } RetainPtr<const CPDF_Dictionary> acro_form = root->GetDictFor("AcroForm"); return acro_form ? acro_form->GetObjectFor("XFA") : nullptr; @@ -166,8 +167,9 @@ std::vector<XFAPacket> GetXFAPackets(RetainPtr<const CPDF_Object> xfa_object) { std::vector<XFAPacket> packets; - if (!xfa_object) + if (!xfa_object) { return packets; + } RetainPtr<const CPDF_Stream> xfa_stream = ToStream(xfa_object->GetDirect()); if (xfa_stream) { @@ -176,21 +178,25 @@ } RetainPtr<const CPDF_Array> xfa_array = ToArray(xfa_object->GetDirect()); - if (!xfa_array) + if (!xfa_array) { return packets; + } packets.reserve(1 + (xfa_array->size() / 2)); for (size_t i = 0; i < xfa_array->size(); i += 2) { - if (i + 1 == xfa_array->size()) + if (i + 1 == xfa_array->size()) { break; + } RetainPtr<const CPDF_String> name = xfa_array->GetStringAt(i); - if (!name) + if (!name) { continue; + } RetainPtr<const CPDF_Stream> data = xfa_array->GetStreamAt(i + 1); - if (!data) + if (!data) { continue; + } packets.push_back({name->GetString(), std::move(data)}); } @@ -227,8 +233,9 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* config) { - if (g_bLibraryInitialized) + if (g_bLibraryInitialized) { return; + } FX_InitializeMemoryAllocators(); CFX_Timer::InitializeGlobals(); @@ -248,15 +255,17 @@ IJS_Runtime::Initialize(config->m_v8EmbedderSlot, config->m_pIsolate, platform); - if (config->version >= 4) + if (config->version >= 4) { SetRendererType(config->m_RendererType); + } } g_bLibraryInitialized = true; } FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary() { - if (!g_bLibraryInitialized) + if (!g_bLibraryInitialized) { return; + } // Note: we teardown/destroy things in reverse order. ResetRendererType(); @@ -306,20 +315,24 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetFormType(FPDF_DOCUMENT document) { const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return FORMTYPE_NONE; + } const CPDF_Dictionary* pRoot = pDoc->GetRoot(); - if (!pRoot) + if (!pRoot) { return FORMTYPE_NONE; + } RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); - if (!pAcroForm) + if (!pAcroForm) { return FORMTYPE_NONE; + } RetainPtr<const CPDF_Object> pXFA = pAcroForm->GetObjectFor("XFA"); - if (!pXFA) + if (!pXFA) { return FORMTYPE_ACRO_FORM; + } bool bNeedsRendering = pRoot->GetBooleanFor("NeedsRendering", false); return bNeedsRendering ? FORMTYPE_XFA_FULL : FORMTYPE_XFA_FOREGROUND; @@ -328,12 +341,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_LoadXFA(FPDF_DOCUMENT document) { #ifdef PDF_ENABLE_XFA auto* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return false; + } auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension()); - if (pContext) + if (pContext) { return pContext->LoadXFADoc(); + } #endif // PDF_ENABLE_XFA return false; } @@ -364,25 +379,29 @@ FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password) { - if (!pFileAccess) + if (!pFileAccess) { return nullptr; + } return LoadDocumentImpl(pdfium::MakeRetain<CPDFSDK_CustomAccess>(pFileAccess), password); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVersion) { - if (!fileVersion) + if (!fileVersion) { return false; + } *fileVersion = 0; CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); - if (!pDoc) + if (!pDoc) { return false; + } const CPDF_Parser* pParser = pDoc->GetParser(); - if (!pParser) + if (!pParser) { return false; + } *fileVersion = pParser->GetFileVersion(); return true; @@ -409,8 +428,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc || !pDoc->GetParser()) + if (!pDoc || !pDoc->GetParser()) { return -1; + } RetainPtr<const CPDF_Dictionary> pDict = pDoc->GetParser()->GetEncryptDict(); return pDict ? pDict->GetIntegerFor("R") : -1; @@ -418,8 +438,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageCount(FPDF_DOCUMENT document) { auto* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 0; + } auto* pExtension = pDoc->GetExtension(); return pExtension ? pExtension->GetPageCount() : pDoc->GetPageCount(); @@ -428,11 +449,13 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, int page_index) { auto* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } - if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) + if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) { return nullptr; + } #ifdef PDF_ENABLE_XFA auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension()); @@ -443,8 +466,9 @@ #endif // PDF_ENABLE_XFA RetainPtr<CPDF_Dictionary> pDict = pDoc->GetMutablePageDictionary(page_index); - if (!pDict) + if (!pDict) { return nullptr; + } auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, std::move(pDict)); pPage->AddPageImageCache(); @@ -473,12 +497,14 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page, FS_RECTF* rect) { - if (!rect) + if (!rect) { return false; + } CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return false; + } *rect = FSRectFFromCFXFloatRect(pPage->GetBBox()); return true; @@ -518,17 +544,20 @@ RetainPtr<const CFX_DIBitmap> source, const CFX_FloatRect& mask_box, FX_RECT* bitmap_area) { - if (IsPageTooSmall(pPage)) + if (IsPageTooSmall(pPage)) { return nullptr; + } FX_RECT page_rect(start_x, start_y, start_x + size_x, start_y + size_y); CFX_Matrix matrix = pPage->GetDisplayMatrix(page_rect, rotate); - if (IsScalingTooSmall(matrix)) + if (IsScalingTooSmall(matrix)) { return nullptr; + } *bitmap_area = matrix.TransformRect(mask_box).GetOuterRect(); - if (bitmap_area->IsEmpty()) + if (bitmap_area->IsEmpty()) { return nullptr; + } // Create a new bitmap to transfer part of the page bitmap to. RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>(); @@ -547,8 +576,9 @@ const FX_RECT& mask_area) { int size_x_bm = mask_area.Width(); int size_y_bm = mask_area.Height(); - if (size_x_bm == 0 || size_y_bm == 0) + if (size_x_bm == 0 || size_y_bm == 0) { return; + } // Create a new bitmap from the old one RetainPtr<CFX_DIBitmap> dest = pdfium::MakeRetain<CFX_DIBitmap>(); @@ -579,8 +609,9 @@ int rotate, int flags) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + if (!pPage) { return false; + } auto owned_context = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* context = owned_context.get(); @@ -646,8 +677,9 @@ bitsStretched = true; } } - if (!bitsStretched) + if (!bitsStretched) { win_dc.SetDIBits(std::move(pBitmap), 0, 0); + } return true; } @@ -762,14 +794,16 @@ context->m_pDevice = std::move(device); CFX_FloatRect clipping_rect; - if (clipping) + if (clipping) { clipping_rect = CFXFloatRectFromFSRectF(*clipping); + } FX_RECT clip_rect = clipping_rect.ToFxRect(); const FX_RECT rect(0, 0, pPage->GetPageWidth(), pPage->GetPageHeight()); CFX_Matrix transform_matrix = pPage->GetDisplayMatrix(rect, 0); - if (matrix) + if (matrix) { transform_matrix *= CFXMatrixFromFSMatrix(*matrix); + } CPDFSDK_RenderPage(context, pPage, transform_matrix, clip_rect, flags, /*color_scheme=*/nullptr); } @@ -807,15 +841,17 @@ #endif // defined(PDF_USE_SKIA) FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page) { - if (!page) + if (!page) { return; + } // Take it back across the API and hold for duration of this function. RetainPtr<IPDF_Page> pPage; pPage.Unleak(IPDFPageFromFPDFPage(page)); - if (pPage->AsXFAPage()) + if (pPage->AsXFAPage()) { return; + } // This will delete the PageView object corresponding to |pPage|. We must // cleanup the PageView before releasing the reference on |pPage| as it will @@ -842,15 +878,17 @@ int device_y, double* page_x, double* page_y) { - if (!page || !page_x || !page_y) + if (!page || !page_x || !page_y) { return false; + } IPDF_Page* pPage = IPDFPageFromFPDFPage(page); const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); std::optional<CFX_PointF> pos = pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y)); - if (!pos.has_value()) + if (!pos.has_value()) { return false; + } *page_x = pos->x; *page_y = pos->y; @@ -867,15 +905,17 @@ double page_y, int* device_x, int* device_y) { - if (!page || !device_x || !device_y) + if (!page || !device_x || !device_y) { return false; + } IPDF_Page* pPage = IPDFPageFromFPDFPage(page); const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); CFX_PointF page_point(static_cast<float>(page_x), static_cast<float>(page_y)); std::optional<CFX_PointF> pos = pPage->PageToDevice(rect, rotate, page_point); - if (!pos.has_value()) + if (!pos.has_value()) { return false; + } *device_x = FXSYS_roundf(pos->x); *device_y = FXSYS_roundf(pos->y); @@ -1046,22 +1086,26 @@ FPDF_GetPageSizeByIndexF(FPDF_DOCUMENT document, int page_index, FS_SIZEF* size) { - if (!size) + if (!size) { return false; + } auto* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return false; + } #ifdef PDF_ENABLE_XFA - if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) + if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) { return false; + } auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension()); if (pContext) { RetainPtr<CPDFXFA_Page> pPage = pContext->GetOrCreateXFAPage(page_index); - if (!pPage) + if (!pPage) { return false; + } size->width = pPage->GetPageWidth(); size->height = pPage->GetPageHeight(); @@ -1070,8 +1114,9 @@ #endif // PDF_ENABLE_XFA RetainPtr<CPDF_Dictionary> pDict = pDoc->GetMutablePageDictionary(page_index); - if (!pDict) + if (!pDict) { return false; + } auto page = pdfium::MakeRetain<CPDF_Page>(pDoc, std::move(pDict)); page->AddPageImageCache(); @@ -1084,12 +1129,14 @@ int page_index, double* width, double* height) { - if (!width || !height) + if (!width || !height) { return false; + } FS_SIZEF size; - if (!FPDF_GetPageSizeByIndexF(document, page_index, &size)) + if (!FPDF_GetPageSizeByIndexF(document, page_index, &size)) { return false; + } *width = size.width; *height = size.height; @@ -1099,8 +1146,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return true; + } CPDF_ViewerPreferences viewRef(pDoc); return viewRef.PrintScaling(); } @@ -1108,8 +1156,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 1; + } CPDF_ViewerPreferences viewRef(pDoc); return viewRef.NumCopies(); } @@ -1117,8 +1166,9 @@ FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } CPDF_ViewerPreferences viewRef(pDoc); // Unretained reference in public API. NOLINTNEXTLINE @@ -1135,24 +1185,29 @@ FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange, size_t index) { const CPDF_Array* pArray = CPDFArrayFromFPDFPageRange(pagerange); - if (!pArray || index >= pArray->size()) + if (!pArray || index >= pArray->size()) { return -1; + } return pArray->GetIntegerAt(index); } FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return DuplexUndefined; + } CPDF_ViewerPreferences viewRef(pDoc); ByteString duplex = viewRef.Duplex(); - if ("Simplex" == duplex) + if ("Simplex" == duplex) { return Simplex; - if ("DuplexFlipShortEdge" == duplex) + } + if ("DuplexFlipShortEdge" == duplex) { return DuplexFlipShortEdge; - if ("DuplexFlipLongEdge" == duplex) + } + if ("DuplexFlipLongEdge" == duplex) { return DuplexFlipLongEdge; + } return DuplexUndefined; } @@ -1162,8 +1217,9 @@ char* buffer, unsigned long length) { const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 0; + } CPDF_ViewerPreferences viewRef(pDoc); std::optional<ByteString> bsVal = viewRef.GenericName(key); @@ -1178,29 +1234,34 @@ FPDF_EXPORT FPDF_DWORD FPDF_CALLCONV FPDF_CountNamedDests(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return 0; + } const CPDF_Dictionary* pRoot = pDoc->GetRoot(); - if (!pRoot) + if (!pRoot) { return 0; + } auto name_tree = CPDF_NameTree::Create(pDoc, "Dests"); FX_SAFE_UINT32 count = name_tree ? name_tree->GetCount() : 0; RetainPtr<const CPDF_Dictionary> pOldStyleDests = pRoot->GetDictFor("Dests"); - if (pOldStyleDests) + if (pOldStyleDests) { count += pOldStyleDests->size(); + } return count.ValueOrDefault(0); } FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDestByName(FPDF_DOCUMENT document, FPDF_BYTESTRING name) { - if (!name || name[0] == 0) + if (!name || name[0] == 0) { return nullptr; + } CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } ByteString dest_name(name); @@ -1228,8 +1289,9 @@ #ifdef PDF_ENABLE_XFA FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Init(FPDF_BSTR* bstr) { - if (!bstr) + if (!bstr) { return -1; + } bstr->str = nullptr; bstr->len = 0; @@ -1268,8 +1330,9 @@ } FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Clear(FPDF_BSTR* bstr) { - if (!bstr) + if (!bstr) { return -1; + } if (bstr->str) { FX_Free(bstr->str); @@ -1284,19 +1347,23 @@ int index, void* buffer, long* buflen) { - if (!buffer) + if (!buffer) { *buflen = 0; + } - if (index < 0) + if (index < 0) { return nullptr; + } CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) + if (!pDoc) { return nullptr; + } const CPDF_Dictionary* pRoot = pDoc->GetRoot(); - if (!pRoot) + if (!pRoot) { return nullptr; + } auto name_tree = CPDF_NameTree::Create(pDoc, "Dests"); size_t name_tree_count = name_tree ? name_tree->GetCount() : 0; @@ -1306,13 +1373,15 @@ // If |index| is out of bounds, then try to retrieve the Nth old style named // destination. Where N is 0-indexed, with N = index - name_tree_count. RetainPtr<const CPDF_Dictionary> pDest = pRoot->GetDictFor("Dests"); - if (!pDest) + if (!pDest) { return nullptr; + } FX_SAFE_INT32 checked_count = name_tree_count; checked_count += pDest->size(); - if (!checked_count.IsValid() || index >= checked_count.ValueOrDie()) + if (!checked_count.IsValid() || index >= checked_count.ValueOrDie()) { return nullptr; + } index -= name_tree_count; int i = 0; @@ -1321,23 +1390,27 @@ for (const auto& it : locker) { bsName = it.first.AsStringView(); pDestObj = it.second; - if (i == index) + if (i == index) { break; + } i++; } wsName = PDF_DecodeText(bsName.unsigned_span()); } else { pDestObj = name_tree->LookupValueAndName(index, &wsName); } - if (!pDestObj) + if (!pDestObj) { return nullptr; + } if (const CPDF_Dictionary* pDict = pDestObj->AsDictionary()) { pDestObj = pDict->GetArrayFor("D"); - if (!pDestObj) + if (!pDestObj) { return nullptr; + } } - if (!pDestObj->IsArray()) + if (!pDestObj->IsArray()) { return nullptr; + } ByteString utf16Name = wsName.ToUTF16LE(); int len = pdfium::checked_cast<int>(utf16Name.GetLength()); @@ -1357,8 +1430,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetXFAPacketCount(FPDF_DOCUMENT document) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return -1; + } return fxcrt::CollectionSize<int>( GetXFAPackets(GetXFAEntryFromDocument(doc))); @@ -1370,8 +1444,9 @@ void* buffer, unsigned long buflen) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc || index < 0) + if (!doc || index < 0) { return 0; + } std::vector<XFAPacket> xfa_packets = GetXFAPackets(GetXFAEntryFromDocument(doc)); @@ -1391,13 +1466,15 @@ unsigned long buflen, unsigned long* out_buflen) { CPDF_Document* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc || index < 0 || !out_buflen) + if (!doc || index < 0 || !out_buflen) { return false; + } std::vector<XFAPacket> xfa_packets = GetXFAPackets(GetXFAEntryFromDocument(doc)); - if (static_cast<size_t>(index) >= xfa_packets.size()) + if (static_cast<size_t>(index) >= xfa_packets.size()) { return false; + } // SAFETY: caller ensures `buffer` points to at least `buflen` bytes. *out_buflen = DecodeStreamMaybeCopyAndReturnLength( @@ -1412,8 +1489,9 @@ unsigned int* buffer, unsigned long length) { auto* doc = CPDFDocumentFromFPDFDocument(document); - if (!doc) + if (!doc) { return 0; + } // Start recording trailer ends. auto* parser = doc->GetParser();
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 5eb5e97..bf5c8ed 100644 --- a/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -459,8 +459,9 @@ TEST_F(FPDFViewEmbedderTest, RepeatedInitDestroy) { for (int i = 0; i < 3; ++i) { - if (!OpenDocument("about_blank.pdf")) + if (!OpenDocument("about_blank.pdf")) { ADD_FAILURE(); + } CloseDocument(); FPDF_DestroyLibrary(); @@ -945,8 +946,9 @@ // Make sure calling FPDFAvail_IsDocAvail() on this file does not infinite // loop either. See bug 875. int ret = PDF_DATA_NOTAVAIL; - while (ret == PDF_DATA_NOTAVAIL) + while (ret == PDF_DATA_NOTAVAIL) { ret = FPDFAvail_IsDocAvail(avail(), &hints); + } EXPECT_EQ(PDF_DATA_AVAIL, ret); }
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 0f0a42c..48a2e3a 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -69,31 +69,36 @@ RetainPtr<CPDF_SeekableMultiStream> CreateXFAMultiStream( const CPDF_Document* pPDFDoc) { const CPDF_Dictionary* pRoot = pPDFDoc->GetRoot(); - if (!pRoot) + if (!pRoot) { return nullptr; + } RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); - if (!pAcroForm) + if (!pAcroForm) { return nullptr; + } RetainPtr<const CPDF_Object> pElementXFA = pAcroForm->GetDirectObjectFor("XFA"); - if (!pElementXFA) + if (!pElementXFA) { return nullptr; + } std::vector<RetainPtr<const CPDF_Stream>> xfa_streams; if (pElementXFA->IsArray()) { const CPDF_Array* pXFAArray = pElementXFA->AsArray(); for (size_t i = 0; i < pXFAArray->size() / 2; i++) { RetainPtr<const CPDF_Stream> pStream = pXFAArray->GetStreamAt(i * 2 + 1); - if (pStream) + if (pStream) { xfa_streams.push_back(std::move(pStream)); + } } } else if (pElementXFA->IsStream()) { xfa_streams.push_back(ToStream(pElementXFA)); } - if (xfa_streams.empty()) + if (xfa_streams.empty()) { return nullptr; + } return pdfium::MakeRetain<CPDF_SeekableMultiStream>(std::move(xfa_streams)); } @@ -235,8 +240,9 @@ } RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetOrCreateXFAPage(int page_index) { - if (page_index < 0) + if (page_index < 0) { return nullptr; + } if (fxcrt::IndexInBounds(xfa_page_list_, page_index)) { if (xfa_page_list_[page_index]) { @@ -248,8 +254,9 @@ } auto pPage = pdfium::MakeRetain<CPDFXFA_Page>(GetPDFDoc(), page_index); - if (!pPage->LoadPage()) + if (!pPage->LoadPage()) { return nullptr; + } if (fxcrt::IndexInBounds(xfa_page_list_, page_index)) { xfa_page_list_[page_index] = pPage; @@ -268,8 +275,9 @@ RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetXFAPage( CXFA_FFPageView* pPage) const { - if (!pPage) + if (!pPage) { return nullptr; + } if (!xfadoc_) { return nullptr; @@ -280,8 +288,9 @@ } for (auto& pTempPage : xfa_page_list_) { - if (pTempPage && pTempPage->GetXFAPageView() == pPage) + if (pTempPage && pTempPage->GetXFAPageView() == pPage) { return pTempPage; + } } return nullptr; } @@ -384,8 +393,9 @@ pdfium::span<uint8_t> buffer_span = buffer.span(); int byte_length = form_fill_env_->JS_appResponse( wsQuestion, wsTitle, wsDefaultAnswer, WideString(), bMark, buffer_span); - if (byte_length <= 0) + if (byte_length <= 0) { return WideString(); + } buffer_span = buffer_span.first(std::min<size_t>(kMaxBytes, byte_length)); return WideString::FromUTF16LE(buffer_span); @@ -439,8 +449,9 @@ bool CPDFXFA_Context::SavePackage(const RetainPtr<IFX_SeekableStream>& pStream, XFA_HashCode code) { CXFA_FFDocView* pXFADocView = GetXFADocView(); - if (!pXFADocView) + if (!pXFADocView) { return false; + } CXFA_FFDoc* ffdoc = pXFADocView->GetDoc(); return ffdoc->SavePackage(ToNode(ffdoc->GetXFADoc()->GetXFAObject(code)), @@ -448,12 +459,14 @@ } void CPDFXFA_Context::SendPostSaveToXFADoc() { - if (!ContainsExtensionForm()) + if (!ContainsExtensionForm()) { return; + } CXFA_FFDocView* pXFADocView = GetXFADocView(); - if (!pXFADocView) + if (!pXFADocView) { return; + } CXFA_FFWidgetHandler* pWidgetHandler = pXFADocView->GetWidgetHandler(); CXFA_ReadyNodeIterator it(pXFADocView->GetRootSubform()); @@ -468,12 +481,14 @@ void CPDFXFA_Context::SendPreSaveToXFADoc( std::vector<RetainPtr<IFX_SeekableStream>>* fileList) { - if (!ContainsExtensionForm()) + if (!ContainsExtensionForm()) { return; + } CXFA_FFDocView* pXFADocView = GetXFADocView(); - if (!pXFADocView) + if (!pXFADocView) { return; + } CXFA_FFWidgetHandler* pWidgetHandler = pXFADocView->GetWidgetHandler(); CXFA_ReadyNodeIterator it(pXFADocView->GetRootSubform());
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 0951dd7..df7ac3c 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -76,12 +76,14 @@ } RetainPtr<CPDFXFA_Page> pPage = context_->GetXFAPage(pPageView); - if (!pPage) + if (!pPage) { return; + } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } pFormFillEnv->Invalidate(pPage.Get(), rt.ToFloatRect().ToFxRect()); } @@ -100,20 +102,24 @@ CXFA_FFWidgetHandler* pWidgetHandler = context_->GetXFADocView()->GetWidgetHandler(); - if (!pWidgetHandler) + if (!pWidgetHandler) { return; + } CXFA_FFPageView* pPageView = hWidget->GetPageView(); - if (!pPageView) + if (!pPageView) { return; + } RetainPtr<CPDFXFA_Page> pPage = context_->GetXFAPage(pPageView); - if (!pPage) + if (!pPage) { return; + } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } CFX_FloatRect rcCaret = pRtAnchor->ToFloatRect(); pFormFillEnv->DisplayCaret(pPage.Get(), bVisible, rcCaret.left, rcCaret.top, @@ -125,20 +131,24 @@ float fMaxPopup, const CFX_RectF& rtAnchor, CFX_RectF* pPopupRect) { - if (!hWidget) + if (!hWidget) { return false; + } CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); - if (!pXFAPageView) + if (!pXFAPageView) { return false; + } RetainPtr<CPDFXFA_Page> pPage = context_->GetXFAPage(pXFAPageView); - if (!pPage) + if (!pPage) { return false; + } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } FS_RECTF page_view_rect = pFormFillEnv->GetPageViewRect(pPage.Get()); int nRotate = hWidget->GetNode()->GetRotate(); @@ -153,10 +163,12 @@ space_available_above_anchor = static_cast<int>(rtAnchor.top - page_view_rect.top); - if (rtAnchor.left < page_view_rect.left) + if (rtAnchor.left < page_view_rect.left) { pPopupRect->left += page_view_rect.left - rtAnchor.left; - if (rtAnchor.right() > page_view_rect.right) + } + if (rtAnchor.right() > page_view_rect.right) { pPopupRect->left -= rtAnchor.right() - page_view_rect.right; + } break; } case 90: { @@ -165,10 +177,12 @@ space_available_above_anchor = static_cast<int>(rtAnchor.left - page_view_rect.left); - if (rtAnchor.bottom() > page_view_rect.bottom) + if (rtAnchor.bottom() > page_view_rect.bottom) { pPopupRect->left += rtAnchor.bottom() - page_view_rect.bottom; - if (rtAnchor.top < page_view_rect.top) + } + if (rtAnchor.top < page_view_rect.top) { pPopupRect->left -= page_view_rect.top - rtAnchor.top; + } break; } case 180: { @@ -177,10 +191,12 @@ space_available_above_anchor = static_cast<int>(page_view_rect.bottom - rtAnchor.bottom()); - if (rtAnchor.right() > page_view_rect.right) + if (rtAnchor.right() > page_view_rect.right) { pPopupRect->left += rtAnchor.right() - page_view_rect.right; - if (rtAnchor.left < page_view_rect.left) + } + if (rtAnchor.left < page_view_rect.left) { pPopupRect->left -= page_view_rect.left - rtAnchor.left; + } break; } case 270: { @@ -189,56 +205,63 @@ space_available_above_anchor = static_cast<int>(page_view_rect.right - rtAnchor.right()); - if (rtAnchor.top < page_view_rect.top) + if (rtAnchor.top < page_view_rect.top) { pPopupRect->left += page_view_rect.top - rtAnchor.top; - if (rtAnchor.bottom() > page_view_rect.bottom) + } + if (rtAnchor.bottom() > page_view_rect.bottom) { pPopupRect->left -= rtAnchor.bottom() - page_view_rect.bottom; + } break; } } // If there is no space on either side, the popup can't be rendered. - if (space_available_below_anchor <= 0 && space_available_above_anchor <= 0) + if (space_available_below_anchor <= 0 && space_available_above_anchor <= 0) { return false; + } // Determine whether to draw above or below the anchor. bool draw_below_anchor; - if (space_available_below_anchor <= 0) + if (space_available_below_anchor <= 0) { draw_below_anchor = false; - else if (space_available_above_anchor <= 0) + } else if (space_available_above_anchor <= 0) { draw_below_anchor = true; - else if (space_available_below_anchor > space_available_above_anchor) + } else if (space_available_below_anchor > space_available_above_anchor) { draw_below_anchor = true; - else + } else { draw_below_anchor = false; + } int space_available = (draw_below_anchor ? space_available_below_anchor : space_available_above_anchor); // Set the popup height and y position according to what was decided above. float popup_height; - if (space_available < fMinPopup) + if (space_available < fMinPopup) { popup_height = fMinPopup; - else if (space_available > fMaxPopup) + } else if (space_available > fMaxPopup) { popup_height = fMaxPopup; - else + } else { popup_height = static_cast<float>(space_available); + } switch (nRotate) { case 0: case 180: { - if (draw_below_anchor) + if (draw_below_anchor) { pPopupRect->top = rtAnchor.height; - else + } else { pPopupRect->top = -popup_height; + } break; } case 90: case 270: { - if (draw_below_anchor) + if (draw_below_anchor) { pPopupRect->top = rtAnchor.width; - else + } else { pPopupRect->top = -popup_height; + } break; } default: @@ -251,34 +274,44 @@ bool CPDFXFA_DocEnvironment::PopupMenu(CXFA_FFWidget* hWidget, const CFX_PointF& ptPopup) { - if (!hWidget) + if (!hWidget) { return false; + } CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); - if (!pXFAPageView) + if (!pXFAPageView) { return false; + } RetainPtr<CPDFXFA_Page> pPage = context_->GetXFAPage(pXFAPageView); - if (!pPage) + if (!pPage) { return false; + } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } int menuFlag = 0; - if (hWidget->CanUndo()) + if (hWidget->CanUndo()) { menuFlag |= FXFA_MENU_UNDO; - if (hWidget->CanRedo()) + } + if (hWidget->CanRedo()) { menuFlag |= FXFA_MENU_REDO; - if (hWidget->CanPaste()) + } + if (hWidget->CanPaste()) { menuFlag |= FXFA_MENU_PASTE; - if (hWidget->CanCopy()) + } + if (hWidget->CanCopy()) { menuFlag |= FXFA_MENU_COPY; - if (hWidget->CanCut()) + } + if (hWidget->CanCut()) { menuFlag |= FXFA_MENU_CUT; - if (hWidget->CanSelectAll()) + } + if (hWidget->CanSelectAll()) { menuFlag |= FXFA_MENU_SELECTALL; + } return pFormFillEnv->PopupMenu(pPage.Get(), menuFlag, ptPopup); } @@ -286,8 +319,9 @@ void CPDFXFA_DocEnvironment::OnPageViewEvent(CXFA_FFPageView* pPageView, CXFA_FFDoc::PageViewEvent eEvent) { CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } if (context_->GetLoadStatus() == CPDFXFA_Context::LoadStatus::kLoading || context_->GetLoadStatus() == CPDFXFA_Context::LoadStatus::kClosing || @@ -300,13 +334,15 @@ } CXFA_FFDocView* pXFADocView = context_->GetXFADocView(); - if (!pXFADocView) + if (!pXFADocView) { return; + } for (int i = 0; i < context_->GetOriginalPageCount(); ++i) { RetainPtr<CPDFXFA_Page> pPage = context_->GetXFAPage(i); - if (!pPage) + if (!pPage) { continue; + } context_->GetFormFillEnv()->RemovePageView(pPage.Get()); pPage->SetXFAPageViewIndex(i); @@ -326,12 +362,14 @@ } CXFA_FFPageView* pPageView = hWidget->GetPageView(); - if (!pPageView) + if (!pPageView) { return; + } RetainPtr<CPDFXFA_Page> pXFAPage = context_->GetXFAPage(pPageView); - if (!pXFAPage) + if (!pXFAPage) { return; + } auto* formfill = context_->GetFormFillEnv(); formfill->GetOrCreatePageView(pXFAPage.Get())->AddAnnotForFFWidget(hWidget); @@ -343,12 +381,14 @@ } CXFA_FFPageView* pPageView = hWidget->GetPageView(); - if (!pPageView) + if (!pPageView) { return; + } RetainPtr<CPDFXFA_Page> pXFAPage = context_->GetXFAPage(pPageView); - if (!pXFAPage) + if (!pXFAPage) { return; + } CPDFSDK_PageView* pSdkPageView = context_->GetFormFillEnv()->GetOrCreatePageView(pXFAPage.Get()); @@ -384,8 +424,9 @@ } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } pFormFillEnv->SetCurrentPage(iCurPage); } @@ -414,12 +455,14 @@ } CPDF_Document* pPDFDoc = context_->GetPDFDoc(); - if (!pPDFDoc) + if (!pPDFDoc) { return WideString(); + } RetainPtr<const CPDF_Dictionary> pInfoDict = pPDFDoc->GetInfo(); - if (!pInfoDict) + if (!pInfoDict) { return WideString(); + } ByteString csTitle = pInfoDict->GetByteStringFor("Title"); return WideString::FromDefANSI(csTitle.AsStringView()); @@ -432,12 +475,14 @@ } CPDF_Document* pPDFDoc = context_->GetPDFDoc(); - if (!pPDFDoc) + if (!pPDFDoc) { return; + } RetainPtr<CPDF_Dictionary> pInfoDict = pPDFDoc->GetInfo(); - if (pInfoDict) + if (pInfoDict) { pInfoDict->SetNewFor<CPDF_String>("Title", wsTitle.AsStringView()); + } } void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, @@ -452,8 +497,9 @@ } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; ByteString bs = wsFilePath.ToUTF16LE(); @@ -468,8 +514,9 @@ } FPDF_FILEHANDLER* pFileHandler = pFormFillEnv->OpenFile( bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, AsFPDFWideString(&bs), "wb"); - if (!pFileHandler) + if (!pFileHandler) { return; + } RetainPtr<IFX_SeekableStream> fileWrite = MakeSeekableStream(pFileHandler); if (fileType == FXFA_SAVEAS_XML) { @@ -483,29 +530,35 @@ } const CPDF_Dictionary* pRoot = context_->GetPDFDoc()->GetRoot(); - if (!pRoot) + if (!pRoot) { return; + } RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); - if (!pAcroForm) + if (!pAcroForm) { return; + } RetainPtr<const CPDF_Array> pArray = ToArray(pAcroForm->GetObjectFor("XFA")); - if (!pArray) + if (!pArray) { return; + } for (size_t i = 1; i < pArray->size(); i += 2) { RetainPtr<const CPDF_Object> pPDFObj = pArray->GetObjectAt(i); RetainPtr<const CPDF_Object> pPrePDFObj = pArray->GetObjectAt(i - 1); - if (!pPrePDFObj->IsString()) + if (!pPrePDFObj->IsString()) { continue; - if (!pPDFObj->IsReference()) + } + if (!pPDFObj->IsReference()) { continue; + } RetainPtr<const CPDF_Stream> pStream = ToStream(pPDFObj->GetDirect()); - if (!pStream) + if (!pStream) { continue; + } if (pPrePDFObj->GetString() == "form") { CXFA_FFDoc* ffdoc = context_->GetXFADocView()->GetDoc(); ffdoc->SavePackage( @@ -547,8 +600,9 @@ } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return; + } pFormFillEnv->GotoURL(wsURL); } @@ -589,8 +643,9 @@ for (int i = 0; i < pageViewCount; i++) { CPDFSDK_PageView* pPageView = context_->GetFormFillEnv()->GetPageViewAtIndex(i); - if (!pPageView) + if (!pPageView) { continue; + } ObservedPtr<CPDFSDK_Annot> pAnnot(pPageView->GetAnnotForFFWidget(hWidget)); if (pAnnot) { @@ -655,14 +710,16 @@ CXFA_FFDoc* hDoc, const WideString& wsLink) { CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return nullptr; + } ByteString bs = wsLink.ToUTF16LE(); FPDF_FILEHANDLER* pFileHandler = pFormFillEnv->OpenFile(0, AsFPDFWideString(&bs), "rb"); - if (!pFileHandler) + if (!pFileHandler) { return nullptr; + } return MakeSeekableStream(pFileHandler); } @@ -695,8 +752,9 @@ WideString tmp; if (!pos.has_value()) { pos = srcURL.Find(L'@'); - if (!pos.has_value()) + if (!pos.has_value()) { return false; + } tmp = srcURL.Right(csURL.GetLength() - 7); } else { @@ -715,13 +773,15 @@ tmp.TrimWhitespace(); if (tmp.GetLength() >= 3 && tmp.Left(3).EqualsASCIINoCase("cc=")) { tmp = tmp.Right(tmp.GetLength() - 3); - if (!csCCAddress.IsEmpty()) + if (!csCCAddress.IsEmpty()) { csCCAddress += L';'; + } csCCAddress += tmp; } else if (tmp.GetLength() >= 4 && tmp.Left(4).EqualsASCIINoCase("bcc=")) { tmp = tmp.Right(tmp.GetLength() - 4); - if (!csBCCAddress.IsEmpty()) + if (!csBCCAddress.IsEmpty()) { csBCCAddress += L';'; + } csBCCAddress += tmp; } else if (tmp.GetLength() >= 8 && tmp.Left(8).EqualsASCIINoCase("subject=")) { @@ -750,8 +810,9 @@ } CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } CXFA_FFDoc* ffdoc = context_->GetXFADocView()->GetDoc(); RetainPtr<IFX_SeekableStream> fileStream = MakeSeekableStream(pFileHandler); @@ -763,8 +824,9 @@ return true; } - if (fileType != FXFA_SAVEAS_XDP) + if (fileType != FXFA_SAVEAS_XDP) { return true; + } if (!flag) { flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | @@ -796,29 +858,39 @@ for (size_t i = 1; i < pArray->size(); i += 2) { RetainPtr<const CPDF_Object> pPDFObj = pArray->GetObjectAt(i); RetainPtr<const CPDF_Object> pPrePDFObj = pArray->GetObjectAt(i - 1); - if (!pPrePDFObj->IsString()) + if (!pPrePDFObj->IsString()) { continue; - if (!pPDFObj->IsReference()) + } + if (!pPDFObj->IsReference()) { continue; + } RetainPtr<const CPDF_Object> pDirectObj = pPDFObj->GetDirect(); - if (!pDirectObj->IsStream()) + if (!pDirectObj->IsStream()) { continue; + } ByteString bsType = pPrePDFObj->GetString(); - if (bsType == "config" && !(flag & FXFA_CONFIG)) + if (bsType == "config" && !(flag & FXFA_CONFIG)) { continue; - if (bsType == "template" && !(flag & FXFA_TEMPLATE)) + } + if (bsType == "template" && !(flag & FXFA_TEMPLATE)) { continue; - if (bsType == "localeSet" && !(flag & FXFA_LOCALESET)) + } + if (bsType == "localeSet" && !(flag & FXFA_LOCALESET)) { continue; - if (bsType == "datasets" && !(flag & FXFA_DATASETS)) + } + if (bsType == "datasets" && !(flag & FXFA_DATASETS)) { continue; - if (bsType == "xmpmeta" && !(flag & FXFA_XMPMETA)) + } + if (bsType == "xmpmeta" && !(flag & FXFA_XMPMETA)) { continue; - if (bsType == "xfdf" && !(flag & FXFA_XFDF)) + } + if (bsType == "xfdf" && !(flag & FXFA_XFDF)) { continue; - if (bsType == "form" && !(flag & FXFA_FORM)) + } + if (bsType == "form" && !(flag & FXFA_FORM)) { continue; + } if (bsType == "form") { ffdoc->SavePackage( @@ -835,20 +907,27 @@ void CPDFXFA_DocEnvironment::ToXFAContentFlags(WideString csSrcContent, FPDF_DWORD& flag) { - if (csSrcContent.Contains(L" config ")) + if (csSrcContent.Contains(L" config ")) { flag |= FXFA_CONFIG; - if (csSrcContent.Contains(L" template ")) + } + if (csSrcContent.Contains(L" template ")) { flag |= FXFA_TEMPLATE; - if (csSrcContent.Contains(L" localeSet ")) + } + if (csSrcContent.Contains(L" localeSet ")) { flag |= FXFA_LOCALESET; - if (csSrcContent.Contains(L" datasets ")) + } + if (csSrcContent.Contains(L" datasets ")) { flag |= FXFA_DATASETS; - if (csSrcContent.Contains(L" xmpmeta ")) + } + if (csSrcContent.Contains(L" xmpmeta ")) { flag |= FXFA_XMPMETA; - if (csSrcContent.Contains(L" xfdf ")) + } + if (csSrcContent.Contains(L" xfdf ")) { flag |= FXFA_XFDF; - if (csSrcContent.Contains(L" form ")) + } + if (csSrcContent.Contains(L" form ")) { flag |= FXFA_FORM; + } if (flag == 0) { flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; @@ -861,24 +940,28 @@ } CXFA_FFDocView* docView = context_->GetXFADocView(); - if (!docView) + if (!docView) { return true; + } CXFA_FFWidgetHandler* pWidgetHandler = docView->GetWidgetHandler(); - if (!pWidgetHandler) + if (!pWidgetHandler) { return true; + } auto it = docView->CreateReadyNodeIterator(); if (it) { CXFA_EventParam Param; Param.type_ = XFA_EVENT_PreSubmit; - while (CXFA_Node* pNode = it->MoveToNext()) + while (CXFA_Node* pNode = it->MoveToNext()) { pWidgetHandler->ProcessEvent(pNode, &Param); + } } it = docView->CreateReadyNodeIterator(); - if (!it) + if (!it) { return true; + } (void)it->MoveToNext(); CXFA_Node* pNode = it->MoveToNext(); @@ -886,8 +969,9 @@ while (pNode) { if (pNode->ProcessValidate(docView, -1) == XFA_EventError::kError) { CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } pFormFillEnv->JS_appAlert(WideString::FromDefANSI(IDS_XFA_Validate_Input), WideString(), JSPLATFORM_ALERT_BUTTON_OK, @@ -912,12 +996,14 @@ CXFA_FFWidgetHandler* pWidgetHandler = context_->GetXFADocView()->GetWidgetHandler(); - if (!pWidgetHandler) + if (!pWidgetHandler) { return; + } auto it = context_->GetXFADocView()->CreateReadyNodeIterator(); - if (!it) + if (!it) { return; + } CXFA_EventParam Param; Param.type_ = XFA_EVENT_PostSubmit; @@ -932,8 +1018,9 @@ bool CPDFXFA_DocEnvironment::SubmitInternal(CXFA_FFDoc* hDoc, CXFA_Submit* submit) { CPDFSDK_FormFillEnvironment* pFormFillEnv = context_->GetFormFillEnv(); - if (!pFormFillEnv) + if (!pFormFillEnv) { return false; + } WideString csURL = submit->GetSubmitTarget(); if (csURL.IsEmpty()) { @@ -953,8 +1040,9 @@ WideString space = WideString::FromDefANSI(" "); csContent = space + csContent + space; FPDF_DWORD flag = 0; - if (submit->IsSubmitEmbedPDF()) + if (submit->IsSubmitEmbedPDF()) { flag |= FXFA_PDF; + } ToXFAContentFlags(csContent, flag); pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); @@ -977,8 +1065,9 @@ default: return false; } - if (!pFileHandler) + if (!pFileHandler) { return false; + } if (csURL.Left(7).EqualsASCIINoCase("mailto:")) { WideString csToAddress;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 8b65023..283ea84 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -33,8 +33,9 @@ CXFA_FFWidget::IteratorIface* GCedWidgetIteratorForPage( CXFA_FFPageView* pFFPageView, CPDFSDK_PageView* pPageView) { - if (!pFFPageView) + if (!pFFPageView) { return nullptr; + } ObservedPtr<CPDFSDK_PageView> pWatchedPageView(pPageView); CXFA_FFWidget::IteratorIface* pIterator = @@ -47,23 +48,27 @@ CXFA_FFWidget::IteratorIface* GCedWidgetIteratorForAnnot( CXFA_FFPageView* pFFPageView, CPDFSDK_Annot* pSDKAnnot) { - if (!pFFPageView) + if (!pFFPageView) { return nullptr; + } CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pSDKAnnot); - if (!pXFAWidget) + if (!pXFAWidget) { return nullptr; + } ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pSDKAnnot); CXFA_FFWidget::IteratorIface* pWidgetIterator = pFFPageView->CreateGCedTraverseWidgetIterator(kIteratorFilter); // Check |pSDKAnnot| again because JS may have destroyed it. - if (!pObservedAnnot) + if (!pObservedAnnot) { return nullptr; + } - if (pWidgetIterator->GetCurrentWidget() != pXFAWidget->GetXFAFFWidget()) + if (pWidgetIterator->GetCurrentWidget() != pXFAWidget->GetXFAFFWidget()) { pWidgetIterator->SetCurrentWidget(pXFAWidget->GetXFAFFWidget()); + } return pWidgetIterator; } @@ -93,8 +98,9 @@ bool CPDFXFA_Page::LoadPDFPage() { RetainPtr<CPDF_Dictionary> pDict = GetDocument()->GetMutablePageDictionary(page_index_); - if (!pDict) + if (!pDict) { return false; + } if (!pdfpage_ || pdfpage_->GetDict() != pDict) { LoadPDFPageFromDict(std::move(pDict)); @@ -144,8 +150,9 @@ } [[fallthrough]]; case FormType::kXFAFull: - if (pPageView) + if (pPageView) { return pPageView->GetPageViewRect().width; + } break; } @@ -168,8 +175,9 @@ } [[fallthrough]]; case FormType::kXFAFull: - if (pPageView) + if (pPageView) { return pPageView->GetPageViewRect().height; + } break; } @@ -219,8 +227,9 @@ } [[fallthrough]]; case FormType::kXFAFull: - if (pPageView) + if (pPageView) { return pPageView->GetDisplayMatrix(rect, iRotate); + } break; } @@ -230,8 +239,9 @@ CPDFSDK_Annot* CPDFXFA_Page::GetNextXFAAnnot(CPDFSDK_Annot* pSDKAnnot) const { CXFA_FFWidget::IteratorIface* pWidgetIterator = GCedWidgetIteratorForAnnot(GetXFAPageView(), pSDKAnnot); - if (!pWidgetIterator) + if (!pWidgetIterator) { return nullptr; + } return pSDKAnnot->GetPageView()->GetAnnotForFFWidget( pWidgetIterator->MoveToNext()); @@ -240,8 +250,9 @@ CPDFSDK_Annot* CPDFXFA_Page::GetPrevXFAAnnot(CPDFSDK_Annot* pSDKAnnot) const { CXFA_FFWidget::IteratorIface* pWidgetIterator = GCedWidgetIteratorForAnnot(GetXFAPageView(), pSDKAnnot); - if (!pWidgetIterator) + if (!pWidgetIterator) { return nullptr; + } return pSDKAnnot->GetPageView()->GetAnnotForFFWidget( pWidgetIterator->MoveToPrevious()); @@ -251,8 +262,9 @@ CPDFSDK_PageView* page_view) const { CXFA_FFWidget::IteratorIface* pWidgetIterator = GCedWidgetIteratorForPage(GetXFAPageView(), page_view); - if (!pWidgetIterator) + if (!pWidgetIterator) { return nullptr; + } return page_view->GetAnnotForFFWidget(pWidgetIterator->MoveToFirst()); } @@ -261,36 +273,42 @@ CPDFSDK_PageView* page_view) const { CXFA_FFWidget::IteratorIface* pWidgetIterator = GCedWidgetIteratorForPage(GetXFAPageView(), page_view); - if (!pWidgetIterator) + if (!pWidgetIterator) { return nullptr; + } return page_view->GetAnnotForFFWidget(pWidgetIterator->MoveToLast()); } int CPDFXFA_Page::HasFormFieldAtPoint(const CFX_PointF& point) const { CXFA_FFPageView* pPageView = GetXFAPageView(); - if (!pPageView) + if (!pPageView) { return -1; + } CXFA_FFDocView* pDocView = pPageView->GetDocView(); - if (!pDocView) + if (!pDocView) { return -1; + } CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); - if (!pWidgetHandler) + if (!pWidgetHandler) { return -1; + } CXFA_FFPageWidgetIterator pWidgetIterator(pPageView, XFA_WidgetStatus::kViewable); CXFA_FFWidget* pXFAAnnot; while ((pXFAAnnot = pWidgetIterator.MoveToNext()) != nullptr) { - if (pXFAAnnot->GetFormFieldType() == FormFieldType::kXFA) + if (pXFAAnnot->GetFormFieldType() == FormFieldType::kXFA) { continue; + } CFX_FloatRect rcWidget = pXFAAnnot->GetWidgetRect().ToFloatRect(); rcWidget.Inflate(1.0f, 1.0f); - if (rcWidget.Contains(point)) + if (rcWidget.Contains(point)) { return static_cast<int>(pXFAAnnot->GetFormFieldType()); + } } return -1; @@ -311,23 +329,27 @@ while (true) { CXFA_FFWidget* pWidget = pWidgetIterator.MoveToNext(); - if (!pWidget) + if (!pWidget) { break; + } CFX_RectF rtWidgetBox = pWidget->GetBBox(CXFA_FFWidget::kDoNotDrawFocus); ++rtWidgetBox.width; ++rtWidgetBox.height; - if (rtWidgetBox.IntersectWith(rectClip)) + if (rtWidgetBox.IntersectWith(rectClip)) { pWidget->RenderWidget(&gs, mtUser2Device, CXFA_FFWidget::kHighlight); + } } CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot); - if (!pXFAWidget) + if (!pXFAWidget) { return; + } CXFA_FFDocView* docView = xfaView->GetDocView(); - if (!docView) + if (!docView) { return; + } docView->GetWidgetHandler()->RenderWidget(pXFAWidget->GetXFAFFWidget(), &gs, mtUser2Device, false);
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp index 86f1a29..9bcf67b 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_widget.cpp
@@ -198,18 +198,24 @@ Mask<XFA_FWL_KeyFlag> GetKeyFlags(Mask<FWL_EVENTFLAG> input) { Mask<XFA_FWL_KeyFlag> results; - if (input & FWL_EVENTFLAG_ControlKey) + if (input & FWL_EVENTFLAG_ControlKey) { results |= XFA_FWL_KeyFlag::kCtrl; - if (input & FWL_EVENTFLAG_LeftButtonDown) + } + if (input & FWL_EVENTFLAG_LeftButtonDown) { results |= XFA_FWL_KeyFlag::kLButton; - if (input & FWL_EVENTFLAG_MiddleButtonDown) + } + if (input & FWL_EVENTFLAG_MiddleButtonDown) { results |= XFA_FWL_KeyFlag::kMButton; - if (input & FWL_EVENTFLAG_RightButtonDown) + } + if (input & FWL_EVENTFLAG_RightButtonDown) { results |= XFA_FWL_KeyFlag::kRButton; - if (input & FWL_EVENTFLAG_ShiftKey) + } + if (input & FWL_EVENTFLAG_ShiftKey) { results |= XFA_FWL_KeyFlag::kShift; - if (input & FWL_EVENTFLAG_AltKey) + } + if (input & FWL_EVENTFLAG_AltKey) { results |= XFA_FWL_KeyFlag::kAlt; + } return results; } @@ -242,8 +248,9 @@ const CFX_Matrix& mtUser2Device, bool bDrawAnnots) { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (!widget_handler) + if (!widget_handler) { return; + } CFGAS_GEGraphics gs(pDevice); bool is_highlight = GetPageView()->GetFormFillEnv()->GetFocusAnnot() != this; @@ -255,8 +262,9 @@ bool CPDFXFA_Widget::DoHitTest(const CFX_PointF& point) { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (!widget_handler) + if (!widget_handler) { return false; + } return widget_handler->HitTest(GetXFAFFWidget(), point) != FWL_WidgetHit::Unknown; @@ -264,12 +272,14 @@ bool CPDFXFA_Widget::OnChangedFocus() { CXFA_FFDocView* doc_view = GetDocView(); - if (!doc_view) + if (!doc_view) { return false; + } CXFA_FFWidget* widget = GetXFAFFWidget(); - if (doc_view->SetFocus(widget)) + if (doc_view->SetFocus(widget)) { return false; + } return doc_view->GetFocusWidget() != widget; } @@ -291,14 +301,16 @@ void CPDFXFA_Widget::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (widget_handler) + if (widget_handler) { widget_handler->OnMouseEnter(GetXFAFFWidget()); + } } void CPDFXFA_Widget::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (widget_handler) + if (widget_handler) { widget_handler->OnMouseExit(GetXFAFFWidget()); + } } bool CPDFXFA_Widget::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, @@ -373,8 +385,9 @@ bool CPDFXFA_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) { CXFA_FFDocView* doc_view = GetDocView(); - if (doc_view) + if (doc_view) { doc_view->SetFocus(nullptr); + } return true; } @@ -400,15 +413,17 @@ WideString CPDFXFA_Widget::GetText() { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (!widget_handler) + if (!widget_handler) { return WideString(); + } return widget_handler->GetText(GetXFAFFWidget()); } WideString CPDFXFA_Widget::GetSelectedText() { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (!widget_handler) + if (!widget_handler) { return WideString(); + } return widget_handler->GetSelectedText(GetXFAFFWidget()); } @@ -420,8 +435,9 @@ void CPDFXFA_Widget::ReplaceSelection(const WideString& text) { CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler(); - if (widget_handler) + if (widget_handler) { widget_handler->PasteText(GetXFAFFWidget(), text); + } } bool CPDFXFA_Widget::SelectAllText() {
diff --git a/fpdfsdk/pwl/cpwl_caret.cpp b/fpdfsdk/pwl/cpwl_caret.cpp index 51a3f18..10ec4af 100644 --- a/fpdfsdk/pwl/cpwl_caret.cpp +++ b/fpdfsdk/pwl/cpwl_caret.cpp
@@ -35,8 +35,9 @@ float fCaretBottom = rcRect.bottom; if (!rcClip.IsEmpty()) { rcRect.Intersect(rcClip); - if (rcRect.IsEmpty()) + if (rcRect.IsEmpty()) { return; + } fCaretTop = rcRect.top; fCaretBottom = rcRect.bottom; @@ -73,8 +74,9 @@ head_point_ = CFX_PointF(); foot_point_ = CFX_PointF(); flash_ = false; - if (!IsVisible()) + if (!IsVisible()) { return; + } timer_.reset(); (void)CPWL_Wnd::SetVisible(false); @@ -91,8 +93,9 @@ timer_ = std::make_unique<CFX_Timer>(GetTimerHandler(), this, kCaretFlashIntervalMs); - if (!CPWL_Wnd::SetVisible(true)) + if (!CPWL_Wnd::SetVisible(true)) { return; + } flash_ = true; Move(invalid_rect_, false, true); @@ -114,8 +117,9 @@ } bool CPWL_Caret::InvalidateRect(const CFX_FloatRect* pRect) { - if (!pRect) + if (!pRect) { return CPWL_Wnd::InvalidateRect(nullptr); + } CFX_FloatRect rcRefresh = *pRect; if (!rcRefresh.IsEmpty()) {
diff --git a/fpdfsdk/pwl/cpwl_cbbutton.cpp b/fpdfsdk/pwl/cpwl_cbbutton.cpp index 14a3b91..3fd8679 100644 --- a/fpdfsdk/pwl/cpwl_cbbutton.cpp +++ b/fpdfsdk/pwl/cpwl_cbbutton.cpp
@@ -23,12 +23,14 @@ const CFX_Matrix& mtUser2Device) { CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device); - if (!IsVisible()) + if (!IsVisible()) { return; + } CFX_FloatRect window = CPWL_Wnd::GetWindowRect(); - if (window.IsEmpty()) + if (window.IsEmpty()) { return; + } static constexpr float kComboBoxTriangleLength = 6.0f; static constexpr float kComboBoxTriangleHalfLength = @@ -66,8 +68,9 @@ SetCapture(); CPWL_Wnd* pParent = GetParentWindow(); - if (pParent) + if (pParent) { pParent->NotifyLButtonDown(this, point); + } return true; }
diff --git a/fpdfsdk/pwl/cpwl_cblistbox.cpp b/fpdfsdk/pwl/cpwl_cblistbox.cpp index 68192df..9dc15e8 100644 --- a/fpdfsdk/pwl/cpwl_cblistbox.cpp +++ b/fpdfsdk/pwl/cpwl_cblistbox.cpp
@@ -31,10 +31,12 @@ ReleaseCapture(); mouse_down_ = false; - if (!ClientHitTest(point)) + if (!ClientHitTest(point)) { return true; - if (CPWL_Wnd* pParent = GetParentWindow()) + } + if (CPWL_Wnd* pParent = GetParentWindow()) { pParent->NotifyLButtonUp(this, point); + } return !OnNotifySelectionChanged(false, nFlag); } @@ -85,8 +87,9 @@ } bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) { - if (auto* pComboBox = static_cast<CPWL_ComboBox*>(GetParentWindow())) + if (auto* pComboBox = static_cast<CPWL_ComboBox*>(GetParentWindow())) { pComboBox->SetSelectText(); + } return OnNotifySelectionChanged(true, nFlag); }
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp index c73d0a2..9290f2a 100644 --- a/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -50,8 +50,9 @@ } void CPWL_ComboBox::KillFocus() { - if (!SetPopup(false)) + if (!SetPopup(false)) { return; + } CPWL_Wnd::KillFocus(); } @@ -152,11 +153,13 @@ ecp.dwFlags = PWS_VISIBLE | PWS_BORDER | PES_CENTER | PES_AUTOSCROLL | PES_UNDO; - if (HasFlag(PWS_AUTOFONTSIZE)) + if (HasFlag(PWS_AUTOFONTSIZE)) { ecp.dwFlags |= PWS_AUTOFONTSIZE; + } - if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) + if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) { ecp.dwFlags |= PWS_READONLY; + } ecp.rcRectWnd = CFX_FloatRect(); ecp.dwBorderWidth = 0; @@ -202,11 +205,13 @@ lcp.fFontSize = (cp.dwFlags & PWS_AUTOFONTSIZE) ? kComboBoxDefaultFontSize : cp.fFontSize; - if (cp.sBorderColor.nColorType == CFX_Color::Type::kTransparent) + if (cp.sBorderColor.nColorType == CFX_Color::Type::kTransparent) { lcp.sBorderColor = kDefaultBlackColor; + } - if (cp.sBackgroundColor.nColorType == CFX_Color::Type::kTransparent) + if (cp.sBackgroundColor.nColorType == CFX_Color::Type::kTransparent) { lcp.sBackgroundColor = kDefaultWhiteColor; + } auto pList = std::make_unique<CPWL_CBListBox>(lcp, CloneAttachedData()); list_ = pList.get();
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp index 4fbb05f..bf2b38b 100644 --- a/fpdfsdk/pwl/cpwl_edit.cpp +++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -76,8 +76,9 @@ float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); CFX_FloatRect rcClient = GetWindowRect().GetDeflated(width, width); CPWL_ScrollBar* pVSB = GetVScrollBar(); - if (pVSB && pVSB->IsVisible()) + if (pVSB && pVSB->IsVisible()) { rcClient.right -= CPWL_ScrollBar::kWidth; + } return rcClient; } @@ -99,8 +100,9 @@ } void CPWL_Edit::CutText() { - if (!CanCut()) + if (!CanCut()) { return; + } edit_impl_->ClearSelection(); } @@ -276,8 +278,9 @@ float CPWL_Edit::GetCharArrayAutoFontSize(const CPDF_Font* pFont, const CFX_FloatRect& rcPlate, int32_t nCharArray) { - if (!pFont || pFont->IsStandardFont()) + if (!pFont || pFont->IsStandardFont()) { return 0.0f; + } const FX_RECT& rcBBox = pFont->GetFontBBox(); @@ -289,24 +292,28 @@ } void CPWL_Edit::SetCharArray(int32_t nCharArray) { - if (!HasFlag(PES_CHARARRAY) || nCharArray <= 0) + if (!HasFlag(PES_CHARARRAY) || nCharArray <= 0) { return; + } edit_impl_->SetCharArray(nCharArray); edit_impl_->SetTextOverflow(true); edit_impl_->Paint(); - if (!HasFlag(PWS_AUTOFONTSIZE)) + if (!HasFlag(PWS_AUTOFONTSIZE)) { return; + } IPVT_FontMap* pFontMap = GetFontMap(); - if (!pFontMap) + if (!pFontMap) { return; + } float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0).Get(), GetClientRect(), nCharArray); - if (fFontSize <= 0.0f) + if (fFontSize <= 0.0f) { return; + } edit_impl_->SetAutoFontSize(false); edit_impl_->SetFontSize(fFontSize); @@ -404,8 +411,9 @@ auto [nSelStart, nSelEnd] = this_observed->GetSelection(); switch (nChar) { case pdfium::ascii::kBackspace: - if (nSelStart == nSelEnd) + if (nSelStart == nSelEnd) { nSelStart = nSelEnd - 1; + } break; case pdfium::ascii::kReturn: break; @@ -443,14 +451,16 @@ bool CPWL_Edit::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point, const CFX_Vector& delta) { - if (!HasFlag(PES_MULTILINE)) + if (!HasFlag(PES_MULTILINE)) { return false; + } CFX_PointF ptScroll = GetScrollPos(); - if (delta.y > 0) + if (delta.y > 0) { ptScroll.y += GetFontSize(); - else + } else { ptScroll.y -= GetFontSize(); + } SetScrollPos(ptScroll); return true; } @@ -490,13 +500,15 @@ } void CPWL_Edit::SetScrollInfo(const PWL_SCROLL_INFO& info) { - if (CPWL_Wnd* pChild = GetVScrollBar()) + if (CPWL_Wnd* pChild = GetVScrollBar()) { pChild->SetScrollInfo(info); + } } void CPWL_Edit::SetScrollPosition(float pos) { - if (CPWL_Wnd* pChild = GetVScrollBar()) + if (CPWL_Wnd* pChild = GetVScrollBar()) { pChild->SetScrollPosition(pos); + } } void CPWL_Edit::ScrollWindowVertically(float pos) { @@ -504,8 +516,9 @@ } void CPWL_Edit::CreateChildWnd(const CreateParams& cp) { - if (!IsReadOnly()) + if (!IsReadOnly()) { CreateEditCaret(cp); + } } void CPWL_Edit::CreateEditCaret(const CreateParams& cp) { @@ -572,8 +585,9 @@ Delete(); return true; case FWL_VKEY_Insert: - if (IsSHIFTKeyDown(nFlag)) + if (IsSHIFTKeyDown(nFlag)) { PasteText(); + } return true; case FWL_VKEY_Up: edit_impl_->OnVK_UP(IsSHIFTKeyDown(nFlag)); @@ -594,10 +608,11 @@ edit_impl_->OnVK_END(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag)); return true; case FWL_VKEY_Unknown: - if (!IsSHIFTKeyDown(nFlag)) + if (!IsSHIFTKeyDown(nFlag)) { ClearSelection(); - else + } else { CutText(); + } return true; default: break; @@ -643,19 +658,22 @@ SelectAllText(); return true; case pdfium::ascii::kControlZ: - if (bShift) + if (bShift) { Redo(); - else + } else { Undo(); + } return true; default: - if (nChar < 32) + if (nChar < 32) { return false; + } } } - if (IsReadOnly()) + if (IsReadOnly()) { return true; + } if (edit_impl_->IsSelected() && word == pdfium::ascii::kBackspace) { word = pdfium::ascii::kNul; @@ -700,8 +718,9 @@ CPWL_Wnd::OnLButtonUp(nFlag, point); if (mouse_down_) { // can receive keybord message - if (ClientHitTest(point) && !IsFocused()) + if (ClientHitTest(point) && !IsFocused()) { SetFocus(); + } ReleaseCapture(); mouse_down_ = false; @@ -712,8 +731,9 @@ bool CPWL_Edit::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point) { CPWL_Wnd::OnLButtonDblClk(nFlag, point); - if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) + if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { edit_impl_->SelectAll(); + } return true; } @@ -725,8 +745,9 @@ } CPWL_Wnd::OnRButtonUp(nFlag, point); - if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) + if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) { return true; + } SetFocus(); return false; @@ -746,8 +767,9 @@ void CPWL_Edit::SetEditCaret(bool bVisible) { CFX_PointF ptHead; CFX_PointF ptFoot; - if (bVisible) + if (bVisible) { GetCaretInfo(&ptHead, &ptFoot); + } SetCaret(bVisible, ptHead, ptFoot); // Note, |this| may no longer be viable at this point. If more work needs to @@ -799,8 +821,9 @@ } void CPWL_Edit::ClearSelection() { - if (!IsReadOnly()) + if (!IsReadOnly()) { edit_impl_->ClearSelection(); + } } void CPWL_Edit::SetScrollPos(const CFX_PointF& point) { @@ -816,23 +839,27 @@ void CPWL_Edit::PasteText() {} void CPWL_Edit::InsertWord(uint16_t word, FX_Charset nCharset) { - if (!IsReadOnly()) + if (!IsReadOnly()) { edit_impl_->InsertWord(word, nCharset); + } } void CPWL_Edit::InsertReturn() { - if (!IsReadOnly()) + if (!IsReadOnly()) { edit_impl_->InsertReturn(); + } } void CPWL_Edit::Delete() { - if (!IsReadOnly()) + if (!IsReadOnly()) { edit_impl_->Delete(); + } } void CPWL_Edit::Backspace() { - if (!IsReadOnly()) + if (!IsReadOnly()) { edit_impl_->Backspace(); + } } bool CPWL_Edit::CanUndo() {
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp index f52c0b2..24f703b 100644 --- a/fpdfsdk/pwl/cpwl_edit_impl.cpp +++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -38,8 +38,9 @@ const CFX_Matrix& mtUser2Device, const ByteString& str, FX_ARGB crTextFill) { - if (!pFont) + if (!pFont) { return; + } CFX_PointF pos = mtUser2Device.Transform(pt); CPDF_RenderOptions ro; @@ -112,14 +113,16 @@ int CPWL_EditImpl::Provider::GetCharWidth(int32_t nFontIndex, uint16_t word) { RetainPtr<CPDF_Font> pPDFFont = GetFontMap()->GetPDFFont(nFontIndex); - if (!pPDFFont) + if (!pPDFFont) { return 0; + } uint32_t charcode = pPDFFont->IsUnicodeCompatible() ? pPDFFont->CharCodeFromUnicode(word) : GetFontMap()->CharCodeFromUnicode(nFontIndex, word); - if (charcode == CPDF_Font::kInvalidCharCode) + if (charcode == CPDF_Font::kInvalidCharCode) { return 0; + } return pPDFFont->GetCharWidthF(charcode); } @@ -166,8 +169,9 @@ void CPWL_EditImpl::RefreshState::Add(const CFX_FloatRect& new_rect) { // Check for overlapped area. for (const auto& rect : refresh_rects_) { - if (rect.Contains(new_rect)) + if (rect.Contains(new_rect)) { return; + } } refresh_rects_.push_back(new_rect); } @@ -220,8 +224,9 @@ void CPWL_EditImpl::UndoStack::AddItem(std::unique_ptr<UndoItemIface> pItem) { DCHECK(!working_); DCHECK(pItem); - if (CanRedo()) + if (CanRedo()) { RemoveTails(); + } if (undo_item_stack_.size() >= kEditUndoMaxItems) { RemoveHeads(); @@ -237,8 +242,9 @@ } void CPWL_EditImpl::UndoStack::RemoveTails() { - while (CanRedo()) + while (CanRedo()) { undo_item_stack_.pop_back(); + } } class CPWL_EditImpl::UndoInsertWord final @@ -614,25 +620,29 @@ int32_t nFontIndex = -1; CFX_PointF ptBT; CFX_RenderDevice::StateRestorer restorer(pDevice); - if (!rcClip.IsEmpty()) + if (!rcClip.IsEmpty()) { pDevice->SetClip_Rect(mtUser2Device.TransformRect(rcClip).ToFxRect()); + } Iterator* pIterator = GetIterator(); IPVT_FontMap* pFontMap = GetFontMap(); - if (!pFontMap) + if (!pFontMap) { return; + } - if (pRange) + if (pRange) { pIterator->SetAt(pRange->BeginPos); - else + } else { pIterator->SetAt(0); + } ByteString sTextBuf; CPVT_WordPlace oldplace; while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetAt(); - if (pRange && place > pRange->EndPos) + if (pRange && place > pRange->EndPos) { break; + } if (!wrSelect.IsEmpty()) { bSelect = place > wrSelect.BeginPos && place <= wrSelect.EndPos; @@ -853,10 +863,12 @@ CPVT_WordPlace oldplace = pIterator->GetWordPlace(); while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetWordPlace(); - if (pIterator->GetWord(wordinfo)) + if (pIterator->GetWord(wordinfo)) { swRet += wordinfo.Word; - if (oldplace.nSecIndex != place.nSecIndex) + } + if (oldplace.nSecIndex != place.nSecIndex) { swRet += L"\r\n"; + } oldplace = place; } return swRet; @@ -878,12 +890,15 @@ CPVT_WordPlace oldplace = wrTemp.BeginPos; while (pIterator->NextWord()) { CPVT_WordPlace place = pIterator->GetWordPlace(); - if (place > wrTemp.EndPos) + if (place > wrTemp.EndPos) { break; - if (pIterator->GetWord(wordinfo)) + } + if (pIterator->GetWord(wordinfo)) { swRet += wordinfo.Word; - if (oldplace.nSecIndex != place.nSecIndex) + } + if (oldplace.nSecIndex != place.nSecIndex) { swRet += L"\r\n"; + } oldplace = place; } return swRet; @@ -898,8 +913,9 @@ CPVT_VariableText::Iterator* pIterator = vt_->GetIterator(); pIterator->SetAt(0); - while (pIterator->NextLine()) + while (pIterator->NextLine()) { ++nLines; + } return nLines; } @@ -1293,10 +1309,12 @@ CPVT_Line lineinfo; do { - if (!pIterator->GetLine(lineinfo)) + if (!pIterator->GetLine(lineinfo)) { break; - if (lineinfo.lineplace.LineCmp(wpEnd) > 0) + } + if (lineinfo.lineplace.LineCmp(wpEnd) > 0) { break; + } CFX_FloatRect rcLine(lineinfo.ptLine.x, lineinfo.ptLine.y + lineinfo.fLineDescent, @@ -1322,8 +1340,9 @@ while (pIterator->NextWord()) { place = pIterator->GetWordPlace(); - if (place > wrTemp.EndPos) + if (place > wrTemp.EndPos) { break; + } pIterator->GetWord(wordinfo); pIterator->GetLine(lineinfo); @@ -1584,10 +1603,11 @@ } if (bShift) { - if (bCtrl) + if (bCtrl) { SetCaret(vt_->GetBeginWordPlace()); - else + } else { SetCaret(vt_->GetLineBeginPlace(wp_caret_)); + } if (sel_state_.IsEmpty()) { sel_state_.Set(wp_old_caret_, wp_caret_); @@ -1605,10 +1625,11 @@ ScrollToCaret(); SetCaretInfo(); } else { - if (bCtrl) + if (bCtrl) { SetCaret(vt_->GetBeginWordPlace()); - else + } else { SetCaret(vt_->GetLineBeginPlace(wp_caret_)); + } ScrollToCaret(); SetCaretOrigin(); @@ -1623,10 +1644,11 @@ } if (bShift) { - if (bCtrl) + if (bCtrl) { SetCaret(vt_->GetEndWordPlace()); - else + } else { SetCaret(vt_->GetLineEndPlace(wp_caret_)); + } if (sel_state_.IsEmpty()) { sel_state_.Set(wp_old_caret_, wp_caret_); @@ -1644,10 +1666,11 @@ ScrollToCaret(); SetCaretInfo(); } else { - if (bCtrl) + if (bCtrl) { SetCaret(vt_->GetEndWordPlace()); - else + } else { SetCaret(vt_->GetLineEndPlace(wp_caret_)); + } ScrollToCaret(); SetCaretOrigin(); @@ -1798,8 +1821,9 @@ void CPWL_EditImpl::InsertText(const WideString& sText, FX_Charset charset, bool bAddUndo) { - if (IsTextOverflow()) + if (IsTextOverflow()) { return; + } vt_->UpdateWordPlace(wp_caret_); SetCaret(DoInsertText(wp_caret_, sText, charset)); @@ -1928,8 +1952,9 @@ return true; } - if (FXSYS_IsFloatBigger(rcContent.Width(), rcPlate.Width())) + if (FXSYS_IsFloatBigger(rcContent.Width(), rcPlate.Width())) { return true; + } } return false; @@ -1972,8 +1997,9 @@ switch (word) { case '\r': wp = vt_->InsertSection(wp); - if (i + 1 < sText.GetLength() && sText[i + 1] == '\n') + if (i + 1 < sText.GetLength() && sText[i + 1] == '\n') { i++; + } break; case '\n': wp = vt_->InsertSection(wp); @@ -1991,8 +2017,9 @@ FX_Charset CPWL_EditImpl::GetCharSetFromUnicode(uint16_t word, FX_Charset nOldCharset) { - if (IPVT_FontMap* pFontMap = GetFontMap()) + if (IPVT_FontMap* pFontMap = GetFontMap()) { return pFontMap->CharSetFromUnicode(word, nOldCharset); + } return nOldCharset; } @@ -2006,8 +2033,9 @@ uint16_t SubWord) { IPVT_FontMap* pFontMap = GetFontMap(); RetainPtr<CPDF_Font> pPDFFont = pFontMap->GetPDFFont(nFontIndex); - if (!pPDFFont) + if (!pPDFFont) { return ByteString(); + } ByteString sWord; if (SubWord > 0) {
diff --git a/fpdfsdk/pwl/cpwl_list_box.cpp b/fpdfsdk/pwl/cpwl_list_box.cpp index 0387187..8200c47 100644 --- a/fpdfsdk/pwl/cpwl_list_box.cpp +++ b/fpdfsdk/pwl/cpwl_list_box.cpp
@@ -52,8 +52,9 @@ for (int32_t i = 0, sz = list_ctrl_->GetCount(); i < sz; i++) { CFX_FloatRect rcItem = list_ctrl_->GetItemRect(i); - if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) + if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) { continue; + } CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); if (CPWL_EditImpl* pEdit = list_ctrl_->GetItemEdit(i)) { @@ -182,13 +183,15 @@ } void CPWL_ListBox::SetScrollInfo(const PWL_SCROLL_INFO& info) { - if (CPWL_Wnd* pChild = GetVScrollBar()) + if (CPWL_Wnd* pChild = GetVScrollBar()) { pChild->SetScrollInfo(info); + } } void CPWL_ListBox::SetScrollPosition(float pos) { - if (CPWL_Wnd* pChild = GetVScrollBar()) + if (CPWL_Wnd* pChild = GetVScrollBar()) { pChild->SetScrollPosition(pos); + } } void CPWL_ListBox::ScrollWindowVertically(float pos) { @@ -262,8 +265,9 @@ SetScrollInfo(Info); CPWL_ScrollBar* pScroll = GetVScrollBar(); - if (!pScroll) + if (!pScroll) { return; + } if (FXSYS_IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || @@ -348,10 +352,11 @@ bool CPWL_ListBox::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point, const CFX_Vector& delta) { - if (delta.y < 0) + if (delta.y < 0) { list_ctrl_->OnVK_DOWN(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag)); - else + } else { list_ctrl_->OnVK_UP(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag)); + } OnNotifySelectionChanged(false, nFlag); return true;
diff --git a/fpdfsdk/pwl/cpwl_list_ctrl.cpp b/fpdfsdk/pwl/cpwl_list_ctrl.cpp index 702575f..0403290 100644 --- a/fpdfsdk/pwl/cpwl_list_ctrl.cpp +++ b/fpdfsdk/pwl/cpwl_list_ctrl.cpp
@@ -64,11 +64,13 @@ } void CPWL_ListCtrl::SelectState::Add(int32_t nBeginIndex, int32_t nEndIndex) { - if (nBeginIndex > nEndIndex) + if (nBeginIndex > nEndIndex) { std::swap(nBeginIndex, nEndIndex); + } - for (int32_t i = nBeginIndex; i <= nEndIndex; ++i) + for (int32_t i = nBeginIndex; i <= nEndIndex; ++i) { Add(i); + } } void CPWL_ListCtrl::SelectState::Sub(int32_t nItemIndex) { @@ -79,11 +81,13 @@ } void CPWL_ListCtrl::SelectState::Sub(int32_t nBeginIndex, int32_t nEndIndex) { - if (nBeginIndex > nEndIndex) + if (nBeginIndex > nEndIndex) { std::swap(nBeginIndex, nEndIndex); + } - for (int32_t i = nBeginIndex; i <= nEndIndex; ++i) + for (int32_t i = nBeginIndex; i <= nEndIndex; ++i) { Sub(i); + } } void CPWL_ListCtrl::SelectState::DeselectAll() { @@ -95,10 +99,11 @@ void CPWL_ListCtrl::SelectState::Done() { auto it = items_.begin(); while (it != items_.end()) { - if (it->second == DESELECTING) + if (it->second == DESELECTING) { it = items_.erase(it); - else + } else { (it++)->second = NORMAL; + } } } @@ -192,8 +197,9 @@ SetSingleSelect(nHitIndex); } - if (!IsItemVisible(nHitIndex)) + if (!IsItemVisible(nHitIndex)) { ScrollToListItem(nHitIndex); + } } void CPWL_ListCtrl::OnMouseMove(const CFX_PointF& point, @@ -221,8 +227,9 @@ SetSingleSelect(nHitIndex); } - if (!IsItemVisible(nHitIndex)) + if (!IsItemVisible(nHitIndex)) { ScrollToListItem(nHitIndex); + } } void CPWL_ListCtrl::OnVK(int32_t nItemIndex, bool bShift, bool bCtrl) { @@ -246,8 +253,9 @@ SetSingleSelect(nItemIndex); } - if (!IsItemVisible(nItemIndex)) + if (!IsItemVisible(nItemIndex)) { ScrollToListItem(nItemIndex); + } } void CPWL_ListCtrl::OnVK_UP(bool bShift, bool bCtrl) { @@ -298,8 +306,9 @@ } CFX_FloatRect CPWL_ListCtrl::GetItemRectInternal(int32_t nIndex) const { - if (!IsValid(nIndex)) + if (!IsValid(nIndex)) { return CFX_FloatRect(); + } CFX_FloatRect rcItem = list_items_[nIndex]->GetRect(); rcItem.left = 0.0f; @@ -313,8 +322,9 @@ } void CPWL_ListCtrl::SetMultipleSelect(int32_t nItemIndex, bool bSelected) { - if (!IsValid(nItemIndex)) + if (!IsValid(nItemIndex)) { return; + } if (bSelected != IsItemSelected(nItemIndex)) { if (bSelected) { @@ -328,8 +338,9 @@ } void CPWL_ListCtrl::SetSingleSelect(int32_t nItemIndex) { - if (!IsValid(nItemIndex)) + if (!IsValid(nItemIndex)) { return; + } if (sel_item_ != nItemIndex) { if (sel_item_ >= 0) { @@ -344,8 +355,9 @@ } void CPWL_ListCtrl::SetCaret(int32_t nItemIndex) { - if (!IsValid(nItemIndex)) + if (!IsValid(nItemIndex)) { return; + } if (IsMultipleSel()) { int32_t nOldIndex = caret_index_; @@ -389,15 +401,17 @@ void CPWL_ListCtrl::SelectItems() { for (const auto& item : select_state_) { - if (item.second != SelectState::NORMAL) + if (item.second != SelectState::NORMAL) { SetMultipleSelect(item.first, item.second == SelectState::SELECTING); + } } select_state_.Done(); } void CPWL_ListCtrl::Select(int32_t nItemIndex) { - if (!IsValid(nItemIndex)) + if (!IsValid(nItemIndex)) { return; + } if (IsMultipleSel()) { select_state_.Add(nItemIndex); @@ -408,13 +422,15 @@ } void CPWL_ListCtrl::Deselect(int32_t nItemIndex) { - if (!IsItemSelected(nItemIndex)) + if (!IsItemSelected(nItemIndex)) { return; + } SetMultipleSelect(nItemIndex, false); - if (!IsMultipleSel()) + if (!IsMultipleSel()) { sel_item_ = -1; + } } bool CPWL_ListCtrl::IsItemVisible(int32_t nItemIndex) const { @@ -425,8 +441,9 @@ } void CPWL_ListCtrl::ScrollToListItem(int32_t nItemIndex) { - if (!IsValid(nItemIndex)) + if (!IsValid(nItemIndex)) { return; + } CFX_FloatRect rcPlate = plate_rect_; CFX_FloatRect rcItem = GetItemRectInternal(nItemIndex); @@ -500,8 +517,9 @@ void CPWL_ListCtrl::ReArrange(int32_t nItemIndex) { float fPosY = 0.0f; - if (IsValid(nItemIndex - 1)) + if (IsValid(nItemIndex - 1)) { fPosY = list_items_[nItemIndex - 1]->GetRect().bottom; + } for (const auto& pListItem : list_items_) { float fListItemHeight = pListItem->GetItemHeight(); @@ -522,8 +540,9 @@ int32_t CPWL_ListCtrl::GetTopItem() const { int32_t nItemIndex = GetItemIndex(GetBTPoint()); - if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1)) + if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1)) { nItemIndex += 1; + } return nItemIndex; } @@ -534,24 +553,29 @@ bool bLast = true; for (const auto& pListItem : list_items_) { CFX_FloatRect rcListItem = pListItem->GetRect(); - if (FXSYS_IsFloatBigger(pt.y, rcListItem.top)) + if (FXSYS_IsFloatBigger(pt.y, rcListItem.top)) { bFirst = false; - if (FXSYS_IsFloatSmaller(pt.y, rcListItem.bottom)) + } + if (FXSYS_IsFloatSmaller(pt.y, rcListItem.bottom)) { bLast = false; + } if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) { return pdfium::checked_cast<int32_t>(&pListItem - &list_items_.front()); } } - if (bFirst) + if (bFirst) { return 0; - if (bLast) + } + if (bLast) { return GetCount() - 1; + } return -1; } WideString CPWL_ListCtrl::GetText() const { - if (IsMultipleSel()) + if (IsMultipleSel()) { return GetItemText(caret_index_); + } return GetItemText(sel_item_); } @@ -564,8 +588,9 @@ } CPWL_EditImpl* CPWL_ListCtrl::GetItemEdit(int32_t nIndex) const { - if (!IsValid(nIndex)) + if (!IsValid(nIndex)) { return nullptr; + } return list_items_[nIndex]->GetEdit(); } @@ -583,8 +608,9 @@ int32_t CPWL_ListCtrl::GetFirstSelected() const { int32_t i = 0; for (const auto& pListItem : list_items_) { - if (pListItem->IsSelected()) + if (pListItem->IsSelected()) { return i; + } ++i; } return -1; @@ -592,8 +618,9 @@ int32_t CPWL_ListCtrl::GetLastSelected() const { for (auto iter = list_items_.rbegin(); iter != list_items_.rend(); ++iter) { - if ((*iter)->IsSelected()) + if ((*iter)->IsSelected()) { return pdfium::checked_cast<int32_t>(&*iter - &list_items_.front()); + } } return -1; } @@ -603,12 +630,14 @@ int32_t sz = GetCount(); for (int32_t i = 0; i < sz; i++) { nCircleIndex++; - if (nCircleIndex >= sz) + if (nCircleIndex >= sz) { nCircleIndex = 0; + } if (Item* pListItem = list_items_[nCircleIndex].get()) { - if (FXSYS_towupper(pListItem->GetFirstChar()) == FXSYS_towupper(nChar)) + if (FXSYS_towupper(pListItem->GetFirstChar()) == FXSYS_towupper(nChar)) { return nCircleIndex; + } } } @@ -620,8 +649,9 @@ } void CPWL_ListCtrl::SetItemSelect(int32_t nIndex, bool bSelected) { - if (IsValid(nIndex)) + if (IsValid(nIndex)) { list_items_[nIndex]->SetSelect(bSelected); + } } bool CPWL_ListCtrl::IsValid(int32_t nItemIndex) const { @@ -629,7 +659,8 @@ } WideString CPWL_ListCtrl::GetItemText(int32_t nIndex) const { - if (IsValid(nIndex)) + if (IsValid(nIndex)) { return list_items_[nIndex]->GetText(); + } return WideString(); }
diff --git a/fpdfsdk/pwl/cpwl_sbbutton.cpp b/fpdfsdk/pwl/cpwl_sbbutton.cpp index 7ad743b..31206ca 100644 --- a/fpdfsdk/pwl/cpwl_sbbutton.cpp +++ b/fpdfsdk/pwl/cpwl_sbbutton.cpp
@@ -23,12 +23,14 @@ void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device) { - if (!IsVisible()) + if (!IsVisible()) { return; + } CFX_FloatRect rectWnd = GetWindowRect(); - if (rectWnd.IsEmpty()) + if (rectWnd.IsEmpty()) { return; + } CFX_PointF ptCenter = GetCenterPoint(); int32_t nTransparency = GetTransparency(); @@ -93,8 +95,9 @@ } // draw friction - if (rectWnd.Height() <= 8.0f) + if (rectWnd.Height() <= 8.0f) { return; + } FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); float nFrictionWidth = 5.0f; @@ -115,8 +118,9 @@ const CFX_PointF& point) { CPWL_Wnd::OnLButtonDown(nFlag, point); - if (CPWL_Wnd* pParent = GetParentWindow()) + if (CPWL_Wnd* pParent = GetParentWindow()) { pParent->NotifyLButtonDown(this, point); + } mouse_down_ = true; SetCapture(); @@ -128,8 +132,9 @@ const CFX_PointF& point) { CPWL_Wnd::OnLButtonUp(nFlag, point); - if (CPWL_Wnd* pParent = GetParentWindow()) + if (CPWL_Wnd* pParent = GetParentWindow()) { pParent->NotifyLButtonUp(this, point); + } mouse_down_ = false; ReleaseCapture(); @@ -141,8 +146,9 @@ const CFX_PointF& point) { CPWL_Wnd::OnMouseMove(nFlag, point); - if (CPWL_Wnd* pParent = GetParentWindow()) + if (CPWL_Wnd* pParent = GetParentWindow()) { pParent->NotifyMouseMove(this, point); + } return true; }
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp index c6c59ec..0692cb6 100644 --- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
@@ -59,10 +59,12 @@ void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { ScrollRange.Set(min, max); - if (FXSYS_IsFloatSmaller(fScrollPos, ScrollRange.fMin)) + if (FXSYS_IsFloatSmaller(fScrollPos, ScrollRange.fMin)) { fScrollPos = ScrollRange.fMin; - if (FXSYS_IsFloatBigger(fScrollPos, ScrollRange.fMax)) + } + if (FXSYS_IsFloatBigger(fScrollPos, ScrollRange.fMax)) { fScrollPos = ScrollRange.fMax; + } } void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { @@ -86,23 +88,27 @@ } void PWL_SCROLL_PRIVATEDATA::AddSmall() { - if (!SetPos(fScrollPos + fSmallStep)) + if (!SetPos(fScrollPos + fSmallStep)) { SetPos(ScrollRange.fMax); + } } void PWL_SCROLL_PRIVATEDATA::SubSmall() { - if (!SetPos(fScrollPos - fSmallStep)) + if (!SetPos(fScrollPos - fSmallStep)) { SetPos(ScrollRange.fMin); + } } void PWL_SCROLL_PRIVATEDATA::AddBig() { - if (!SetPos(fScrollPos + fBigStep)) + if (!SetPos(fScrollPos + fBigStep)) { SetPos(ScrollRange.fMax); + } } void PWL_SCROLL_PRIVATEDATA::SubBig() { - if (!SetPos(fScrollPos - fBigStep)) + if (!SetPos(fScrollPos - fBigStep)) { SetPos(ScrollRange.fMin); + } } CPWL_ScrollBar::CPWL_ScrollBar( @@ -192,8 +198,9 @@ if (HasFlag(PWS_AUTOTRANSPARENT)) { if (GetTransparency() != 255) { SetTransparency(255); - if (!InvalidateRect(nullptr)) + if (!InvalidateRect(nullptr)) { return true; + } } } @@ -212,15 +219,17 @@ if (rcMinArea.Contains(point)) { private_data_.SubBig(); - if (!MovePosButton(true)) + if (!MovePosButton(true)) { return true; + } NotifyScrollWindow(); } if (rcMaxArea.Contains(point)) { private_data_.AddBig(); - if (!MovePosButton(true)) + if (!MovePosButton(true)) { return true; + } NotifyScrollWindow(); } } @@ -235,8 +244,9 @@ if (HasFlag(PWS_AUTOTRANSPARENT)) { if (GetTransparency() != kTransparency) { SetTransparency(kTransparency); - if (!InvalidateRect(nullptr)) + if (!InvalidateRect(nullptr)) { return true; + } } } @@ -406,8 +416,9 @@ void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { private_data_.SubSmall(); - if (!MovePosButton(true)) + if (!MovePosButton(true)) { return; + } NotifyScrollWindow(); min_or_max_ = true; @@ -420,8 +431,9 @@ void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { private_data_.AddSmall(); - if (!MovePosButton(true)) + if (!MovePosButton(true)) { return; + } NotifyScrollWindow(); min_or_max_ = false; @@ -465,8 +477,9 @@ private_data_.SetPos(fNewPos); if (!FXSYS_IsFloatEqual(fOldScrollPos, private_data_.fScrollPos)) { - if (!MovePosButton(true)) + if (!MovePosButton(true)) { return; + } NotifyScrollWindow(); } @@ -475,8 +488,9 @@ void CPWL_ScrollBar::NotifyScrollWindow() { CPWL_Wnd* pParent = GetParentWindow(); - if (!pParent) + if (!pParent) { return; + } pParent->ScrollWindowVertically(origin_info_.fContentMax - private_data_.fScrollPos); @@ -540,8 +554,9 @@ return; } - if (!MovePosButton(true)) + if (!MovePosButton(true)) { return; + } NotifyScrollWindow(); }
diff --git a/fpdfsdk/pwl/cpwl_special_button.cpp b/fpdfsdk/pwl/cpwl_special_button.cpp index 17f209a..28a61a9 100644 --- a/fpdfsdk/pwl/cpwl_special_button.cpp +++ b/fpdfsdk/pwl/cpwl_special_button.cpp
@@ -32,16 +32,18 @@ bool CPWL_CheckBox::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point) { - if (IsReadOnly()) + if (IsReadOnly()) { return false; + } SetCheck(!IsChecked()); return true; } bool CPWL_CheckBox::OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) { - if (IsReadOnly()) + if (IsReadOnly()) { return false; + } SetCheck(!IsChecked()); return true; @@ -56,16 +58,18 @@ bool CPWL_RadioButton::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point) { - if (IsReadOnly()) + if (IsReadOnly()) { return false; + } SetCheck(true); return true; } bool CPWL_RadioButton::OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) { - if (IsReadOnly()) + if (IsReadOnly()) { return false; + } SetCheck(true); return true;
diff --git a/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp b/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp index e9f1d6d..6a9f34f 100644 --- a/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp +++ b/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp
@@ -18,9 +18,7 @@ ASSERT_TRUE(OpenDocument("click_form.pdf")); } - void TearDown() override { - EmbedderTest::TearDown(); - } + void TearDown() override { EmbedderTest::TearDown(); } void CreateAndInitializeFormPDF() { formfill_env_ = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle());
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp index 9a0153b..2ec3239 100644 --- a/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -84,8 +84,9 @@ ObservedPtr<SharedCaptureFocusState> this_observed(this); if (!this_observed->keyboard_paths_.empty()) { CPWL_Wnd* pWnd = this_observed->keyboard_paths_.front(); - if (pWnd) + if (pWnd) { pWnd->OnKillFocus(); + } } if (!this_observed) { return; @@ -211,8 +212,9 @@ } bool CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) { - if (!IsValid()) + if (!IsValid()) { return true; + } CFX_FloatRect rcOld = GetWindowRect(); window_rect_ = rcNew; @@ -226,8 +228,9 @@ } } } - if (bRefresh && !InvalidateRectMove(rcOld, rcNew)) + if (bRefresh && !InvalidateRectMove(rcOld, rcNew)) { return false; + } creation_params_.rcRectWnd = window_rect_; return true; @@ -252,8 +255,9 @@ void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device) { CFX_FloatRect rectWnd = GetWindowRect(); - if (rectWnd.IsEmpty()) + if (rectWnd.IsEmpty()) { return; + } if (HasFlag(PWS_BACKGROUND)) { float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); @@ -285,8 +289,9 @@ CFX_FloatRect rcRefresh = pRect ? *pRect : this_observed->GetWindowRect(); if (!this_observed->HasFlag(PWS_NOREFRESHCLIP)) { CFX_FloatRect rcClip = this_observed->GetClipRect(); - if (!rcClip.IsEmpty()) + if (!rcClip.IsEmpty()) { rcRefresh.Intersect(rcClip); + } } CFX_FloatRect rcWin = this_observed->PWLtoWnd(rcRefresh); @@ -298,25 +303,31 @@ } bool CPWL_Wnd::OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag) { - if (!IsValid() || !IsVisible()) + if (!IsValid() || !IsVisible()) { return false; - if (!IsWndCaptureKeyboard(this)) + } + if (!IsWndCaptureKeyboard(this)) { return false; + } for (const auto& pChild : children_) { - if (IsWndCaptureKeyboard(pChild.get())) + if (IsWndCaptureKeyboard(pChild.get())) { return pChild->OnKeyDown(nKeyCode, nFlag); + } } return false; } bool CPWL_Wnd::OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) { - if (!IsValid() || !IsVisible()) + if (!IsValid() || !IsVisible()) { return false; - if (!IsWndCaptureKeyboard(this)) + } + if (!IsWndCaptureKeyboard(this)) { return false; + } for (const auto& pChild : children_) { - if (IsWndCaptureKeyboard(pChild.get())) + if (IsWndCaptureKeyboard(pChild.get())) { return pChild->OnChar(nChar, nFlag); + } } return false; } @@ -396,16 +407,19 @@ bool CPWL_Wnd::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point, const CFX_Vector& delta) { - if (!IsValid() || !IsVisible()) + if (!IsValid() || !IsVisible()) { return false; + } SetCursor(); - if (!IsWndCaptureKeyboard(this)) + if (!IsWndCaptureKeyboard(this)) { return false; + } for (const auto& pChild : children_) { - if (IsWndCaptureKeyboard(pChild.get())) + if (IsWndCaptureKeyboard(pChild.get())) { return pChild->OnMouseWheel(nFlag, point, delta); + } } return false; } @@ -450,8 +464,9 @@ float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width); - if (CPWL_ScrollBar* pVSB = GetVScrollBar()) + if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { rcClient.right -= pVSB->GetScrollBarWidth(); + } rcClient.Normalize(); return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect(); @@ -640,8 +655,9 @@ void CPWL_Wnd::CreateChildWnd(const CreateParams& cp) {} void CPWL_Wnd::SetCursor() { - if (IsValid()) + if (IsValid()) { GetFillerNotify()->SetCursor(GetCreationParams()->eCursorType); + } } void CPWL_Wnd::CreateSharedCaptureFocusState() { @@ -741,8 +757,9 @@ CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { CFX_Matrix mt; - if (ProviderIface* pProvider = GetProvider()) + if (ProviderIface* pProvider = GetProvider()) { mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); + } return mt; }