Clang-format core/fpdfdoc
Change-Id: Id823bfeb6f69450f6b81286c6d1a3b59ac7c18de
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130712
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index f3c2946..84b72f3 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -58,15 +58,17 @@
}
ByteString csType = dict_->GetNameFor("S");
- if (csType.IsEmpty())
+ if (csType.IsEmpty()) {
return Type::kUnknown;
+ }
static_assert(
std::size(kActionTypeStrings) == static_cast<size_t>(Type::kLast),
"Type mismatch");
for (size_t i = 0; i < std::size(kActionTypeStrings); ++i) {
- if (csType == kActionTypeStrings[i])
+ if (csType == kActionTypeStrings[i]) {
return static_cast<Type>(i + 1);
+ }
}
return Type::kUnknown;
}
@@ -88,23 +90,27 @@
RetainPtr<const CPDF_Object> pFile =
dict_->GetDirectObjectFor(pdfium::stream::kF);
- if (pFile)
+ if (pFile) {
return CPDF_FileSpec(std::move(pFile)).GetFileName();
+ }
- if (type != Type::kLaunch)
+ if (type != Type::kLaunch) {
return WideString();
+ }
RetainPtr<const CPDF_Dictionary> pWinDict = dict_->GetDictFor("Win");
- if (!pWinDict)
+ if (!pWinDict) {
return WideString();
+ }
return WideString::FromDefANSI(
pWinDict->GetByteStringFor(pdfium::stream::kF).AsStringView());
}
ByteString CPDF_Action::GetURI(const CPDF_Document* pDoc) const {
- if (GetType() != Type::kURI)
+ if (GetType() != Type::kURI) {
return ByteString();
+ }
ByteString csURI = dict_->GetByteStringFor("URI");
RetainPtr<const CPDF_Dictionary> pURI = pDoc->GetRoot()->GetDictFor("URI");
@@ -112,8 +118,9 @@
auto result = csURI.Find(":");
if (!result.has_value() || result.value() == 0) {
RetainPtr<const CPDF_Object> pBase = pURI->GetDirectObjectFor("Base");
- if (pBase && (pBase->IsString() || pBase->IsStream()))
+ if (pBase && (pBase->IsString() || pBase->IsStream())) {
csURI = pBase->GetString() + csURI;
+ }
}
}
return csURI;
@@ -145,8 +152,9 @@
RetainPtr<const CPDF_Object> pFields = csType == "Hide"
? dict_->GetDirectObjectFor("T")
: dict_->GetArrayFor("Fields");
- if (!pFields)
+ if (!pFields) {
return result;
+ }
if (pFields->IsDictionary() || pFields->IsString()) {
result.push_back(std::move(pFields));
@@ -154,21 +162,24 @@
}
const CPDF_Array* pArray = pFields->AsArray();
- if (!pArray)
+ if (!pArray) {
return result;
+ }
for (size_t i = 0; i < pArray->size(); ++i) {
RetainPtr<const CPDF_Object> pObj = pArray->GetDirectObjectAt(i);
- if (pObj)
+ if (pObj) {
result.push_back(std::move(pObj));
+ }
}
return result;
}
std::optional<WideString> CPDF_Action::MaybeGetJavaScript() const {
RetainPtr<const CPDF_Object> pObject = GetJavaScriptObject();
- if (!pObject)
+ if (!pObject) {
return std::nullopt;
+ }
return pObject->GetUnicodeText();
}
@@ -183,10 +194,12 @@
}
RetainPtr<const CPDF_Object> pNext = dict_->GetDirectObjectFor("Next");
- if (!pNext)
+ if (!pNext) {
return 0;
- if (pNext->IsDictionary())
+ }
+ if (pNext->IsDictionary()) {
return 1;
+ }
const CPDF_Array* pArray = pNext->AsArray();
return pArray ? pArray->size() : 0;
}
@@ -197,15 +210,18 @@
}
RetainPtr<const CPDF_Object> pNext = dict_->GetDirectObjectFor("Next");
- if (!pNext)
+ if (!pNext) {
return CPDF_Action(nullptr);
+ }
- if (const CPDF_Array* pArray = pNext->AsArray())
+ if (const CPDF_Array* pArray = pNext->AsArray()) {
return CPDF_Action(pArray->GetDictAt(iIndex));
+ }
if (const CPDF_Dictionary* pDict = pNext->AsDictionary()) {
- if (iIndex == 0)
+ if (iIndex == 0) {
return CPDF_Action(pdfium::WrapRetain(pDict));
+ }
}
return CPDF_Action(nullptr);
}
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 837abf3..ecb98ae 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -48,8 +48,9 @@
const CFX_Matrix& mtUser2Device,
CFX_Matrix* matrix) {
CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode);
- if (!pForm)
+ if (!pForm) {
return nullptr;
+ }
CFX_Matrix form_matrix = pForm->GetDict()->GetMatrixFor("Matrix");
CFX_FloatRect form_bbox =
@@ -79,28 +80,34 @@
bool bFallbackToNormal) {
RetainPtr<CPDF_Dictionary> pAP =
pAnnotDict->GetMutableDictFor(pdfium::annotation::kAP);
- if (!pAP)
+ if (!pAP) {
return nullptr;
+ }
const char* ap_entry = "N";
- if (eMode == CPDF_Annot::AppearanceMode::kDown)
+ if (eMode == CPDF_Annot::AppearanceMode::kDown) {
ap_entry = "D";
- else if (eMode == CPDF_Annot::AppearanceMode::kRollover)
+ } else if (eMode == CPDF_Annot::AppearanceMode::kRollover) {
ap_entry = "R";
- if (bFallbackToNormal && !pAP->KeyExist(ap_entry))
+ }
+ if (bFallbackToNormal && !pAP->KeyExist(ap_entry)) {
ap_entry = "N";
+ }
RetainPtr<CPDF_Object> psub = pAP->GetMutableDirectObjectFor(ap_entry);
- if (!psub)
+ if (!psub) {
return nullptr;
+ }
RetainPtr<CPDF_Stream> pStream(psub->AsMutableStream());
- if (pStream)
+ if (pStream) {
return pStream;
+ }
CPDF_Dictionary* pDict = psub->AsMutableDictionary();
- if (!pDict)
+ if (!pDict) {
return nullptr;
+ }
ByteString as = pAnnotDict->GetByteStringFor(pdfium::annotation::kAS);
if (as.IsEmpty()) {
@@ -134,8 +141,9 @@
}
void CPDF_Annot::GenerateAPIfNeeded() {
- if (!ShouldGenerateAP())
+ if (!ShouldGenerateAP()) {
return;
+ }
if (!CPDF_GenerateAP::GenerateAnnotAP(document_, annot_dict_.Get(),
subtype_)) {
return;
@@ -150,15 +158,17 @@
// the appearance defined in the existing AP dictionary.
RetainPtr<const CPDF_Dictionary> pAP =
annot_dict_->GetDictFor(pdfium::annotation::kAP);
- if (pAP && pAP->GetDictFor("N"))
+ if (pAP && pAP->GetDictFor("N")) {
return false;
+ }
return !IsHidden();
}
bool CPDF_Annot::ShouldDrawAnnotation() const {
- if (IsHidden())
+ if (IsHidden()) {
return false;
+ }
return open_state_ || subtype_ != CPDF_Annot::Subtype::POPUP;
}
@@ -173,8 +183,9 @@
CFX_FloatRect CPDF_Annot::RectForDrawing() const {
bool bShouldUseQuadPointsCoords =
is_text_markup_annotation_ && has_generated_ap_;
- if (bShouldUseQuadPointsCoords)
+ if (bShouldUseQuadPointsCoords) {
return BoundingRectFromQuadPoints(annot_dict_.Get());
+ }
return annot_dict_->GetRectFor(pdfium::annotation::kRect);
}
@@ -206,8 +217,9 @@
CPDF_Form* CPDF_Annot::GetAPForm(CPDF_Page* pPage, AppearanceMode mode) {
RetainPtr<CPDF_Stream> pStream = GetAnnotAP(annot_dict_.Get(), mode);
- if (!pStream)
+ if (!pStream) {
return nullptr;
+ }
auto it = ap_map_.find(pStream);
if (it != ap_map_.end()) {
@@ -264,8 +276,9 @@
CFX_FloatRect ret;
RetainPtr<const CPDF_Array> pArray = pAnnotDict->GetArrayFor("QuadPoints");
size_t nQuadPointCount = pArray ? QuadPointCount(pArray.Get()) : 0;
- if (nQuadPointCount == 0)
+ if (nQuadPointCount == 0) {
return ret;
+ }
ret = RectFromQuadPointsArray(pArray.Get(), 0);
for (size_t i = 1; i < nQuadPointCount; ++i) {
@@ -280,131 +293,188 @@
size_t nIndex) {
RetainPtr<const CPDF_Array> pArray = pAnnotDict->GetArrayFor("QuadPoints");
size_t nQuadPointCount = pArray ? QuadPointCount(pArray.Get()) : 0;
- if (nIndex >= nQuadPointCount)
+ if (nIndex >= nQuadPointCount) {
return CFX_FloatRect();
+ }
return RectFromQuadPointsArray(pArray.Get(), nIndex);
}
// static
CPDF_Annot::Subtype CPDF_Annot::StringToAnnotSubtype(
const ByteString& sSubtype) {
- if (sSubtype == "Text")
+ if (sSubtype == "Text") {
return CPDF_Annot::Subtype::TEXT;
- if (sSubtype == "Link")
+ }
+ if (sSubtype == "Link") {
return CPDF_Annot::Subtype::LINK;
- if (sSubtype == "FreeText")
+ }
+ if (sSubtype == "FreeText") {
return CPDF_Annot::Subtype::FREETEXT;
- if (sSubtype == "Line")
+ }
+ if (sSubtype == "Line") {
return CPDF_Annot::Subtype::LINE;
- if (sSubtype == "Square")
+ }
+ if (sSubtype == "Square") {
return CPDF_Annot::Subtype::SQUARE;
- if (sSubtype == "Circle")
+ }
+ if (sSubtype == "Circle") {
return CPDF_Annot::Subtype::CIRCLE;
- if (sSubtype == "Polygon")
+ }
+ if (sSubtype == "Polygon") {
return CPDF_Annot::Subtype::POLYGON;
- if (sSubtype == "PolyLine")
+ }
+ if (sSubtype == "PolyLine") {
return CPDF_Annot::Subtype::POLYLINE;
- if (sSubtype == "Highlight")
+ }
+ if (sSubtype == "Highlight") {
return CPDF_Annot::Subtype::HIGHLIGHT;
- if (sSubtype == "Underline")
+ }
+ if (sSubtype == "Underline") {
return CPDF_Annot::Subtype::UNDERLINE;
- if (sSubtype == "Squiggly")
+ }
+ if (sSubtype == "Squiggly") {
return CPDF_Annot::Subtype::SQUIGGLY;
- if (sSubtype == "StrikeOut")
+ }
+ if (sSubtype == "StrikeOut") {
return CPDF_Annot::Subtype::STRIKEOUT;
- if (sSubtype == "Stamp")
+ }
+ if (sSubtype == "Stamp") {
return CPDF_Annot::Subtype::STAMP;
- if (sSubtype == "Caret")
+ }
+ if (sSubtype == "Caret") {
return CPDF_Annot::Subtype::CARET;
- if (sSubtype == "Ink")
+ }
+ if (sSubtype == "Ink") {
return CPDF_Annot::Subtype::INK;
- if (sSubtype == "Popup")
+ }
+ if (sSubtype == "Popup") {
return CPDF_Annot::Subtype::POPUP;
- if (sSubtype == "FileAttachment")
+ }
+ if (sSubtype == "FileAttachment") {
return CPDF_Annot::Subtype::FILEATTACHMENT;
- if (sSubtype == "Sound")
+ }
+ if (sSubtype == "Sound") {
return CPDF_Annot::Subtype::SOUND;
- if (sSubtype == "Movie")
+ }
+ if (sSubtype == "Movie") {
return CPDF_Annot::Subtype::MOVIE;
- if (sSubtype == "Widget")
+ }
+ if (sSubtype == "Widget") {
return CPDF_Annot::Subtype::WIDGET;
- if (sSubtype == "Screen")
+ }
+ if (sSubtype == "Screen") {
return CPDF_Annot::Subtype::SCREEN;
- if (sSubtype == "PrinterMark")
+ }
+ if (sSubtype == "PrinterMark") {
return CPDF_Annot::Subtype::PRINTERMARK;
- if (sSubtype == "TrapNet")
+ }
+ if (sSubtype == "TrapNet") {
return CPDF_Annot::Subtype::TRAPNET;
- if (sSubtype == "Watermark")
+ }
+ if (sSubtype == "Watermark") {
return CPDF_Annot::Subtype::WATERMARK;
- if (sSubtype == "3D")
+ }
+ if (sSubtype == "3D") {
return CPDF_Annot::Subtype::THREED;
- if (sSubtype == "RichMedia")
+ }
+ if (sSubtype == "RichMedia") {
return CPDF_Annot::Subtype::RICHMEDIA;
- if (sSubtype == "XFAWidget")
+ }
+ if (sSubtype == "XFAWidget") {
return CPDF_Annot::Subtype::XFAWIDGET;
- if (sSubtype == "Redact")
+ }
+ if (sSubtype == "Redact") {
return CPDF_Annot::Subtype::REDACT;
+ }
return CPDF_Annot::Subtype::UNKNOWN;
}
// static
ByteString CPDF_Annot::AnnotSubtypeToString(CPDF_Annot::Subtype nSubtype) {
- if (nSubtype == CPDF_Annot::Subtype::TEXT)
+ if (nSubtype == CPDF_Annot::Subtype::TEXT) {
return "Text";
- if (nSubtype == CPDF_Annot::Subtype::LINK)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::LINK) {
return "Link";
- if (nSubtype == CPDF_Annot::Subtype::FREETEXT)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::FREETEXT) {
return "FreeText";
- if (nSubtype == CPDF_Annot::Subtype::LINE)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::LINE) {
return "Line";
- if (nSubtype == CPDF_Annot::Subtype::SQUARE)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::SQUARE) {
return "Square";
- if (nSubtype == CPDF_Annot::Subtype::CIRCLE)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::CIRCLE) {
return "Circle";
- if (nSubtype == CPDF_Annot::Subtype::POLYGON)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::POLYGON) {
return "Polygon";
- if (nSubtype == CPDF_Annot::Subtype::POLYLINE)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::POLYLINE) {
return "PolyLine";
- if (nSubtype == CPDF_Annot::Subtype::HIGHLIGHT)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::HIGHLIGHT) {
return "Highlight";
- if (nSubtype == CPDF_Annot::Subtype::UNDERLINE)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::UNDERLINE) {
return "Underline";
- if (nSubtype == CPDF_Annot::Subtype::SQUIGGLY)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::SQUIGGLY) {
return "Squiggly";
- if (nSubtype == CPDF_Annot::Subtype::STRIKEOUT)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::STRIKEOUT) {
return "StrikeOut";
- if (nSubtype == CPDF_Annot::Subtype::STAMP)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::STAMP) {
return "Stamp";
- if (nSubtype == CPDF_Annot::Subtype::CARET)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::CARET) {
return "Caret";
- if (nSubtype == CPDF_Annot::Subtype::INK)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::INK) {
return "Ink";
- if (nSubtype == CPDF_Annot::Subtype::POPUP)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::POPUP) {
return "Popup";
- if (nSubtype == CPDF_Annot::Subtype::FILEATTACHMENT)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::FILEATTACHMENT) {
return "FileAttachment";
- if (nSubtype == CPDF_Annot::Subtype::SOUND)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::SOUND) {
return "Sound";
- if (nSubtype == CPDF_Annot::Subtype::MOVIE)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::MOVIE) {
return "Movie";
- if (nSubtype == CPDF_Annot::Subtype::WIDGET)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::WIDGET) {
return "Widget";
- if (nSubtype == CPDF_Annot::Subtype::SCREEN)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::SCREEN) {
return "Screen";
- if (nSubtype == CPDF_Annot::Subtype::PRINTERMARK)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::PRINTERMARK) {
return "PrinterMark";
- if (nSubtype == CPDF_Annot::Subtype::TRAPNET)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::TRAPNET) {
return "TrapNet";
- if (nSubtype == CPDF_Annot::Subtype::WATERMARK)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::WATERMARK) {
return "Watermark";
- if (nSubtype == CPDF_Annot::Subtype::THREED)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::THREED) {
return "3D";
- if (nSubtype == CPDF_Annot::Subtype::RICHMEDIA)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::RICHMEDIA) {
return "RichMedia";
- if (nSubtype == CPDF_Annot::Subtype::XFAWIDGET)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::XFAWIDGET) {
return "XFAWidget";
- if (nSubtype == CPDF_Annot::Subtype::REDACT)
+ }
+ if (nSubtype == CPDF_Annot::Subtype::REDACT) {
return "Redact";
+ }
return ByteString();
}
@@ -417,8 +487,9 @@
CFX_RenderDevice* pDevice,
const CFX_Matrix& mtUser2Device,
AppearanceMode mode) {
- if (!ShouldDrawAnnotation())
+ if (!ShouldDrawAnnotation()) {
return false;
+ }
// It might happen that by the time this annotation instance was created,
// it was flagged as "hidden" (e.g. /F 2), and hence CPDF_GenerateAP decided
@@ -429,8 +500,9 @@
CFX_Matrix matrix;
CPDF_Form* pForm = AnnotGetMatrix(pPage, this, mode, mtUser2Device, &matrix);
- if (!pForm)
+ if (!pForm) {
return false;
+ }
CPDF_RenderContext context(pPage->GetDocument(),
pPage->GetMutablePageResources(),
@@ -444,8 +516,9 @@
CPDF_RenderContext* pContext,
const CFX_Matrix& mtUser2Device,
AppearanceMode mode) {
- if (!ShouldDrawAnnotation())
+ if (!ShouldDrawAnnotation()) {
return false;
+ }
// It might happen that by the time this annotation instance was created,
// it was flagged as "hidden" (e.g. /F 2), and hence CPDF_GenerateAP decided
@@ -456,8 +529,9 @@
CFX_Matrix matrix;
CPDF_Form* pForm = AnnotGetMatrix(pPage, this, mode, mtUser2Device, &matrix);
- if (!pForm)
+ if (!pForm) {
return false;
+ }
pContext->AppendLayer(pForm, matrix);
return true;
@@ -465,12 +539,14 @@
void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice,
const CFX_Matrix* pUser2Device) {
- if (GetSubtype() == CPDF_Annot::Subtype::POPUP)
+ if (GetSubtype() == CPDF_Annot::Subtype::POPUP) {
return;
+ }
uint32_t annot_flags = GetFlags();
- if (annot_flags & pdfium::annotation_flags::kHidden)
+ if (annot_flags & pdfium::annotation_flags::kHidden) {
return;
+ }
#if BUILDFLAG(IS_WIN)
bool is_printing = pDevice->GetDeviceType() == DeviceType::kPrinter;
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 1c74533..ca2788d 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -72,12 +72,14 @@
std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Document* pDocument,
CPDF_Page* pPage,
CPDF_Annot* pAnnot) {
- if (!PopupAppearsForAnnotType(pAnnot->GetSubtype()))
+ if (!PopupAppearsForAnnotType(pAnnot->GetSubtype())) {
return nullptr;
+ }
const CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict();
- if (!pParentDict)
+ if (!pParentDict) {
return nullptr;
+ }
// TODO(crbug.com/pdfium/1098): Determine if we really need to check if
// /Contents is empty or not. If so, optimize decoding for empty check.
@@ -130,8 +132,9 @@
RetainPtr<const CPDF_Object> pFieldTypeObj =
CPDF_FormField::GetFieldAttrForDict(pAnnotDict, pdfium::form_fields::kFT);
- if (!pFieldTypeObj)
+ if (!pFieldTypeObj) {
return;
+ }
ByteString field_type = pFieldTypeObj->GetString();
if (field_type == pdfium::form_fields::kTx) {
@@ -151,17 +154,21 @@
return;
}
- if (field_type != pdfium::form_fields::kBtn)
+ if (field_type != pdfium::form_fields::kBtn) {
return;
- if (flags & pdfium::form_flags::kButtonPushbutton)
+ }
+ if (flags & pdfium::form_flags::kButtonPushbutton) {
return;
- if (pAnnotDict->KeyExist(pdfium::annotation::kAS))
+ }
+ if (pAnnotDict->KeyExist(pdfium::annotation::kAS)) {
return;
+ }
RetainPtr<const CPDF_Dictionary> pParentDict =
pAnnotDict->GetDictFor(pdfium::form_fields::kParent);
- if (!pParentDict || !pParentDict->KeyExist(pdfium::annotation::kAS))
+ if (!pParentDict || !pParentDict->KeyExist(pdfium::annotation::kAS)) {
return;
+ }
pAnnotDict->SetNewFor<CPDF_String>(
pdfium::annotation::kAS,
@@ -173,8 +180,9 @@
CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
: page_(pPage), document_(page_->GetDocument()) {
RetainPtr<CPDF_Array> pAnnots = page_->GetMutableAnnotsArray();
- if (!pAnnots)
+ if (!pAnnots) {
return;
+ }
const CPDF_Dictionary* pRoot = document_->GetRoot();
RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm");
@@ -183,8 +191,9 @@
for (size_t i = 0; i < pAnnots->size(); ++i) {
RetainPtr<CPDF_Dictionary> pDict =
ToDictionary(pAnnots->GetMutableDirectObjectAt(i));
- if (!pDict)
+ if (!pDict) {
continue;
+ }
const ByteString subtype =
pDict->GetByteStringFor(pdfium::annotation::kSubtype);
if (subtype == "Popup") {
@@ -205,8 +214,9 @@
for (size_t i = 0; i < annot_count_; ++i) {
std::unique_ptr<CPDF_Annot> pPopupAnnot =
CreatePopupAnnot(document_, page_, annot_list_[i].get());
- if (pPopupAnnot)
+ if (pPopupAnnot) {
annot_list_.push_back(std::move(pPopupAnnot));
+ }
}
}
@@ -216,8 +226,9 @@
// annotations.
size_t nPopupCount = annot_list_.size() - annot_count_;
std::vector<std::unique_ptr<CPDF_Annot>> popups(nPopupCount);
- for (size_t i = 0; i < nPopupCount; ++i)
+ for (size_t i = 0; i < nPopupCount; ++i) {
popups[i] = std::move(annot_list_[annot_count_ + i]);
+ }
annot_list_.clear();
}
@@ -236,18 +247,22 @@
CHECK(pContext);
for (const auto& pAnnot : annot_list_) {
bool bWidget = pAnnot->GetSubtype() == CPDF_Annot::Subtype::WIDGET;
- if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget))
+ if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) {
continue;
+ }
uint32_t annot_flags = pAnnot->GetFlags();
- if (annot_flags & pdfium::annotation_flags::kHidden)
+ if (annot_flags & pdfium::annotation_flags::kHidden) {
continue;
+ }
- if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0)
+ if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0) {
continue;
+ }
- if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView))
+ if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView)) {
continue;
+ }
pAnnot->DrawInContext(page_, pContext, mtMatrix,
CPDF_Annot::AppearanceMode::kNormal);
@@ -260,6 +275,7 @@
bool bShowWidget) {
CHECK(pContext);
DisplayPass(pContext, bPrinting, mtUser2Device, false);
- if (bShowWidget)
+ if (bShowWidget) {
DisplayPass(pContext, bPrinting, mtUser2Device, true);
+ }
}
diff --git a/core/fpdfdoc/cpdf_apsettings.cpp b/core/fpdfdoc/cpdf_apsettings.cpp
index 9147a55..cf15503 100644
--- a/core/fpdfdoc/cpdf_apsettings.cpp
+++ b/core/fpdfdoc/cpdf_apsettings.cpp
@@ -36,8 +36,9 @@
}
RetainPtr<const CPDF_Array> pEntry = dict_->GetArrayFor(csEntry);
- if (!pEntry)
+ if (!pEntry) {
return {CFX_Color::Type::kTransparent, 0};
+ }
const size_t dwCount = pEntry->size();
if (dwCount == 1) {
@@ -80,8 +81,9 @@
}
RetainPtr<const CPDF_Array> pEntry = dict_->GetArrayFor(csEntry);
- if (!pEntry)
+ if (!pEntry) {
return CFX_Color();
+ }
size_t dwCount = pEntry->size();
if (dwCount == 1) {
diff --git a/core/fpdfdoc/cpdf_bafontmap.cpp b/core/fpdfdoc/cpdf_bafontmap.cpp
index b7b79d5..ca385af 100644
--- a/core/fpdfdoc/cpdf_bafontmap.cpp
+++ b/core/fpdfdoc/cpdf_bafontmap.cpp
@@ -42,8 +42,9 @@
RetainPtr<CPDF_Font> AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc,
ByteString sFontFaceName,
FX_Charset nCharset) {
- if (!pDoc)
+ if (!pDoc) {
return nullptr;
+ }
auto pFXFont = std::make_unique<CFX_Font>();
pFXFont->LoadSubst(sFontFaceName, true, 0, 0, 0,
@@ -89,8 +90,9 @@
AddFontToAnnotDict(default_font_, default_font_name_);
}
- if (nCharset != FX_Charset::kANSI)
+ if (nCharset != FX_Charset::kANSI) {
GetFontIndex(CFX_Font::kDefaultAnsiFontName, FX_Charset::kANSI, false);
+ }
}
CPDF_BAFontMap::~CPDF_BAFontMap() = default;
@@ -113,16 +115,18 @@
FX_Charset nCharset,
int32_t nFontIndex) {
if (nFontIndex > 0) {
- if (KnowWord(nFontIndex, word))
+ if (KnowWord(nFontIndex, word)) {
return nFontIndex;
+ }
} else {
if (!data_.empty()) {
const Data* pData = data_.front().get();
if (nCharset == FX_Charset::kDefault ||
pData->nCharset == FX_Charset::kSymbol ||
nCharset == pData->nCharset) {
- if (KnowWord(0, word))
+ if (KnowWord(0, word)) {
return 0;
+ }
}
}
}
@@ -130,14 +134,16 @@
int32_t nNewFontIndex =
GetFontIndex(GetCachedNativeFontName(nCharset), nCharset, true);
if (nNewFontIndex >= 0) {
- if (KnowWord(nNewFontIndex, word))
+ if (KnowWord(nNewFontIndex, word)) {
return nNewFontIndex;
+ }
}
nNewFontIndex = GetFontIndex(CFX_Font::kUniversalDefaultFontName,
FX_Charset::kDefault, false);
if (nNewFontIndex >= 0) {
- if (KnowWord(nNewFontIndex, word))
+ if (KnowWord(nNewFontIndex, word)) {
return nNewFontIndex;
+ }
}
return -1;
}
@@ -148,11 +154,13 @@
}
Data* pData = data_[nFontIndex].get();
- if (!pData->pFont)
+ if (!pData->pFont) {
return -1;
+ }
- if (pData->pFont->IsUnicodeCompatible())
+ if (pData->pFont->IsUnicodeCompatible()) {
return pData->pFont->CharCodeFromUnicode(word);
+ }
return word < 0xFF ? word : -1;
}
@@ -160,12 +168,14 @@
FX_Charset CPDF_BAFontMap::CharSetFromUnicode(uint16_t word,
FX_Charset nOldCharset) {
// to avoid CJK Font to show ASCII
- if (word < 0x7F)
+ if (word < 0x7F) {
return FX_Charset::kANSI;
+ }
// follow the old charset
- if (nOldCharset != FX_Charset::kDefault)
+ if (nOldCharset != FX_Charset::kDefault) {
return nOldCharset;
+ }
return CFX_Font::GetCharSetFromUnicode(word);
}
@@ -181,17 +191,20 @@
}
const CPDF_Dictionary* pRootDict = document_->GetRoot();
- if (!pRootDict)
+ if (!pRootDict) {
return nullptr;
+ }
RetainPtr<const CPDF_Dictionary> pAcroFormDict =
pRootDict->GetDictFor("AcroForm");
- if (!pAcroFormDict)
+ if (!pAcroFormDict) {
return nullptr;
+ }
RetainPtr<const CPDF_Dictionary> pDRDict = pAcroFormDict->GetDictFor("DR");
- if (!pDRDict)
+ if (!pDRDict) {
return nullptr;
+ }
return FindResFontSameCharset(pDRDict.Get(), sFontAlias, nCharset);
}
@@ -200,12 +213,14 @@
const CPDF_Dictionary* pResDict,
ByteString* sFontAlias,
FX_Charset nCharset) {
- if (!pResDict)
+ if (!pResDict) {
return nullptr;
+ }
RetainPtr<const CPDF_Dictionary> pFonts = pResDict->GetDictFor("Font");
- if (!pFonts)
+ if (!pFonts) {
return nullptr;
+ }
RetainPtr<CPDF_Font> pFind;
CPDF_DictionaryLocker locker(pFonts);
@@ -213,13 +228,15 @@
const ByteString& csKey = it.first;
RetainPtr<CPDF_Dictionary> pElement =
ToDictionary(it.second->GetMutableDirect());
- if (!ValidateDictType(pElement.Get(), "Font"))
+ if (!ValidateDictType(pElement.Get(), "Font")) {
continue;
+ }
auto* pData = CPDF_DocPageData::FromDocument(document_);
RetainPtr<CPDF_Font> pFont = pData->GetFont(std::move(pElement));
- if (!pFont)
+ if (!pFont) {
continue;
+ }
auto maybe_charset = pFont->GetSubstFontCharset();
if (maybe_charset.has_value() && maybe_charset.value() == nCharset) {
@@ -236,15 +253,17 @@
(annot_dict_->GetNameFor(pdfium::annotation::kSubtype) == "Widget");
if (bWidget) {
RetainPtr<CPDF_Dictionary> pRootDict = document_->GetMutableRoot();
- if (pRootDict)
+ if (pRootDict) {
pAcroFormDict = pRootDict->GetMutableDictFor("AcroForm");
+ }
}
ByteString sDA;
RetainPtr<const CPDF_Object> pObj =
CPDF_FormField::GetFieldAttrForDict(annot_dict_.Get(), "DA");
- if (pObj)
+ if (pObj) {
sDA = pObj->GetString();
+ }
if (bWidget) {
if (sDA.IsEmpty()) {
@@ -252,8 +271,9 @@
sDA = pObj ? pObj->GetString() : ByteString();
}
}
- if (sDA.IsEmpty())
+ if (sDA.IsEmpty()) {
return nullptr;
+ }
CPDF_DefaultAppearance appearance(sDA);
float font_size;
@@ -283,16 +303,18 @@
}
}
}
- if (!pFontDict)
+ if (!pFontDict) {
return nullptr;
+ }
return CPDF_DocPageData::FromDocument(document_)->GetFont(pFontDict);
}
void CPDF_BAFontMap::AddFontToAnnotDict(const RetainPtr<CPDF_Font>& pFont,
const ByteString& sAlias) {
- if (!pFont)
+ if (!pFont) {
return;
+ }
RetainPtr<CPDF_Dictionary> pAPDict =
annot_dict_->GetOrCreateDictFor(pdfium::annotation::kAP);
@@ -337,8 +359,9 @@
FX_Charset nCharset,
bool bFind) {
int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
- if (nFontIndex >= 0)
+ if (nFontIndex >= 0) {
return nFontIndex;
+ }
ByteString sAlias;
RetainPtr<CPDF_Font> pFont =
@@ -376,25 +399,29 @@
}
ByteString CPDF_BAFontMap::GetNativeFontName(FX_Charset nCharset) {
- if (nCharset == FX_Charset::kDefault)
+ if (nCharset == FX_Charset::kDefault) {
nCharset = GetNativeCharset();
+ }
ByteString sFontName = CFX_Font::GetDefaultFontNameByCharset(nCharset);
- if (!FindNativeTrueTypeFont(sFontName.AsStringView()))
+ if (!FindNativeTrueTypeFont(sFontName.AsStringView())) {
return ByteString();
+ }
return sFontName;
}
ByteString CPDF_BAFontMap::GetCachedNativeFontName(FX_Charset nCharset) {
for (const auto& pData : native_font_) {
- if (pData && pData->nCharset == nCharset)
+ if (pData && pData->nCharset == nCharset) {
return pData->sFontName;
+ }
}
ByteString sNew = GetNativeFontName(nCharset);
- if (sNew.IsEmpty())
+ if (sNew.IsEmpty()) {
return ByteString();
+ }
auto pNewData = std::make_unique<Native>();
pNewData->nCharset = nCharset;
@@ -405,16 +432,18 @@
RetainPtr<CPDF_Font> CPDF_BAFontMap::AddFontToDocument(ByteString sFontName,
FX_Charset nCharset) {
- if (CFX_FontMapper::IsStandardFontName(sFontName))
+ if (CFX_FontMapper::IsStandardFontName(sFontName)) {
return AddStandardFont(sFontName);
+ }
return AddSystemFont(sFontName, nCharset);
}
RetainPtr<CPDF_Font> CPDF_BAFontMap::AddStandardFont(ByteString sFontName) {
auto* pPageData = CPDF_DocPageData::FromDocument(document_);
- if (sFontName == "ZapfDingbats")
+ if (sFontName == "ZapfDingbats") {
return pPageData->AddStandardFont(sFontName, nullptr);
+ }
static const CPDF_FontEncoding fe(FontEncoding::kWinAnsi);
return pPageData->AddStandardFont(sFontName, &fe);
@@ -422,11 +451,13 @@
RetainPtr<CPDF_Font> CPDF_BAFontMap::AddSystemFont(ByteString sFontName,
FX_Charset nCharset) {
- if (sFontName.IsEmpty())
+ if (sFontName.IsEmpty()) {
sFontName = GetNativeFontName(nCharset);
+ }
- if (nCharset == FX_Charset::kDefault)
+ if (nCharset == FX_Charset::kDefault) {
nCharset = GetNativeCharset();
+ }
return AddNativeTrueTypeFontToPDF(document_, sFontName, nCharset);
}
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp
index 1f1aea9..158da88 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.cpp
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -19,12 +19,14 @@
CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(
const CPDF_Bookmark& parent) const {
const CPDF_Dictionary* parent_dict = parent.GetDict();
- if (parent_dict)
+ if (parent_dict) {
return CPDF_Bookmark(parent_dict->GetDictFor("First"));
+ }
const CPDF_Dictionary* root = document_->GetRoot();
- if (!root)
+ if (!root) {
return CPDF_Bookmark();
+ }
RetainPtr<const CPDF_Dictionary> outlines = root->GetDictFor("Outlines");
return outlines ? CPDF_Bookmark(outlines->GetDictFor("First"))
@@ -34,8 +36,9 @@
CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(
const CPDF_Bookmark& bookmark) const {
const CPDF_Dictionary* dict = bookmark.GetDict();
- if (!dict)
+ if (!dict) {
return CPDF_Bookmark();
+ }
RetainPtr<const CPDF_Dictionary> next = dict->GetDictFor("Next");
return next != dict ? CPDF_Bookmark(std::move(next)) : CPDF_Bookmark();
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
index 1b4ee9f..382b75a 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -31,20 +31,24 @@
parser->SetCurrentPosition(0);
while (true) {
pBuf[buf_index++] = parser->GetCurrentPosition();
- if (buf_index == nParams)
+ if (buf_index == nParams) {
buf_index = 0;
+ }
buf_count++;
- if (buf_count > nParams)
+ if (buf_count > nParams) {
buf_count = nParams;
+ }
ByteStringView word = parser->GetWord();
- if (word.IsEmpty())
+ if (word.IsEmpty()) {
return false;
+ }
if (word == token) {
- if (buf_count < nParams)
+ if (buf_count < nParams) {
continue;
+ }
parser->SetCurrentPosition(pBuf[buf_index]);
return true;
@@ -108,8 +112,9 @@
std::optional<CFX_Color::TypeAndARGB> CPDF_DefaultAppearance::GetColorARGB()
const {
std::optional<CFX_Color> maybe_color = GetColor();
- if (!maybe_color.has_value())
+ if (!maybe_color.has_value()) {
return std::nullopt;
+ }
const CFX_Color& color = maybe_color.value();
if (color.nColorType == CFX_Color::Type::kGray) {
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index 4e1ab31..7da5be3 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -40,11 +40,13 @@
// static
CPDF_Dest CPDF_Dest::Create(CPDF_Document* pDoc,
RetainPtr<const CPDF_Object> pDest) {
- if (!pDest)
+ if (!pDest) {
return CPDF_Dest(nullptr);
+ }
- if (pDest->IsString() || pDest->IsName())
+ if (pDest->IsString() || pDest->IsName()) {
return CPDF_Dest(CPDF_NameTree::LookupNamedDest(pDoc, pDest->GetString()));
+ }
return CPDF_Dest(ToArray(pDest));
}
@@ -55,14 +57,17 @@
}
RetainPtr<const CPDF_Object> pPage = array_->GetDirectObjectAt(0);
- if (!pPage)
+ if (!pPage) {
return -1;
+ }
- if (pPage->IsNumber())
+ if (pPage->IsNumber()) {
return pPage->GetInteger();
+ }
- if (!pPage->IsDictionary())
+ if (!pPage->IsDictionary()) {
return -1;
+ }
return pDoc->GetPageIndex(pPage->GetObjNum());
}
@@ -115,8 +120,9 @@
}
RetainPtr<const CPDF_Name> xyz = ToName(array_->GetDirectObjectAt(1));
- if (!xyz || xyz->GetString() != "XYZ")
+ if (!xyz || xyz->GetString() != "XYZ") {
return false;
+ }
RetainPtr<const CPDF_Number> numX = ToNumber(array_->GetDirectObjectAt(2));
RetainPtr<const CPDF_Number> numY = ToNumber(array_->GetDirectObjectAt(3));
@@ -127,18 +133,21 @@
*pHasY = !!numY;
*pHasZoom = !!numZoom;
- if (numX)
+ if (numX) {
*pX = numX->GetNumber();
- if (numY)
+ }
+ if (numY) {
*pY = numY->GetNumber();
+ }
// A zoom value of 0 is equivalent to a null value, so treat it as a null.
if (numZoom) {
float num = numZoom->GetNumber();
- if (num == 0.0)
+ if (num == 0.0) {
*pHasZoom = false;
- else
+ } else {
*pZoom = num;
+ }
}
return true;
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index 8c96586..e3eca22 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -103,16 +103,19 @@
if (const CPDF_Dictionary* pDict = obj_->AsDictionary()) {
RetainPtr<const CPDF_String> pUF =
ToString(pDict->GetDirectObjectFor("UF"));
- if (pUF)
+ if (pUF) {
csFileName = pUF->GetUnicodeText();
+ }
if (csFileName.IsEmpty()) {
RetainPtr<const CPDF_String> pK =
ToString(pDict->GetDirectObjectFor(pdfium::stream::kF));
- if (pK)
+ if (pK) {
csFileName = WideString::FromDefANSI(pK->GetString().AsStringView());
+ }
}
- if (pDict->GetByteStringFor("FS") == "URL")
+ if (pDict->GetByteStringFor("FS") == "URL") {
return csFileName;
+ }
if (csFileName.IsEmpty()) {
for (const auto* key : {"DOS", "Mac", "Unix"}) {
@@ -133,13 +136,15 @@
RetainPtr<const CPDF_Stream> CPDF_FileSpec::GetFileStream() const {
const CPDF_Dictionary* pDict = obj_->AsDictionary();
- if (!pDict)
+ if (!pDict) {
return nullptr;
+ }
// Get the embedded files dictionary.
RetainPtr<const CPDF_Dictionary> pFiles = pDict->GetDictFor("EF");
- if (!pFiles)
+ if (!pFiles) {
return nullptr;
+ }
// List of keys to check for the file specification string.
// Follows the same precedence order as GetFileName().
@@ -150,8 +155,9 @@
ByteString key = kKeys[i];
if (!pDict->GetUnicodeTextFor(key).IsEmpty()) {
RetainPtr<const CPDF_Stream> pStream = pFiles->GetStreamFor(key);
- if (pStream)
+ if (pStream) {
return pStream;
+ }
}
}
return nullptr;
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index be6eca8..fb874ec 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -57,17 +57,20 @@
DCHECK(GetType() == CPDF_FormField::kCheckBox ||
GetType() == CPDF_FormField::kRadioButton);
RetainPtr<const CPDF_Dictionary> pAP = widget_dict_->GetDictFor("AP");
- if (!pAP)
+ if (!pAP) {
return ByteString();
+ }
RetainPtr<const CPDF_Dictionary> pN = pAP->GetDictFor("N");
- if (!pN)
+ if (!pN) {
return ByteString();
+ }
CPDF_DictionaryLocker locker(pN);
for (const auto& it : locker) {
- if (it.first != "Off")
+ if (it.first != "Off") {
return it.first;
+ }
}
return ByteString();
}
@@ -79,8 +82,9 @@
if (ToArray(field_->GetFieldAttr("Opt"))) {
csOn = ByteString::FormatInteger(field_->GetControlIndex(this));
}
- if (csOn.IsEmpty())
+ if (csOn.IsEmpty()) {
csOn = "Yes";
+ }
return csOn;
}
@@ -89,10 +93,12 @@
GetType() == CPDF_FormField::kRadioButton);
ByteString csOn = GetOnStateName();
RetainPtr<const CPDF_Array> pArray = ToArray(field_->GetFieldAttr("Opt"));
- if (pArray)
+ if (pArray) {
csOn = pArray->GetByteStringAt(field_->GetControlIndex(this));
- if (csOn.IsEmpty())
+ }
+ if (csOn.IsEmpty()) {
csOn = "Yes";
+ }
return PDF_DecodeText(csOn.unsigned_span());
}
@@ -108,8 +114,9 @@
DCHECK(GetType() == CPDF_FormField::kCheckBox ||
GetType() == CPDF_FormField::kRadioButton);
RetainPtr<const CPDF_Object> pDV = field_->GetFieldAttr("DV");
- if (!pDV)
+ if (!pDV) {
return false;
+ }
ByteString csDV = pDV->GetString();
ByteString csOn = GetOnStateName();
@@ -121,10 +128,12 @@
GetType() == CPDF_FormField::kRadioButton);
ByteString csOldAS = widget_dict_->GetByteStringFor("AS", "Off");
ByteString csAS = "Off";
- if (bChecked)
+ if (bChecked) {
csAS = GetOnStateName();
- if (csOldAS == csAS)
+ }
+ if (csOldAS == csAS) {
return;
+ }
widget_dict_->SetNewFor<CPDF_Name>("AS", csAS);
}
@@ -133,9 +142,9 @@
ByteString csH = widget_dict_->GetByteStringFor("H", "I");
for (size_t i = 0; i < std::size(kHighlightModes); ++i) {
// TODO(tsepez): disambiguate string ctors.
- if (csH == ByteStringView(kHighlightModes[i])) {
- return static_cast<HighlightingMode>(i);
- }
+ if (csH == ByteStringView(kHighlightModes[i])) {
+ return static_cast<HighlightingMode>(i);
+ }
}
return kInvert;
}
@@ -189,16 +198,18 @@
}
RetainPtr<const CPDF_Object> pObj =
field_->GetFieldAttr(pdfium::form_fields::kDA);
- if (pObj)
+ if (pObj) {
return CPDF_DefaultAppearance(pObj->GetString());
+ }
return form_->GetDefaultAppearance();
}
std::optional<WideString> CPDF_FormControl::GetDefaultControlFontName() const {
RetainPtr<CPDF_Font> pFont = GetDefaultControlFont();
- if (!pFont)
+ if (!pFont) {
return std::nullopt;
+ }
return WideString::FromDefANSI(pFont->GetBaseFontName().AsStringView());
}
@@ -207,8 +218,9 @@
float fFontSize;
CPDF_DefaultAppearance cDA = GetDefaultAppearance();
std::optional<ByteString> csFontNameTag = cDA.GetFont(&fFontSize);
- if (!csFontNameTag.has_value() || csFontNameTag->IsEmpty())
+ if (!csFontNameTag.has_value() || csFontNameTag->IsEmpty()) {
return nullptr;
+ }
RetainPtr<CPDF_Dictionary> pDRDict = ToDictionary(
CPDF_FormField::GetMutableFieldAttrForDict(widget_dict_.Get(), "DR"));
@@ -220,29 +232,34 @@
if (pElement) {
RetainPtr<CPDF_Font> pFont =
form_->GetFontForElement(std::move(pElement));
- if (pFont)
+ if (pFont) {
return pFont;
+ }
}
}
}
RetainPtr<CPDF_Font> pFormFont = form_->GetFormFont(csFontNameTag.value());
- if (pFormFont)
+ if (pFormFont) {
return pFormFont;
+ }
RetainPtr<CPDF_Dictionary> pPageDict = widget_dict_->GetMutableDictFor("P");
RetainPtr<CPDF_Dictionary> pDict = ToDictionary(
CPDF_FormField::GetMutableFieldAttrForDict(pPageDict.Get(), "Resources"));
- if (!pDict)
+ if (!pDict) {
return nullptr;
+ }
RetainPtr<CPDF_Dictionary> pFonts = pDict->GetMutableDictFor("Font");
- if (!ValidateFontResourceDict(pFonts.Get()))
+ if (!ValidateFontResourceDict(pFonts.Get())) {
return nullptr;
+ }
RetainPtr<CPDF_Dictionary> pElement =
pFonts->GetMutableDictFor(csFontNameTag.value());
- if (!pElement)
+ if (!pElement) {
return nullptr;
+ }
return form_->GetFontForElement(std::move(pElement));
}
@@ -254,8 +271,9 @@
RetainPtr<const CPDF_Object> pObj =
field_->GetFieldAttr(pdfium::form_fields::kQ);
- if (pObj)
+ if (pObj) {
return pObj->GetInteger();
+ }
return form_->GetFormAlignment();
}
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index fcf90ac..a9f6a5f 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -38,12 +38,14 @@
const ByteString& name,
int nLevel) {
static constexpr int kGetFieldMaxRecursion = 32;
- if (!pFieldDict || nLevel > kGetFieldMaxRecursion)
+ if (!pFieldDict || nLevel > kGetFieldMaxRecursion) {
return nullptr;
+ }
RetainPtr<const CPDF_Object> pAttr = pFieldDict->GetDirectObjectFor(name);
- if (pAttr)
+ if (pAttr) {
return pAttr;
+ }
return GetFieldAttrRecursive(
pFieldDict->GetDictFor(pdfium::form_fields::kParent).Get(), name,
@@ -96,14 +98,16 @@
visited.insert(pLevel);
WideString short_name = pLevel->GetUnicodeTextFor(pdfium::form_fields::kT);
if (!short_name.IsEmpty()) {
- if (full_name.IsEmpty())
+ if (full_name.IsEmpty()) {
full_name = std::move(short_name);
- else
+ } else {
full_name = short_name + L'.' + full_name;
+ }
}
pLevel = pLevel->GetDictFor(pdfium::form_fields::kParent).Get();
- if (pdfium::Contains(visited, pLevel))
+ if (pdfium::Contains(visited, pLevel)) {
break;
+ }
}
return full_name;
}
@@ -135,12 +139,13 @@
is_unison_ = true;
}
} else if (type_name == pdfium::form_fields::kTx) {
- if (flags & pdfium::form_flags::kTextFileSelect)
+ if (flags & pdfium::form_flags::kTextFileSelect) {
type_ = kFile;
- else if (flags & pdfium::form_flags::kTextRichText)
+ } else if (flags & pdfium::form_flags::kTextRichText) {
type_ = kRichText;
- else
+ } else {
type_ = kText;
+ }
} else if (type_name == pdfium::form_fields::kCh) {
if (flags & pdfium::form_flags::kChoiceCombo) {
type_ = kComboBox;
@@ -187,8 +192,9 @@
ClearSelection(NotificationOption::kDoNotNotify);
WideString csValue;
int iIndex = GetDefaultSelectedItem();
- if (iIndex >= 0)
+ if (iIndex >= 0) {
csValue = GetOptionLabel(iIndex);
+ }
if (!NotifyListOrComboBoxBeforeChange(csValue)) {
return;
}
@@ -206,17 +212,20 @@
// Limit scope of |pDV| and |pV| because they may get invalidated
// during notification below.
RetainPtr<const CPDF_Object> pDV = GetDefaultValueObject();
- if (pDV)
+ if (pDV) {
csDValue = pDV->GetUnicodeText();
+ }
RetainPtr<const CPDF_Object> pV = GetValueObject();
- if (pV)
+ if (pV) {
csValue = pV->GetUnicodeText();
+ }
}
bool bHasRV = !!GetFieldAttrInternal(pdfium::form_fields::kRV);
- if (!bHasRV && (csDValue == csValue))
+ if (!bHasRV && (csDValue == csValue)) {
return;
+ }
if (!form_->NotifyBeforeValueChange(this, csDValue)) {
return;
@@ -228,8 +237,9 @@
RetainPtr<const CPDF_Object> pDV = GetDefaultValueObject();
if (pDV) {
RetainPtr<CPDF_Object> pClone = pDV->Clone();
- if (!pClone)
+ if (!pClone) {
return;
+ }
dict_->SetFor(pdfium::form_fields::kV, std::move(pClone));
if (bHasRV) {
@@ -255,13 +265,15 @@
}
int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
- if (!pControl)
+ if (!pControl) {
return -1;
+ }
const auto& controls = GetControls();
auto it = std::find(controls.begin(), controls.end(), pControl);
- if (it == controls.end())
+ if (it == controls.end()) {
return -1;
+ }
return pdfium::checked_cast<int>(it - controls.begin());
}
@@ -319,8 +331,9 @@
}
WideString CPDF_FormField::GetValue(bool bDefault) const {
- if (GetType() == kCheckBox || GetType() == kRadioButton)
+ if (GetType() == kCheckBox || GetType() == kRadioButton) {
return GetCheckValue(bDefault);
+ }
RetainPtr<const CPDF_Object> pValue =
bDefault ? GetDefaultValueObject() : GetValueObject();
@@ -328,8 +341,9 @@
if (!bDefault && type_ != kText) {
pValue = GetDefaultValueObject();
}
- if (!pValue)
+ if (!pValue) {
return WideString();
+ }
}
switch (pValue->GetType()) {
@@ -339,8 +353,9 @@
case CPDF_Object::kArray: {
RetainPtr<const CPDF_Object> pNewValue =
pValue->AsArray()->GetDirectObjectAt(0);
- if (pNewValue)
+ if (pNewValue) {
return pNewValue->GetUnicodeText();
+ }
break;
}
default:
@@ -397,17 +412,20 @@
SetItemSelection(iIndex, NotificationOption::kDoNotNotify);
}
}
- if (notify == NotificationOption::kNotify)
+ if (notify == NotificationOption::kNotify) {
form_->NotifyAfterValueChange(this);
+ }
break;
}
case kListBox: {
int iIndex = FindOption(value);
- if (iIndex < 0)
+ if (iIndex < 0) {
return false;
+ }
- if (bDefault && iIndex == GetDefaultSelectedItem())
+ if (bDefault && iIndex == GetDefaultSelectedItem()) {
return false;
+ }
if (notify == NotificationOption::kNotify &&
!form_->NotifyBeforeSelectionChange(this, value)) {
@@ -417,8 +435,9 @@
ClearSelection(NotificationOption::kDoNotNotify);
SetItemSelection(iIndex, NotificationOption::kDoNotNotify);
}
- if (notify == NotificationOption::kNotify)
+ if (notify == NotificationOption::kNotify) {
form_->NotifyAfterSelectionChange(this);
+ }
break;
}
default:
@@ -434,48 +453,57 @@
int CPDF_FormField::GetMaxLen() const {
RetainPtr<const CPDF_Object> pObj = GetFieldAttrInternal("MaxLen");
- if (pObj)
+ if (pObj) {
return pObj->GetInteger();
+ }
for (auto& pControl : GetControls()) {
- if (!pControl)
+ if (!pControl) {
continue;
+ }
RetainPtr<const CPDF_Dictionary> pWidgetDict = pControl->GetWidgetDict();
- if (pWidgetDict->KeyExist("MaxLen"))
+ if (pWidgetDict->KeyExist("MaxLen")) {
return pWidgetDict->GetIntegerFor("MaxLen");
+ }
}
return 0;
}
int CPDF_FormField::CountSelectedItems() const {
const CPDF_Object* pValue = GetValueOrSelectedIndicesObject();
- if (!pValue)
+ if (!pValue) {
return 0;
+ }
- if (pValue->IsString() || pValue->IsNumber())
+ if (pValue->IsString() || pValue->IsNumber()) {
return pValue->GetString().IsEmpty() ? 0 : 1;
+ }
const CPDF_Array* pArray = pValue->AsArray();
return pArray ? fxcrt::CollectionSize<int>(*pArray) : 0;
}
int CPDF_FormField::GetSelectedIndex(int index) const {
const CPDF_Object* pValue = GetValueOrSelectedIndicesObject();
- if (!pValue)
+ if (!pValue) {
return -1;
+ }
- if (pValue->IsNumber())
+ if (pValue->IsNumber()) {
return pValue->GetInteger();
+ }
WideString sel_value;
if (pValue->IsString()) {
- if (index != 0)
+ if (index != 0) {
return -1;
+ }
sel_value = pValue->GetUnicodeText();
} else {
const CPDF_Array* pArray = pValue->AsArray();
- if (!pArray || index < 0)
+ if (!pArray || index < 0) {
return -1;
+ }
RetainPtr<const CPDF_Object> elementValue =
pArray->GetDirectObjectAt(index);
@@ -484,12 +512,14 @@
if (index < CountSelectedOptions()) {
int iOptIndex = GetSelectedOptionIndex(index);
WideString csOpt = GetOptionValue(iOptIndex);
- if (csOpt == sel_value)
+ if (csOpt == sel_value) {
return iOptIndex;
+ }
}
for (int i = 0; i < CountOptions(); i++) {
- if (sel_value == GetOptionValue(i))
+ if (sel_value == GetOptionValue(i)) {
return i;
+ }
}
return -1;
}
@@ -498,15 +528,18 @@
if (notify == NotificationOption::kNotify) {
WideString csValue;
int iIndex = GetSelectedIndex(0);
- if (iIndex >= 0)
+ if (iIndex >= 0) {
csValue = GetOptionLabel(iIndex);
- if (!NotifyListOrComboBoxBeforeChange(csValue))
+ }
+ if (!NotifyListOrComboBoxBeforeChange(csValue)) {
return false;
+ }
}
dict_->RemoveFor(pdfium::form_fields::kV);
dict_->RemoveFor("I");
- if (notify == NotificationOption::kNotify)
+ if (notify == NotificationOption::kNotify) {
NotifyListOrComboBoxAfterChange();
+ }
return true;
}
@@ -539,8 +572,9 @@
use_selected_indices_ = UseSelectedIndicesObject();
}
- if (notify == NotificationOption::kNotify)
+ if (notify == NotificationOption::kNotify) {
NotifyListOrComboBoxAfterChange();
+ }
}
void CPDF_FormField::SetItemSelectionSelected(int index,
@@ -562,22 +596,26 @@
auto pArray = dict_->SetNewFor<CPDF_Array>(pdfium::form_fields::kV);
for (int i = 0; i < CountOptions(); i++) {
- if (i == index || IsItemSelected(i))
+ if (i == index || IsItemSelected(i)) {
pArray->AppendNew<CPDF_String>(GetOptionValue(i).AsStringView());
+ }
}
}
int CPDF_FormField::GetDefaultSelectedItem() const {
CHECK(IsComboOrListField(GetType()));
RetainPtr<const CPDF_Object> pValue = GetDefaultValueObject();
- if (!pValue)
+ if (!pValue) {
return -1;
+ }
WideString csDV = pValue->GetUnicodeText();
- if (csDV.IsEmpty())
+ if (csDV.IsEmpty()) {
return -1;
+ }
for (int i = 0; i < CountOptions(); i++) {
- if (csDV == GetOptionValue(i))
+ if (csDV == GetOptionValue(i)) {
return i;
+ }
}
return -1;
}
@@ -603,19 +641,23 @@
WideString CPDF_FormField::GetOptionText(int index, int sub_index) const {
CHECK(HasOptField());
RetainPtr<const CPDF_Array> pArray = ToArray(GetFieldAttrInternal("Opt"));
- if (!pArray)
+ if (!pArray) {
return WideString();
+ }
RetainPtr<const CPDF_Object> pOption = pArray->GetDirectObjectAt(index);
- if (!pOption)
+ if (!pOption) {
return WideString();
+ }
const CPDF_Array* pOptionArray = pOption->AsArray();
- if (pOptionArray)
+ if (pOptionArray) {
pOption = pOptionArray->GetDirectObjectAt(sub_index);
+ }
- if (!pOption)
+ if (!pOption) {
return WideString();
+ }
const CPDF_String* pString = pOption->AsString();
return pString ? pString->GetUnicodeText() : WideString();
@@ -631,8 +673,9 @@
int CPDF_FormField::FindOption(const WideString& csOptValue) const {
for (int i = 0; i < CountOptions(); i++) {
- if (GetOptionValue(i) == csOptValue)
+ if (GetOptionValue(i) == csOptValue) {
return i;
+ }
}
return -1;
}
@@ -655,18 +698,20 @@
if (is_unison_) {
WideString csEValue = pCtrl->GetExportValue();
if (csEValue == csWExport) {
- if (pCtrl->GetOnStateName() == pControl->GetOnStateName())
+ if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) {
pCtrl->CheckControl(bChecked);
- else if (bChecked)
+ } else if (bChecked) {
pCtrl->CheckControl(false);
+ }
} else if (bChecked) {
pCtrl->CheckControl(false);
}
} else {
- if (i == iControlIndex)
+ if (i == iControlIndex) {
pCtrl->CheckControl(bChecked);
- else if (bChecked)
+ } else if (bChecked) {
pCtrl->CheckControl(false);
+ }
}
}
@@ -678,17 +723,20 @@
} else {
ByteString csV;
const CPDF_Object* pV = GetValueObject();
- if (pV)
+ if (pV) {
csV = pV->GetString();
- if (csV == csBExport)
+ }
+ if (csV == csBExport) {
dict_->SetNewFor<CPDF_Name>(pdfium::form_fields::kV, "Off");
+ }
}
} else if (bChecked) {
dict_->SetNewFor<CPDF_Name>(pdfium::form_fields::kV,
ByteString::FormatInteger(iControlIndex));
}
- if (notify == NotificationOption::kNotify)
+ if (notify == NotificationOption::kNotify) {
form_->NotifyAfterCheckedStatusChange(this);
+ }
}
WideString CPDF_FormField::GetCheckValue(bool bDefault) const {
@@ -720,11 +768,13 @@
CheckControl(GetControlIndex(pControl), val,
NotificationOption::kDoNotNotify);
}
- if (val)
+ if (val) {
break;
+ }
}
- if (notify == NotificationOption::kNotify)
+ if (notify == NotificationOption::kNotify) {
form_->NotifyAfterCheckedStatusChange(this);
+ }
return true;
}
@@ -739,12 +789,14 @@
}
int CPDF_FormField::GetSelectedOptionIndex(int index) const {
- if (index < 0)
+ if (index < 0) {
return 0;
+ }
RetainPtr<const CPDF_Array> pArray = ToArray(GetSelectedIndicesObject());
- if (!pArray)
+ if (!pArray) {
return -1;
+ }
return index < fxcrt::CollectionSize<int>(*pArray)
? pArray->GetIntegerAt(index)
@@ -753,15 +805,17 @@
bool CPDF_FormField::IsSelectedOption(const WideString& wsOptValue) const {
RetainPtr<const CPDF_Object> pValueObject = GetValueObject();
- if (!pValueObject)
+ if (!pValueObject) {
return false;
+ }
const CPDF_Array* pValueArray = pValueObject->AsArray();
if (pValueArray) {
CPDF_ArrayLocker locker(pValueArray);
for (const auto& pObj : locker) {
- if (pObj->IsString() && pObj->GetUnicodeText() == wsOptValue)
+ if (pObj->IsString() && pObj->GetUnicodeText() == wsOptValue) {
return true;
+ }
}
}
@@ -772,15 +826,17 @@
bool CPDF_FormField::IsSelectedIndex(int iOptIndex) const {
RetainPtr<const CPDF_Object> pSelectedIndicesObject =
GetSelectedIndicesObject();
- if (!pSelectedIndicesObject)
+ if (!pSelectedIndicesObject) {
return false;
+ }
const CPDF_Array* pSelectedIndicesArray = pSelectedIndicesObject->AsArray();
if (pSelectedIndicesArray) {
CPDF_ArrayLocker locker(pSelectedIndicesArray);
for (const auto& pObj : locker) {
- if (pObj->IsNumber() && pObj->GetInteger() == iOptIndex)
+ if (pObj->IsNumber() && pObj->GetInteger() == iOptIndex) {
return true;
+ }
}
}
@@ -792,8 +848,9 @@
RetainPtr<CPDF_Array> pArray = dict_->GetOrCreateArrayFor("I");
for (size_t i = 0; i < pArray->size(); i++) {
int iFind = pArray->GetIntegerAt(i);
- if (iFind == iOptIndex)
+ if (iFind == iOptIndex) {
return;
+ }
if (iFind > iOptIndex) {
pArray->InsertNewAt<CPDF_Number>(i, iOptIndex);
@@ -808,24 +865,27 @@
RetainPtr<const CPDF_Object> pSelectedIndicesObject =
GetSelectedIndicesObject();
- if (!pSelectedIndicesObject)
+ if (!pSelectedIndicesObject) {
return false;
+ }
// If there's not value object, then just use the indices object.
RetainPtr<const CPDF_Object> pValueObject = GetValueObject();
- if (!pValueObject)
+ if (!pValueObject) {
return true;
+ }
// Verify that the selected indices object is either an array or a number and
// count the number of indices.
size_t selected_indices_size;
const CPDF_Array* pSelectedIndicesArray = pSelectedIndicesObject->AsArray();
- if (pSelectedIndicesArray)
+ if (pSelectedIndicesArray) {
selected_indices_size = pSelectedIndicesArray->size();
- else if (pSelectedIndicesObject->IsNumber())
+ } else if (pSelectedIndicesObject->IsNumber()) {
selected_indices_size = 1;
- else
+ } else {
return false;
+ }
// Verify that the number of values is equal to |selected_indices_size|. Then,
// count the number of occurrences of each of the distinct values in the
@@ -833,16 +893,19 @@
std::map<WideString, size_t> values;
const CPDF_Array* pValueArray = pValueObject->AsArray();
if (pValueArray) {
- if (pValueArray->size() != selected_indices_size)
+ if (pValueArray->size() != selected_indices_size) {
return false;
+ }
CPDF_ArrayLocker locker(pValueArray);
for (const auto& pObj : locker) {
- if (pObj->IsString())
+ if (pObj->IsString()) {
values[pObj->GetUnicodeText()]++;
+ }
}
} else if (pValueObject->IsString()) {
- if (selected_indices_size != 1)
+ if (selected_indices_size != 1) {
return false;
+ }
values[pValueObject->GetUnicodeText()]++;
}
@@ -853,21 +916,25 @@
if (pSelectedIndicesArray) {
CPDF_ArrayLocker locker(pSelectedIndicesArray);
for (const auto& pObj : locker) {
- if (!pObj->IsNumber())
+ if (!pObj->IsNumber()) {
return false;
+ }
int index = pObj->GetInteger();
- if (index < 0 || index >= num_options)
+ if (index < 0 || index >= num_options) {
return false;
+ }
WideString wsOptValue = GetOptionValue(index);
auto it = values.find(wsOptValue);
- if (it == values.end())
+ if (it == values.end()) {
return false;
+ }
it->second--;
- if (it->second == 0)
+ if (it->second == 0) {
values.erase(it);
+ }
}
return values.empty();
@@ -875,8 +942,9 @@
DCHECK(pSelectedIndicesObject->IsNumber());
int index = pSelectedIndicesObject->GetInteger();
- if (index < 0 || index >= num_options)
+ if (index < 0 || index >= num_options) {
return false;
+ }
return pdfium::Contains(values, GetOptionValue(index));
}
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index 7cadb2b..d190d60 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -1394,10 +1394,11 @@
}
float remainder = rect.right - (x - kDelta);
- if (isUpwards)
+ if (isUpwards) {
app_stream << rect.right << " " << bottom + remainder << " l ";
- else
+ } else {
app_stream << rect.right << " " << top - remainder << " l ";
+ }
app_stream << "S\n";
}
diff --git a/core/fpdfdoc/cpdf_iconfit.cpp b/core/fpdfdoc/cpdf_iconfit.cpp
index 7d6a157..79acd75 100644
--- a/core/fpdfdoc/cpdf_iconfit.cpp
+++ b/core/fpdfdoc/cpdf_iconfit.cpp
@@ -32,12 +32,15 @@
}
ByteString csSW = dict_->GetByteStringFor("SW", "A");
- if (csSW == "B")
+ if (csSW == "B") {
return ScaleMethod::kBigger;
- if (csSW == "S")
+ }
+ if (csSW == "S") {
return ScaleMethod::kSmaller;
- if (csSW == "N")
+ }
+ if (csSW == "N") {
return ScaleMethod::kNever;
+ }
return ScaleMethod::kAlways;
}
@@ -53,14 +56,17 @@
}
RetainPtr<const CPDF_Array> pA = dict_->GetArrayFor("A");
- if (!pA)
+ if (!pA) {
return {fLeft, fBottom};
+ }
size_t dwCount = pA->size();
- if (dwCount > 0)
+ if (dwCount > 0) {
fLeft = pA->GetFloatAt(0);
- if (dwCount > 1)
+ }
+ if (dwCount > 1) {
fBottom = pA->GetFloatAt(1);
+ }
return {fLeft, fBottom};
}
@@ -74,8 +80,9 @@
}
RetainPtr<const CPDF_Array> pA = dict_->GetArrayFor("A");
- if (!pA)
+ if (!pA) {
return CFX_PointF();
+ }
size_t dwCount = pA->size();
return {dwCount > 0 ? pA->GetFloatAt(0) : 0.0f,
@@ -96,16 +103,20 @@
fVScale = fPlateHeight / std::max(fImageHeight, 1.0f);
break;
case CPDF_IconFit::ScaleMethod::kBigger:
- if (fPlateWidth < fImageWidth)
+ if (fPlateWidth < fImageWidth) {
fHScale = fPlateWidth / std::max(fImageWidth, 1.0f);
- if (fPlateHeight < fImageHeight)
+ }
+ if (fPlateHeight < fImageHeight) {
fVScale = fPlateHeight / std::max(fImageHeight, 1.0f);
+ }
break;
case CPDF_IconFit::ScaleMethod::kSmaller:
- if (fPlateWidth > fImageWidth)
+ if (fPlateWidth > fImageWidth) {
fHScale = fPlateWidth / std::max(fImageWidth, 1.0f);
- if (fPlateHeight > fImageHeight)
+ }
+ if (fPlateHeight > fImageHeight) {
fVScale = fPlateHeight / std::max(fImageHeight, 1.0f);
+ }
break;
case CPDF_IconFit::ScaleMethod::kNever:
break;
diff --git a/core/fpdfdoc/cpdf_linklist.cpp b/core/fpdfdoc/cpdf_linklist.cpp
index 7db8d8e..c80270e 100644
--- a/core/fpdfdoc/cpdf_linklist.cpp
+++ b/core/fpdfdoc/cpdf_linklist.cpp
@@ -22,21 +22,25 @@
int* z_order) {
const std::vector<RetainPtr<CPDF_Dictionary>>* pPageLinkList =
GetPageLinks(pPage);
- if (!pPageLinkList)
+ if (!pPageLinkList) {
return CPDF_Link();
+ }
for (size_t i = pPageLinkList->size(); i > 0; --i) {
size_t annot_index = i - 1;
RetainPtr<CPDF_Dictionary> pAnnot = (*pPageLinkList)[annot_index];
- if (!pAnnot)
+ if (!pAnnot) {
continue;
+ }
CPDF_Link link(std::move(pAnnot));
- if (!link.GetRect().Contains(point))
+ if (!link.GetRect().Contains(point)) {
continue;
+ }
- if (z_order)
+ if (z_order) {
*z_order = pdfium::checked_cast<int32_t>(annot_index);
+ }
return link;
}
return CPDF_Link();
@@ -45,8 +49,9 @@
const std::vector<RetainPtr<CPDF_Dictionary>>* CPDF_LinkList::GetPageLinks(
CPDF_Page* pPage) {
uint32_t objnum = pPage->GetDict()->GetObjNum();
- if (objnum == 0)
+ if (objnum == 0) {
return nullptr;
+ }
auto it = page_map_.find(objnum);
if (it != page_map_.end()) {
@@ -56,8 +61,9 @@
// std::map::operator[] forces the creation of a map entry.
auto* page_link_list = &page_map_[objnum];
RetainPtr<CPDF_Array> pAnnotList = pPage->GetMutableAnnotsArray();
- if (!pAnnotList)
+ if (!pAnnotList) {
return page_link_list;
+ }
for (size_t i = 0; i < pAnnotList->size(); ++i) {
RetainPtr<CPDF_Dictionary> pAnnot = pAnnotList->GetMutableDictAt(i);
diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp
index 6a2a51c..42393cc 100644
--- a/core/fpdfdoc/cpdf_metadata.cpp
+++ b/core/fpdfdoc/cpdf_metadata.cpp
@@ -34,12 +34,14 @@
if (attr.EqualsASCII("http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/")) {
for (const auto* child = element->GetFirstChild(); child;
child = child->GetNextSibling()) {
- if (child->GetType() != CFX_XMLNode::Type::kElement)
+ if (child->GetType() != CFX_XMLNode::Type::kElement) {
continue;
+ }
const auto* child_elem = static_cast<const CFX_XMLElement*>(child);
- if (!child_elem->GetName().EqualsASCII("adhocwf:workflowType"))
+ if (!child_elem->GetName().EqualsASCII("adhocwf:workflowType")) {
continue;
+ }
switch (child_elem->GetTextData().GetInteger()) {
case 0:
@@ -86,8 +88,9 @@
auto stream = pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pAcc->GetSpan());
CFX_XMLParser parser(stream);
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
- if (!doc)
+ if (!doc) {
return {};
+ }
std::vector<UnsupportedFeature> unsupported;
CheckForSharedFormInternal(/*depth=*/0, doc->GetRoot(), &unsupported);
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index 3865dd1..ae6a250 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -42,8 +42,9 @@
csLeft = pLimits->GetUnicodeTextAt(0);
csRight = pLimits->GetUnicodeTextAt(1);
}
- while (pLimits->size() > 2)
+ while (pLimits->size() > 2) {
pLimits->RemoveAt(pLimits->size() - 1);
+ }
return {csLeft, csRight};
}
@@ -54,8 +55,9 @@
const CPDF_Array* pFind,
int nLevel,
std::vector<CPDF_Array*>* pLimits) {
- if (nLevel > kNameTreeMaxRecursion)
+ if (nLevel > kNameTreeMaxRecursion) {
return false;
+ }
if (pNode->GetArrayFor("Names") == pFind) {
pLimits->push_back(pNode->GetMutableArrayFor("Limits").Get());
@@ -63,13 +65,15 @@
}
RetainPtr<CPDF_Array> pKids = pNode->GetMutableArrayFor("Kids");
- if (!pKids)
+ if (!pKids) {
return false;
+ }
for (size_t i = 0; i < pKids->size(); ++i) {
RetainPtr<CPDF_Dictionary> pKid = pKids->GetMutableDictAt(i);
- if (!pKid)
+ if (!pKid) {
continue;
+ }
if (GetNodeAncestorsLimitsInternal(pKid, pFind, nLevel + 1, pLimits)) {
pLimits->push_back(pNode->GetMutableArrayFor("Limits").Get());
@@ -96,23 +100,28 @@
const CPDF_Array* pFind,
const WideString& csName,
int nLevel) {
- if (nLevel > kNameTreeMaxRecursion)
+ if (nLevel > kNameTreeMaxRecursion) {
return false;
+ }
RetainPtr<CPDF_Array> pLimits = pNode->GetMutableArrayFor("Limits");
WideString csLeft;
WideString csRight;
- if (pLimits)
+ if (pLimits) {
std::tie(csLeft, csRight) = GetNodeLimitsAndSanitize(pLimits.Get());
+ }
RetainPtr<const CPDF_Array> pNames = pNode->GetArrayFor("Names");
if (pNames) {
- if (pNames != pFind)
+ if (pNames != pFind) {
return false;
- if (pNames->IsEmpty() || !pLimits)
+ }
+ if (pNames->IsEmpty() || !pLimits) {
return true;
- if (csLeft != csName && csRight != csName)
+ }
+ if (csLeft != csName && csRight != csName) {
return true;
+ }
// Since |csName| defines |pNode|'s limits, we need to loop through the
// names to find the new lower and upper limits.
@@ -120,10 +129,12 @@
WideString csNewRight = csLeft;
for (size_t i = 0; i < pNames->size() / 2; ++i) {
WideString wsName = pNames->GetUnicodeTextAt(i * 2);
- if (wsName.Compare(csNewLeft) < 0)
+ if (wsName.Compare(csNewLeft) < 0) {
csNewLeft = wsName;
- if (wsName.Compare(csNewRight) > 0)
+ }
+ if (wsName.Compare(csNewRight) > 0) {
csNewRight = wsName;
+ }
}
pLimits->SetNewAt<CPDF_String>(0, csNewLeft.AsStringView());
pLimits->SetNewAt<CPDF_String>(1, csNewRight.AsStringView());
@@ -131,14 +142,16 @@
}
RetainPtr<CPDF_Array> pKids = pNode->GetMutableArrayFor("Kids");
- if (!pKids)
+ if (!pKids) {
return false;
+ }
// Loop through the kids to find the leaf array |pFind|.
for (size_t i = 0; i < pKids->size(); ++i) {
RetainPtr<CPDF_Dictionary> pKid = pKids->GetMutableDictAt(i);
- if (!pKid)
+ if (!pKid) {
continue;
+ }
if (!UpdateNodesAndLimitsUponDeletion(pKid.Get(), pFind, csName,
nLevel + 1)) {
continue;
@@ -148,10 +161,12 @@
(pKid->KeyExist("Kids") && pKid->GetArrayFor("Kids")->IsEmpty())) {
pKids->RemoveAt(i);
}
- if (pKids->IsEmpty() || !pLimits)
+ if (pKids->IsEmpty() || !pLimits) {
return true;
- if (csLeft != csName && csRight != csName)
+ }
+ if (csLeft != csName && csRight != csName) {
return true;
+ }
// Since |csName| defines |pNode|'s limits, we need to loop through the
// kids to find the new lower and upper limits.
@@ -161,10 +176,12 @@
RetainPtr<const CPDF_Array> pKidLimits =
pKids->GetDictAt(j)->GetArrayFor("Limits");
DCHECK(pKidLimits);
- if (pKidLimits->GetUnicodeTextAt(0).Compare(csNewLeft) < 0)
+ if (pKidLimits->GetUnicodeTextAt(0).Compare(csNewLeft) < 0) {
csNewLeft = pKidLimits->GetUnicodeTextAt(0);
- if (pKidLimits->GetUnicodeTextAt(1).Compare(csNewRight) > 0)
+ }
+ if (pKidLimits->GetUnicodeTextAt(1).Compare(csNewRight) > 0) {
csNewRight = pKidLimits->GetUnicodeTextAt(1);
+ }
}
pLimits->SetNewAt<CPDF_String>(0, csNewLeft.AsStringView());
pLimits->SetNewAt<CPDF_String>(1, csNewRight.AsStringView());
@@ -176,8 +193,9 @@
bool IsTraversedObject(const CPDF_Object* obj,
std::set<uint32_t>* seen_obj_nums) {
uint32_t obj_num = obj->GetObjNum();
- if (!obj_num)
+ if (!obj_num) {
return false;
+ }
bool inserted = seen_obj_nums->insert(obj_num).second;
return !inserted;
@@ -185,13 +203,15 @@
bool IsArrayWithTraversedObject(const CPDF_Array* array,
std::set<uint32_t>* seen_obj_nums) {
- if (IsTraversedObject(array, seen_obj_nums))
+ if (IsTraversedObject(array, seen_obj_nums)) {
return true;
+ }
CPDF_ArrayLocker locker(array);
for (const auto& item : locker) {
- if (IsTraversedObject(item.Get(), seen_obj_nums))
+ if (IsTraversedObject(item.Get(), seen_obj_nums)) {
return true;
+ }
}
return false;
}
@@ -208,15 +228,18 @@
size_t* nIndex,
NodeToInsert* node_to_insert,
std::set<uint32_t>* seen_obj_nums) {
- if (nLevel > kNameTreeMaxRecursion)
+ if (nLevel > kNameTreeMaxRecursion) {
return nullptr;
+ }
RetainPtr<CPDF_Array> pLimits = pNode->GetMutableArrayFor("Limits");
RetainPtr<CPDF_Array> pNames = pNode->GetMutableArrayFor("Names");
- if (pNames && IsArrayWithTraversedObject(pNames.Get(), seen_obj_nums))
+ if (pNames && IsArrayWithTraversedObject(pNames.Get(), seen_obj_nums)) {
pNames.Reset();
- if (pLimits && IsArrayWithTraversedObject(pLimits.Get(), seen_obj_nums))
+ }
+ if (pLimits && IsArrayWithTraversedObject(pLimits.Get(), seen_obj_nums)) {
pLimits.Reset();
+ }
if (pLimits) {
auto [csLeft, csRight] = GetNodeLimitsAndSanitize(pLimits.Get());
@@ -248,14 +271,16 @@
for (size_t i = 0; i < dwCount; i++) {
WideString csValue = pNames->GetUnicodeTextAt(i * 2);
int32_t iCompare = csValue.Compare(csName);
- if (iCompare > 0)
+ if (iCompare > 0) {
break;
+ }
if (node_to_insert) {
node_to_insert->names = pNames;
node_to_insert->index = pdfium::checked_cast<int32_t>(i);
}
- if (iCompare < 0)
+ if (iCompare < 0) {
continue;
+ }
*nIndex += i;
return pNames->GetDirectObjectAt(i * 2 + 1);
@@ -266,18 +291,21 @@
// Search through the node's children.
RetainPtr<CPDF_Array> pKids = pNode->GetMutableArrayFor("Kids");
- if (!pKids || IsTraversedObject(pKids.Get(), seen_obj_nums))
+ if (!pKids || IsTraversedObject(pKids.Get(), seen_obj_nums)) {
return nullptr;
+ }
for (size_t i = 0; i < pKids->size(); i++) {
RetainPtr<CPDF_Dictionary> pKid = pKids->GetMutableDictAt(i);
- if (!pKid || IsTraversedObject(pKid.Get(), seen_obj_nums))
+ if (!pKid || IsTraversedObject(pKid.Get(), seen_obj_nums)) {
continue;
+ }
RetainPtr<const CPDF_Object> pFound = SearchNameNodeByNameInternal(
pKid, csName, nLevel + 1, nIndex, node_to_insert, seen_obj_nums);
- if (pFound)
+ if (pFound) {
return pFound;
+ }
}
return nullptr;
}
@@ -312,8 +340,9 @@
size_t nTargetPairIndex,
int nLevel,
size_t* nCurPairIndex) {
- if (nLevel > kNameTreeMaxRecursion)
+ if (nLevel > kNameTreeMaxRecursion) {
return std::nullopt;
+ }
RetainPtr<CPDF_Array> pNames = pNode->GetMutableArrayFor("Names");
if (pNames) {
@@ -325,8 +354,9 @@
size_t index = 2 * (nTargetPairIndex - *nCurPairIndex);
RetainPtr<CPDF_Object> value = pNames->GetMutableDirectObjectAt(index + 1);
- if (!value)
+ if (!value) {
return std::nullopt;
+ }
IndexSearchResult result;
result.key = pNames->GetUnicodeTextAt(index);
@@ -337,17 +367,20 @@
}
RetainPtr<CPDF_Array> pKids = pNode->GetMutableArrayFor("Kids");
- if (!pKids)
+ if (!pKids) {
return std::nullopt;
+ }
for (size_t i = 0; i < pKids->size(); i++) {
RetainPtr<CPDF_Dictionary> pKid = pKids->GetMutableDictAt(i);
- if (!pKid)
+ if (!pKid) {
continue;
+ }
std::optional<IndexSearchResult> result = SearchNameNodeByIndexInternal(
pKid.Get(), nTargetPairIndex, nLevel + 1, nCurPairIndex);
- if (result.has_value())
+ if (result.has_value()) {
return result;
+ }
}
return std::nullopt;
}
@@ -366,26 +399,31 @@
size_t CountNamesInternal(const CPDF_Dictionary* pNode,
int nLevel,
std::set<const CPDF_Dictionary*>& seen) {
- if (nLevel > kNameTreeMaxRecursion)
+ if (nLevel > kNameTreeMaxRecursion) {
return 0;
+ }
const bool inserted = seen.insert(pNode).second;
- if (!inserted)
+ if (!inserted) {
return 0;
+ }
RetainPtr<const CPDF_Array> pNames = pNode->GetArrayFor("Names");
- if (pNames)
+ if (pNames) {
return pNames->size() / 2;
+ }
RetainPtr<const CPDF_Array> pKids = pNode->GetArrayFor("Kids");
- if (!pKids)
+ if (!pKids) {
return 0;
+ }
size_t nCount = 0;
for (size_t i = 0; i < pKids->size(); i++) {
RetainPtr<const CPDF_Dictionary> pKid = pKids->GetDictAt(i);
- if (!pKid)
+ if (!pKid) {
continue;
+ }
nCount += CountNamesInternal(pKid.Get(), nLevel + 1, seen);
}
@@ -395,11 +433,13 @@
RetainPtr<const CPDF_Array> GetNamedDestFromObject(
RetainPtr<const CPDF_Object> obj) {
RetainPtr<const CPDF_Array> array = ToArray(obj);
- if (array)
+ if (array) {
return array;
+ }
RetainPtr<const CPDF_Dictionary> dict = ToDictionary(obj);
- if (dict)
+ if (dict) {
return dict->GetArrayFor("D");
+ }
return nullptr;
}
@@ -407,8 +447,9 @@
const ByteString& name) {
RetainPtr<const CPDF_Dictionary> pDests =
pDoc->GetRoot()->GetDictFor("Dests");
- if (!pDests)
+ if (!pDests) {
return nullptr;
+ }
return GetNamedDestFromObject(pDests->GetDirectObjectFor(name));
}
@@ -426,16 +467,19 @@
CPDF_Document* pDoc,
const ByteString& category) {
RetainPtr<CPDF_Dictionary> pRoot = pDoc->GetMutableRoot();
- if (!pRoot)
+ if (!pRoot) {
return nullptr;
+ }
RetainPtr<CPDF_Dictionary> pNames = pRoot->GetMutableDictFor("Names");
- if (!pNames)
+ if (!pNames) {
return nullptr;
+ }
RetainPtr<CPDF_Dictionary> pCategory = pNames->GetMutableDictFor(category);
- if (!pCategory)
+ if (!pCategory) {
return nullptr;
+ }
return pdfium::WrapUnique(
new CPDF_NameTree(std::move(pCategory))); // Private ctor.
@@ -446,8 +490,9 @@
CPDF_Document* pDoc,
const ByteString& category) {
RetainPtr<CPDF_Dictionary> pRoot = pDoc->GetMutableRoot();
- if (!pRoot)
+ if (!pRoot) {
return nullptr;
+ }
// Retrieve the document's Names dictionary; create it if missing.
RetainPtr<CPDF_Dictionary> pNames = pRoot->GetMutableDictFor("Names");
@@ -480,10 +525,12 @@
const ByteString& name) {
RetainPtr<const CPDF_Array> dest_array;
std::unique_ptr<CPDF_NameTree> name_tree = Create(pDoc, "Dests");
- if (name_tree)
+ if (name_tree) {
dest_array = name_tree->LookupNewStyleNamedDest(name);
- if (!dest_array)
+ }
+ if (!dest_array) {
dest_array = LookupOldStyleNamedDest(pDoc, name);
+ }
return dest_array;
}
@@ -538,14 +585,17 @@
std::vector<CPDF_Array*> all_limits =
GetNodeAncestorsLimits(root_, node_to_insert.names.Get());
for (auto* pLimits : all_limits) {
- if (!pLimits)
+ if (!pLimits) {
continue;
+ }
- if (name.Compare(pLimits->GetUnicodeTextAt(0)) < 0)
+ if (name.Compare(pLimits->GetUnicodeTextAt(0)) < 0) {
pLimits->SetNewAt<CPDF_String>(0, name.AsStringView());
+ }
- if (name.Compare(pLimits->GetUnicodeTextAt(1)) > 0)
+ if (name.Compare(pLimits->GetUnicodeTextAt(1)) > 0) {
pLimits->SetNewAt<CPDF_String>(1, name.AsStringView());
+ }
}
return true;
}
diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp
index a306177..01b0115 100644
--- a/core/fpdfdoc/cpdf_structelement.cpp
+++ b/core/fpdfdoc/cpdf_structelement.cpp
@@ -58,15 +58,17 @@
std::optional<WideString> CPDF_StructElement::GetID() const {
RetainPtr<const CPDF_Object> obj = dict_->GetObjectFor("ID");
- if (!obj || !obj->IsString())
+ if (!obj || !obj->IsString()) {
return std::nullopt;
+ }
return obj->GetUnicodeText();
}
std::optional<WideString> CPDF_StructElement::GetLang() const {
RetainPtr<const CPDF_Object> obj = dict_->GetObjectFor("Lang");
- if (!obj || !obj->IsString())
+ if (!obj || !obj->IsString()) {
return std::nullopt;
+ }
return obj->GetUnicodeText();
}
@@ -111,8 +113,9 @@
const CPDF_Reference* pRef = ToReference(pObj.Get());
const uint32_t page_obj_num = pRef ? pRef->GetRefObjNum() : 0;
RetainPtr<const CPDF_Object> pKids = dict_->GetDirectObjectFor("K");
- if (!pKids)
+ if (!pKids) {
return;
+ }
DCHECK(kids_.empty());
if (const CPDF_Array* pArray = pKids->AsArray()) {
@@ -130,8 +133,9 @@
void CPDF_StructElement::LoadKid(uint32_t page_obj_num,
RetainPtr<const CPDF_Object> pKidObj,
Kid& kid) {
- if (!pKidObj)
+ if (!pKidObj) {
return;
+ }
if (pKidObj->IsNumber()) {
if (tree_->GetPageObjNum() != page_obj_num) {
@@ -145,8 +149,9 @@
}
const CPDF_Dictionary* pKidDict = pKidObj->AsDictionary();
- if (!pKidDict)
+ if (!pKidDict) {
return;
+ }
if (RetainPtr<const CPDF_Reference> pRef =
ToReference(pKidDict->GetObjectFor("Pg"))) {
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index ea3c1f0..eddd907 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -30,8 +30,9 @@
std::unique_ptr<CPDF_StructTree> CPDF_StructTree::LoadPage(
const CPDF_Document* pDoc,
RetainPtr<const CPDF_Dictionary> pPageDict) {
- if (!IsTagged(pDoc))
+ if (!IsTagged(pDoc)) {
return nullptr;
+ }
auto pTree = std::make_unique<CPDF_StructTree>(pDoc);
pTree->LoadPageTree(std::move(pPageDict));
@@ -47,8 +48,9 @@
ByteString CPDF_StructTree::GetRoleMapNameFor(const ByteString& type) const {
if (role_map_) {
ByteString mapped = role_map_->GetNameFor(type);
- if (!mapped.IsEmpty())
+ if (!mapped.IsEmpty()) {
return mapped;
+ }
}
return type;
}
@@ -60,40 +62,46 @@
}
RetainPtr<const CPDF_Object> pKids = tree_root_->GetDirectObjectFor("K");
- if (!pKids)
+ if (!pKids) {
return;
+ }
size_t kids_count;
- if (pKids->IsDictionary())
+ if (pKids->IsDictionary()) {
kids_count = 1;
- else if (const CPDF_Array* pArray = pKids->AsArray())
+ } else if (const CPDF_Array* pArray = pKids->AsArray()) {
kids_count = pArray->size();
- else
+ } else {
return;
+ }
kids_.clear();
kids_.resize(kids_count);
RetainPtr<const CPDF_Dictionary> pParentTree =
tree_root_->GetDictFor("ParentTree");
- if (!pParentTree)
+ if (!pParentTree) {
return;
+ }
CPDF_NumberTree parent_tree(std::move(pParentTree));
int parents_id = page_->GetIntegerFor("StructParents", -1);
- if (parents_id < 0)
+ if (parents_id < 0) {
return;
+ }
RetainPtr<const CPDF_Array> pParentArray =
ToArray(parent_tree.LookupValue(parents_id));
- if (!pParentArray)
+ if (!pParentArray) {
return;
+ }
StructElementMap element_map;
for (size_t i = 0; i < pParentArray->size(); i++) {
RetainPtr<const CPDF_Dictionary> pParent = pParentArray->GetDictAt(i);
- if (pParent)
+ if (pParent) {
AddPageNode(std::move(pParent), &element_map, 0);
+ }
}
}
@@ -102,27 +110,31 @@
StructElementMap* map,
int nLevel) {
static constexpr int kStructTreeMaxRecursion = 32;
- if (nLevel > kStructTreeMaxRecursion)
+ if (nLevel > kStructTreeMaxRecursion) {
return nullptr;
+ }
auto it = map->find(pDict);
- if (it != map->end())
+ if (it != map->end()) {
return it->second;
+ }
RetainPtr<const CPDF_Dictionary> key(pDict);
auto pElement = pdfium::MakeRetain<CPDF_StructElement>(this, pDict);
(*map)[key] = pElement;
RetainPtr<const CPDF_Dictionary> pParent = pDict->GetDictFor("P");
if (!pParent || pParent->GetNameFor("Type") == "StructTreeRoot") {
- if (!AddTopLevelNode(pDict, pElement))
+ if (!AddTopLevelNode(pDict, pElement)) {
map->erase(key);
+ }
return pElement;
}
RetainPtr<CPDF_StructElement> pParentElement =
AddPageNode(std::move(pParent), map, nLevel + 1);
- if (!pParentElement)
+ if (!pParentElement) {
return pElement;
+ }
if (!pParentElement->UpdateKidIfElement(pDict, pElement.Get())) {
map->erase(key);
@@ -137,18 +149,21 @@
const CPDF_Dictionary* pDict,
const RetainPtr<CPDF_StructElement>& pElement) {
RetainPtr<const CPDF_Object> pObj = tree_root_->GetDirectObjectFor("K");
- if (!pObj)
+ if (!pObj) {
return false;
+ }
if (pObj->IsDictionary()) {
- if (pObj->GetObjNum() != pDict->GetObjNum())
+ if (pObj->GetObjNum() != pDict->GetObjNum()) {
return false;
+ }
kids_[0] = pElement;
}
const CPDF_Array* pTopKids = pObj->AsArray();
- if (!pTopKids)
+ if (!pTopKids) {
return true;
+ }
bool bSave = false;
for (size_t i = 0; i < pTopKids->size(); i++) {
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index 00e436a..f6255fa 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -44,12 +44,14 @@
std::optional<ByteString> CPDF_ViewerPreferences::GenericName(
const ByteString& bsKey) const {
RetainPtr<const CPDF_Dictionary> pDict = GetViewerPreferences();
- if (!pDict)
+ if (!pDict) {
return std::nullopt;
+ }
RetainPtr<const CPDF_Name> pName = ToName(pDict->GetObjectFor(bsKey));
- if (!pName)
+ if (!pName) {
return std::nullopt;
+ }
return pName->GetString();
}
diff --git a/core/fpdfdoc/cpvt_floatrect.h b/core/fpdfdoc/cpvt_floatrect.h
index a9add92..05ab972 100644
--- a/core/fpdfdoc/cpvt_floatrect.h
+++ b/core/fpdfdoc/cpvt_floatrect.h
@@ -23,8 +23,9 @@
: CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top) {}
float Height() const {
- if (top > bottom)
+ if (top > bottom) {
return top - bottom;
+ }
return bottom - top;
}
};
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index 4a8d1e9..5b804fe 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -37,8 +37,9 @@
RetainPtr<CPDF_Font> pPDFFont =
CPDF_InteractiveForm::AddNativeInteractiveFormFont(document_,
&sys_font_alias_);
- if (!pPDFFont)
+ if (!pPDFFont) {
return;
+ }
RetainPtr<CPDF_Dictionary> pFontList = res_dict_->GetMutableDictFor("Font");
if (ValidateFontResourceDict(pFontList.Get()) &&
diff --git a/core/fpdfdoc/cpvt_section.cpp b/core/fpdfdoc/cpvt_section.cpp
index 546322f..6b9f629 100644
--- a/core/fpdfdoc/cpvt_section.cpp
+++ b/core/fpdfdoc/cpvt_section.cpp
@@ -260,8 +260,9 @@
CPVT_WordPlace CPVT_Section::GetPrevWordPlace(
const CPVT_WordPlace& place) const {
- if (place.nLineIndex < 0)
+ if (place.nLineIndex < 0) {
return GetBeginWordPlace();
+ }
if (place.nLineIndex >= fxcrt::CollectionSize<int32_t>(line_array_)) {
return GetEndWordPlace();
@@ -285,8 +286,9 @@
CPVT_WordPlace CPVT_Section::GetNextWordPlace(
const CPVT_WordPlace& place) const {
- if (place.nLineIndex < 0)
+ if (place.nLineIndex < 0) {
return GetBeginWordPlace();
+ }
if (place.nLineIndex >= fxcrt::CollectionSize<int32_t>(line_array_)) {
return GetEndWordPlace();
@@ -335,10 +337,12 @@
float fTop = pLine->line_info_.fLineY - pLine->line_info_.fLineAscent -
vt_->GetLineLeading();
float fBottom = pLine->line_info_.fLineY - pLine->line_info_.fLineDescent;
- if (FXSYS_IsFloatBigger(point.y, fTop))
+ if (FXSYS_IsFloatBigger(point.y, fTop)) {
bUp = false;
- if (FXSYS_IsFloatSmaller(point.y, fBottom))
+ }
+ if (FXSYS_IsFloatSmaller(point.y, fBottom)) {
bDown = false;
+ }
if (FXSYS_IsFloatSmaller(point.y, fTop)) {
nRight = nMid - 1;
nMid = (nLeft + nRight) / 2;
@@ -356,10 +360,12 @@
place.nLineIndex = nMid;
return place;
}
- if (bUp)
+ if (bUp) {
place = GetBeginWordPlace();
- if (bDown)
+ }
+ if (bDown) {
place = GetEndWordPlace();
+ }
return place;
}
@@ -387,8 +393,9 @@
int32_t nRight = range.EndPos.nWordIndex + 1;
int32_t nMid = (nLeft + nRight) / 2;
while (nLeft < nRight) {
- if (nMid == nLeft)
+ if (nMid == nLeft) {
break;
+ }
if (nMid == nRight) {
nMid--;
break;
diff --git a/core/fpdfdoc/cpvt_variabletext.cpp b/core/fpdfdoc/cpvt_variabletext.cpp
index b5813b7..cfd7856 100644
--- a/core/fpdfdoc/cpvt_variabletext.cpp
+++ b/core/fpdfdoc/cpvt_variabletext.cpp
@@ -43,12 +43,14 @@
int CPVT_VariableText::Provider::GetCharWidth(int32_t nFontIndex,
uint16_t word) {
RetainPtr<CPDF_Font> pPDFFont = font_map_->GetPDFFont(nFontIndex);
- if (!pPDFFont)
+ if (!pPDFFont) {
return 0;
+ }
uint32_t charcode = pPDFFont->CharCodeFromUnicode(word);
- if (charcode == CPDF_Font::kInvalidCharCode)
+ if (charcode == CPDF_Font::kInvalidCharCode) {
return 0;
+ }
return pPDFFont->GetCharWidthF(charcode);
}
@@ -67,12 +69,14 @@
FX_Charset charset,
int32_t nFontIndex) {
if (RetainPtr<CPDF_Font> pDefFont = font_map_->GetPDFFont(0)) {
- if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode)
+ if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) {
return 0;
+ }
}
if (RetainPtr<CPDF_Font> pSysFont = font_map_->GetPDFFont(1)) {
- if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode)
+ if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) {
return 1;
+ }
}
return -1;
}
@@ -134,8 +138,9 @@
}
const CPVT_WordInfo* pInfo = pSection->GetWordFromArray(cur_pos_.nWordIndex);
- if (!pInfo)
+ if (!pInfo) {
return false;
+ }
word.Word = pInfo->Word;
word.nCharset = pInfo->nCharset;
@@ -160,8 +165,9 @@
CPVT_Section* pSection = vt_->section_array_[cur_pos_.nSecIndex].get();
const CPVT_Section::Line* pLine =
pSection->GetLineFromArray(cur_pos_.nLineIndex);
- if (!pLine)
+ if (!pLine) {
return false;
+ }
line.ptLine = vt_->InToOut(
CFX_PointF(pLine->line_info_.fLineX + pSection->GetRect().left,
@@ -262,8 +268,9 @@
ClearWords(PlaceRange);
if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) {
ClearEmptySections(PlaceRange);
- if (!bLastSecPos)
+ if (!bLastSecPos) {
LinkLatterSection(PlaceRange.BeginPos);
+ }
}
return PlaceRange.BeginPos;
}
@@ -296,16 +303,18 @@
switch (word) {
case 0x0D:
if (multi_line_) {
- if (i + 1 < sz && swText[i + 1] == 0x0A)
+ if (i + 1 < sz && swText[i + 1] == 0x0A) {
i++;
+ }
wp.AdvanceSection();
AddSection(wp);
}
break;
case 0x0A:
if (multi_line_) {
- if (i + 1 < sz && swText[i + 1] == 0x0D)
+ if (i + 1 < sz && swText[i + 1] == 0x0D) {
i++;
+ }
wp.AdvanceSection();
AddSection(wp);
}
@@ -322,8 +331,9 @@
}
void CPVT_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const {
- if (place.nSecIndex < 0)
+ if (place.nSecIndex < 0) {
place = GetBeginWordPlace();
+ }
if (static_cast<size_t>(place.nSecIndex) >= section_array_.size()) {
place = GetEndWordPlace();
}
@@ -345,8 +355,9 @@
i < sz && i < newplace.nSecIndex; i++) {
CPVT_Section* pSection = section_array_[i].get();
nIndex += pSection->GetWordArraySize();
- if (i != sz - 1)
+ if (i != sz - 1) {
nIndex += kReturnLength;
+ }
}
if (fxcrt::IndexInBounds(section_array_, i)) {
nIndex += newplace.nWordIndex + kReturnLength;
@@ -379,8 +390,9 @@
}
nOldIndex = nIndex;
}
- if (!bFound)
+ if (!bFound) {
place = GetEndWordPlace();
+ }
return place;
}
@@ -397,15 +409,17 @@
CPVT_WordPlace CPVT_VariableText::GetPrevWordPlace(
const CPVT_WordPlace& place) const {
- if (place.nSecIndex < 0)
+ if (place.nSecIndex < 0) {
return GetBeginWordPlace();
+ }
if (static_cast<size_t>(place.nSecIndex) >= section_array_.size()) {
return GetEndWordPlace();
}
CPVT_Section* pSection = section_array_[place.nSecIndex].get();
- if (place > pSection->GetBeginWordPlace())
+ if (place > pSection->GetBeginWordPlace()) {
return pSection->GetPrevWordPlace(place);
+ }
if (!fxcrt::IndexInBounds(section_array_, place.nSecIndex - 1)) {
return GetBeginWordPlace();
}
@@ -414,15 +428,17 @@
CPVT_WordPlace CPVT_VariableText::GetNextWordPlace(
const CPVT_WordPlace& place) const {
- if (place.nSecIndex < 0)
+ if (place.nSecIndex < 0) {
return GetBeginWordPlace();
+ }
if (static_cast<size_t>(place.nSecIndex) >= section_array_.size()) {
return GetEndWordPlace();
}
CPVT_Section* pSection = section_array_[place.nSecIndex].get();
- if (place < pSection->GetEndWordPlace())
+ if (place < pSection->GetEndWordPlace()) {
return pSection->GetNextWordPlace(place);
+ }
if (!fxcrt::IndexInBounds(section_array_, place.nSecIndex + 1)) {
return GetEndWordPlace();
}
@@ -443,10 +459,12 @@
break;
}
CPVT_Section* pSection = section_array_[nMid].get();
- if (FXSYS_IsFloatBigger(pt.y, pSection->GetRect().top))
+ if (FXSYS_IsFloatBigger(pt.y, pSection->GetRect().top)) {
bUp = false;
- if (FXSYS_IsFloatBigger(pSection->GetRect().bottom, pt.y))
+ }
+ if (FXSYS_IsFloatBigger(pSection->GetRect().bottom, pt.y)) {
bDown = false;
+ }
if (FXSYS_IsFloatSmaller(pt.y, pSection->GetRect().top)) {
nRight = nMid - 1;
nMid = (nLeft + nRight) / 2;
@@ -462,10 +480,12 @@
place.nSecIndex = nMid;
return place;
}
- if (bUp)
+ if (bUp) {
place = GetBeginWordPlace();
- if (bDown)
+ }
+ if (bDown) {
place = GetEndWordPlace();
+ }
return place;
}
@@ -529,8 +549,9 @@
CPVT_Section* pSection = section_array_[place.nSecIndex].get();
const CPVT_Section::Line* pLine =
pSection->GetLineFromArray(place.nLineIndex);
- if (!pLine)
+ if (!pLine) {
return place;
+ }
return pLine->GetEndWordPlace();
}
@@ -683,15 +704,17 @@
CPVT_WordPlace CPVT_VariableText::PrevLineHeaderPlace(
const CPVT_WordPlace& place) const {
- if (place.nWordIndex < 0 && place.nLineIndex > 0)
+ if (place.nWordIndex < 0 && place.nLineIndex > 0) {
return GetPrevWordPlace(place);
+ }
return place;
}
CPVT_WordPlace CPVT_VariableText::NextLineHeaderPlace(
const CPVT_WordPlace& place) const {
- if (place.nWordIndex < 0 && place.nLineIndex > 0)
+ if (place.nWordIndex < 0 && place.nLineIndex > 0) {
return GetNextWordPlace(place);
+ }
return place;
}
@@ -756,14 +779,16 @@
CPVT_Section* pSection = section_array_[place.nSecIndex].get();
CPVT_WordPlace leftplace = GetPrevWordPlace(place);
- if (leftplace == place)
+ if (leftplace == place) {
return place;
+ }
if (leftplace.nSecIndex != place.nSecIndex) {
- if (pSection->GetWordArraySize() == 0)
+ if (pSection->GetWordArraySize() == 0) {
ClearEmptySection(place);
- else
+ } else {
LinkLatterSection(leftplace);
+ }
} else {
pSection->ClearWord(place);
}
@@ -777,13 +802,15 @@
CPVT_Section* pSection = section_array_[place.nSecIndex].get();
CPVT_WordPlace rightplace = NextLineHeaderPlace(GetNextWordPlace(place));
- if (rightplace == place)
+ if (rightplace == place) {
return place;
+ }
- if (rightplace.nSecIndex != place.nSecIndex)
+ if (rightplace.nSecIndex != place.nSecIndex) {
LinkLatterSection(place);
- else
+ } else {
pSection->ClearWord(rightplace);
+ }
return place;
}
diff --git a/core/fpdfdoc/cpvt_wordinfo.cpp b/core/fpdfdoc/cpvt_wordinfo.cpp
index a301a32..689dd29 100644
--- a/core/fpdfdoc/cpvt_wordinfo.cpp
+++ b/core/fpdfdoc/cpvt_wordinfo.cpp
@@ -39,8 +39,9 @@
CPVT_WordInfo::~CPVT_WordInfo() = default;
CPVT_WordInfo& CPVT_WordInfo::operator=(const CPVT_WordInfo& word) {
- if (this == &word)
+ if (this == &word) {
return *this;
+ }
Word = word.Word;
nCharset = word.nCharset;
diff --git a/core/fpdfdoc/cpvt_wordplace.h b/core/fpdfdoc/cpvt_wordplace.h
index 2d0f9c8..f00a97a 100644
--- a/core/fpdfdoc/cpvt_wordplace.h
+++ b/core/fpdfdoc/cpvt_wordplace.h
@@ -39,17 +39,21 @@
return !(*this == wp);
}
inline bool operator<(const CPVT_WordPlace& wp) const {
- if (nSecIndex != wp.nSecIndex)
+ if (nSecIndex != wp.nSecIndex) {
return nSecIndex < wp.nSecIndex;
- if (nLineIndex != wp.nLineIndex)
+ }
+ if (nLineIndex != wp.nLineIndex) {
return nLineIndex < wp.nLineIndex;
+ }
return nWordIndex < wp.nWordIndex;
}
inline bool operator>(const CPVT_WordPlace& wp) const {
- if (nSecIndex != wp.nSecIndex)
+ if (nSecIndex != wp.nSecIndex) {
return nSecIndex > wp.nSecIndex;
- if (nLineIndex != wp.nLineIndex)
+ }
+ if (nLineIndex != wp.nLineIndex) {
return nLineIndex > wp.nLineIndex;
+ }
return nWordIndex > wp.nWordIndex;
}
inline bool operator<=(const CPVT_WordPlace& wp) const {
@@ -60,8 +64,9 @@
}
inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex != wp.nSecIndex)
+ if (nSecIndex != wp.nSecIndex) {
return nSecIndex - wp.nSecIndex;
+ }
return nLineIndex - wp.nLineIndex;
}
diff --git a/core/fpdfdoc/cpvt_wordrange.h b/core/fpdfdoc/cpvt_wordrange.h
index 5d84af3..3bd477e 100644
--- a/core/fpdfdoc/cpvt_wordrange.h
+++ b/core/fpdfdoc/cpvt_wordrange.h
@@ -29,8 +29,9 @@
}
void Normalize() {
- if (BeginPos > EndPos)
+ if (BeginPos > EndPos) {
std::swap(BeginPos, EndPos);
+ }
}
CPVT_WordPlace BeginPos;