summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r--core/src/fpdfdoc/doc_action.cpp35
-rw-r--r--core/src/fpdfdoc/doc_ap.cpp9
-rw-r--r--core/src/fpdfdoc/doc_basic.cpp54
-rw-r--r--core/src/fpdfdoc/doc_bookmark.cpp10
-rw-r--r--core/src/fpdfdoc/doc_formcontrol.cpp12
-rw-r--r--core/src/fpdfdoc/doc_formfield.cpp70
-rw-r--r--core/src/fpdfdoc/doc_link.cpp5
-rw-r--r--core/src/fpdfdoc/doc_ocg.cpp79
-rw-r--r--core/src/fpdfdoc/doc_tagged.cpp130
9 files changed, 169 insertions, 235 deletions
diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp
index bcbfe0f112..d685f64cae 100644
--- a/core/src/fpdfdoc/doc_action.cpp
+++ b/core/src/fpdfdoc/doc_action.cpp
@@ -22,9 +22,8 @@ CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
CFX_ByteStringC name = pDest->GetString();
return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name));
}
- if (pDest->GetType() == PDFOBJ_ARRAY) {
- return CPDF_Dest((CPDF_Array*)pDest);
- }
+ if (CPDF_Array* pArray = pDest->AsArray())
+ return CPDF_Dest(pArray);
return CPDF_Dest();
}
const FX_CHAR* g_sATypes[] = {
@@ -108,8 +107,8 @@ FX_DWORD CPDF_ActionFields::GetFieldsCount() const {
return 1;
if (pFields->IsString())
return 1;
- if (pFields->GetType() == PDFOBJ_ARRAY)
- return ((CPDF_Array*)pFields)->GetCount();
+ if (CPDF_Array* pArray = pFields->AsArray())
+ return pArray->GetCount();
return 0;
}
void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const {
@@ -133,8 +132,7 @@ void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const {
if (pFields->IsDictionary() || pFields->IsString()) {
fieldObjects.Add(pFields);
- } else if (pFields->GetType() == PDFOBJ_ARRAY) {
- CPDF_Array* pArray = (CPDF_Array*)pFields;
+ } else if (CPDF_Array* pArray = pFields->AsArray()) {
FX_DWORD iCount = pArray->GetCount();
for (FX_DWORD i = 0; i < iCount; i++) {
CPDF_Object* pObj = pArray->GetElementValue(i);
@@ -166,8 +164,8 @@ CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const {
if (pFields->IsDictionary() || pFields->IsString()) {
if (iIndex == 0)
pFindObj = pFields;
- } else if (pFields->GetType() == PDFOBJ_ARRAY) {
- pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex);
+ } else if (CPDF_Array* pArray = pFields->AsArray()) {
+ pFindObj = pArray->GetElementValue(iIndex);
}
return pFindObj;
}
@@ -222,20 +220,16 @@ int32_t CPDF_Action::GetOperationType() const {
return 0;
}
FX_DWORD CPDF_Action::GetSubActionsCount() const {
- if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
+ if (!m_pDict || !m_pDict->KeyExist("Next"))
return 0;
- }
+
CPDF_Object* pNext = m_pDict->GetElementValue("Next");
- if (!pNext) {
+ if (!pNext)
return 0;
- }
- int iObjType = pNext->GetType();
- if (iObjType == PDFOBJ_DICTIONARY) {
+ if (pNext->IsDictionary())
return 1;
- }
- if (iObjType == PDFOBJ_ARRAY) {
- return ((CPDF_Array*)pNext)->GetCount();
- }
+ if (CPDF_Array* pArray = pNext->AsArray())
+ return pArray->GetCount();
return 0;
}
CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const {
@@ -246,8 +240,7 @@ CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const {
if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
if (iIndex == 0)
return CPDF_Action(pDict);
- } else if (pNext->GetType() == PDFOBJ_ARRAY) {
- CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext);
+ } else if (CPDF_Array* pArray = ToArray(pNext)) {
return CPDF_Action(pArray->GetDict(iIndex));
}
return CPDF_Action();
diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp
index 71025ec532..77a1f15306 100644
--- a/core/src/fpdfdoc/doc_ap.cpp
+++ b/core/src/fpdfdoc/doc_ap.cpp
@@ -618,12 +618,11 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
}
if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) {
CFX_WideString swItem;
- if (pOpt->IsString()) {
+ if (pOpt->IsString())
swItem = pOpt->GetUnicodeText();
- } else if (pOpt->GetType() == PDFOBJ_ARRAY) {
- swItem =
- ((CPDF_Array*)pOpt)->GetElementValue(1)->GetUnicodeText();
- }
+ else if (CPDF_Array* pArray = pOpt->AsArray())
+ swItem = pArray->GetElementValue(1)->GetUnicodeText();
+
FX_BOOL bSelected = FALSE;
if (pSels) {
for (FX_DWORD s = 0, ssz = pSels->GetCount(); s < ssz; s++) {
diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp
index cbf956bd9b..b32e34bb4c 100644
--- a/core/src/fpdfdoc/doc_basic.cpp
+++ b/core/src/fpdfdoc/doc_basic.cpp
@@ -7,10 +7,11 @@
#include "../../include/fpdfdoc/fpdf_doc.h"
const int nMaxRecursion = 32;
int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
- if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(m_pObj);
+ if (!pArray)
return 0;
- }
- CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0);
+
+ CPDF_Object* pPage = pArray->GetElementValue(0);
if (!pPage)
return 0;
if (pPage->IsNumber())
@@ -20,10 +21,11 @@ int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
return pDoc->GetPageIndex(pPage->GetObjNum());
}
FX_DWORD CPDF_Dest::GetPageObjNum() {
- if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(m_pObj);
+ if (!pArray)
return 0;
- }
- CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0);
+
+ CPDF_Object* pPage = pArray->GetElementValue(0);
if (!pPage)
return 0;
if (pPage->IsNumber())
@@ -35,11 +37,12 @@ FX_DWORD CPDF_Dest::GetPageObjNum() {
const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR",
"FitB", "FitBH", "FitBV", ""};
int CPDF_Dest::GetZoomMode() {
- if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(m_pObj);
+ if (!pArray)
return 0;
- }
+
CFX_ByteString mode;
- CPDF_Object* pObj = ((CPDF_Array*)m_pObj)->GetElementValue(1);
+ CPDF_Object* pObj = pArray->GetElementValue(1);
mode = pObj ? pObj->GetString() : CFX_ByteString();
int i = 0;
while (g_sZoomModes[i][0] != '\0') {
@@ -51,16 +54,11 @@ int CPDF_Dest::GetZoomMode() {
return 0;
}
FX_FLOAT CPDF_Dest::GetParam(int index) {
- if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) {
- return 0;
- }
- return ((CPDF_Array*)m_pObj)->GetNumber(2 + index);
+ CPDF_Array* pArray = ToArray(m_pObj);
+ return pArray ? pArray->GetNumber(2 + index) : 0;
}
CFX_ByteString CPDF_Dest::GetRemoteName() {
- if (m_pObj == NULL) {
- return CFX_ByteString();
- }
- return m_pObj->GetString();
+ return m_pObj ? m_pObj->GetString() : CFX_ByteString();
}
CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc,
const CFX_ByteStringC& category) {
@@ -224,23 +222,19 @@ CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const {
CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
const CFX_ByteStringC& sName) {
CPDF_Object* pValue = LookupValue(sName);
- if (pValue == NULL) {
+ if (!pValue) {
CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict(FX_BSTRC("Dests"));
- if (pDests == NULL) {
- return NULL;
- }
+ if (!pDests)
+ return nullptr;
pValue = pDests->GetElementValue(sName);
}
- if (pValue == NULL) {
- return NULL;
- }
- if (pValue->GetType() == PDFOBJ_ARRAY) {
- return (CPDF_Array*)pValue;
- }
- if (CPDF_Dictionary* pDict = pValue->AsDictionary()) {
+ if (!pValue)
+ return nullptr;
+ if (CPDF_Array* pArray = pValue->AsArray())
+ return pArray;
+ if (CPDF_Dictionary* pDict = pValue->AsDictionary())
return pDict->GetArray(FX_BSTRC("D"));
- }
- return NULL;
+ return nullptr;
}
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \
_FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
diff --git a/core/src/fpdfdoc/doc_bookmark.cpp b/core/src/fpdfdoc/doc_bookmark.cpp
index 6b020e5957..5ebd27e6e7 100644
--- a/core/src/fpdfdoc/doc_bookmark.cpp
+++ b/core/src/fpdfdoc/doc_bookmark.cpp
@@ -68,21 +68,19 @@ CFX_WideString CPDF_Bookmark::GetTitle() const {
return CFX_WideString(buf.get(), len);
}
CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const {
- if (!m_pDict) {
+ if (!m_pDict)
return CPDF_Dest();
- }
+
CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
if (!pDest)
return CPDF_Dest();
-
if (pDest->IsString() || pDest->IsName()) {
CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
CFX_ByteStringC name = pDest->GetString();
return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name));
}
- if (pDest->GetType() == PDFOBJ_ARRAY) {
- return CPDF_Dest((CPDF_Array*)pDest);
- }
+ if (CPDF_Array* pArray = pDest->AsArray())
+ return CPDF_Dest(pArray);
return CPDF_Dest();
}
CPDF_Action CPDF_Bookmark::GetAction() const {
diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp
index c5f47d20cb..35329f9e05 100644
--- a/core/src/fpdfdoc/doc_formcontrol.cpp
+++ b/core/src/fpdfdoc/doc_formcontrol.cpp
@@ -85,15 +85,13 @@ CFX_ByteString CPDF_FormControl::GetCheckedAPState() {
CFX_ByteString csOn = GetOnStateName();
if (GetType() == CPDF_FormField::RadioButton ||
GetType() == CPDF_FormField::CheckBox) {
- CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
- if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
+ if (ToArray(FPDF_GetFieldAttr(m_pField->m_pDict, "Opt"))) {
int iIndex = m_pField->GetControlIndex(this);
csOn.Format("%d", iIndex);
}
}
- if (csOn.IsEmpty()) {
+ if (csOn.IsEmpty())
csOn = "Yes";
- }
return csOn;
}
CFX_WideString CPDF_FormControl::GetExportValue() {
@@ -102,10 +100,10 @@ CFX_WideString CPDF_FormControl::GetExportValue() {
CFX_ByteString csOn = GetOnStateName();
if (GetType() == CPDF_FormField::RadioButton ||
GetType() == CPDF_FormField::CheckBox) {
- CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
- if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
+ if (CPDF_Array* pArray =
+ ToArray(FPDF_GetFieldAttr(m_pField->m_pDict, "Opt"))) {
int iIndex = m_pField->GetControlIndex(this);
- csOn = ((CPDF_Array*)pOpt)->GetString(iIndex);
+ csOn = pArray->GetString(iIndex);
}
}
if (csOn.IsEmpty()) {
diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp
index 0766eb0bc0..efa2ea23bd 100644
--- a/core/src/fpdfdoc/doc_formfield.cpp
+++ b/core/src/fpdfdoc/doc_formfield.cpp
@@ -307,10 +307,9 @@ CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) {
case PDFOBJ_STREAM:
return pValue->GetUnicodeText();
case PDFOBJ_ARRAY:
- pValue = ((CPDF_Array*)pValue)->GetElementValue(0);
- if (pValue) {
+ pValue = pValue->AsArray()->GetElementValue(0);
+ if (pValue)
return pValue->GetUnicodeText();
- }
break;
}
return CFX_WideString();
@@ -419,28 +418,24 @@ int CPDF_FormField::GetMaxLen() {
}
int CPDF_FormField::CountSelectedItems() {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
- if (pValue == NULL) {
+ if (!pValue) {
pValue = FPDF_GetFieldAttr(m_pDict, "I");
- if (pValue == NULL) {
+ if (!pValue)
return 0;
- }
}
if (pValue->IsString() || pValue->IsNumber())
return pValue->GetString().IsEmpty() ? 0 : 1;
-
- if (pValue->GetType() != PDFOBJ_ARRAY) {
- return 0;
- }
- return ((CPDF_Array*)pValue)->GetCount();
+ if (CPDF_Array* pArray = pValue->AsArray())
+ return pArray->GetCount();
+ return 0;
}
int CPDF_FormField::GetSelectedIndex(int index) {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
- if (pValue == NULL) {
+ if (!pValue) {
pValue = FPDF_GetFieldAttr(m_pDict, "I");
- if (pValue == NULL) {
+ if (!pValue)
return -1;
- }
}
if (pValue->IsNumber())
return pValue->GetInteger();
@@ -449,16 +444,13 @@ int CPDF_FormField::GetSelectedIndex(int index) {
if (pValue->IsString()) {
if (index != 0)
return -1;
-
sel_value = pValue->GetUnicodeText();
} else {
- if (pValue->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = pValue->AsArray();
+ if (!pArray || index < 0)
return -1;
- }
- if (index < 0) {
- return -1;
- }
- CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index);
+
+ CPDF_Object* elementValue = pArray->GetElementValue(index);
sel_value =
elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
}
@@ -537,10 +529,10 @@ FX_BOOL CPDF_FormField::IsItemSelected(int index) {
return (pValue->GetInteger() == index);
}
- if (pValue->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = pValue->AsArray();
+ if (!pArray)
return FALSE;
- }
- CPDF_Array* pArray = (CPDF_Array*)pValue;
+
int iPos = -1;
for (int j = 0; j < CountSelectedOptions(); j++) {
if (GetSelectedOptionIndex(j) == index) {
@@ -584,11 +576,8 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
if (pValue->GetUnicodeText() == opt_value) {
m_pDict->RemoveAt("V");
}
- } else if (pValue->GetType() == PDFOBJ_ARRAY) {
+ } else if (pValue->IsArray()) {
CPDF_Array* pArray = CPDF_Array::Create();
- if (pArray == NULL) {
- return FALSE;
- }
int iCount = CountOptions();
for (int i = 0; i < iCount; i++) {
if (i != index) {
@@ -703,24 +692,19 @@ void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl) {
}
}
int CPDF_FormField::CountOptions() {
- CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
- return 0;
- }
- return ((CPDF_Array*)pValue)->GetCount();
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
+ return pArray ? pArray->GetCount() : 0;
}
CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
- CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
+ if (!pArray)
return CFX_WideString();
- }
- CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index);
- if (pOption == NULL) {
+
+ CPDF_Object* pOption = pArray->GetElementValue(index);
+ if (!pOption)
return CFX_WideString();
- }
- if (pOption->GetType() == PDFOBJ_ARRAY) {
- pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index);
- }
+ if (CPDF_Array* pOptionArray = pOption->AsArray())
+ pOption = pOptionArray->GetElementValue(sub_index);
CPDF_String* pString = ToString(pOption);
return pString ? pString->GetUnicodeText() : CFX_WideString();
@@ -873,7 +857,7 @@ FX_BOOL CPDF_FormField::CheckControl(int iControlIndex,
}
}
CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) {
+ if (!ToArray(pOpt)) {
if (bChecked) {
m_pDict->SetAtName("V", csBExport);
} else {
diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp
index 977efeafd1..6d3f6c5046 100644
--- a/core/src/fpdfdoc/doc_link.cpp
+++ b/core/src/fpdfdoc/doc_link.cpp
@@ -81,9 +81,8 @@ CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) {
CFX_ByteStringC name = pDest->GetString();
return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name));
}
- if (pDest->GetType() == PDFOBJ_ARRAY) {
- return CPDF_Dest((CPDF_Array*)pDest);
- }
+ if (CPDF_Array* pArray = pDest->AsArray())
+ return CPDF_Dest(pArray);
return CPDF_Dest();
}
CPDF_Action CPDF_Link::GetAction() {
diff --git a/core/src/fpdfdoc/doc_ocg.cpp b/core/src/fpdfdoc/doc_ocg.cpp
index e66b04489f..b252456df6 100644
--- a/core/src/fpdfdoc/doc_ocg.cpp
+++ b/core/src/fpdfdoc/doc_ocg.cpp
@@ -7,23 +7,18 @@
#include "../../include/fpdfdoc/fpdf_doc.h"
static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject,
const CPDF_Dictionary* pGroupDict) {
- if (pObject == NULL || pGroupDict == NULL) {
+ if (!pObject || !pGroupDict)
return -1;
- }
- int32_t iType = pObject->GetType();
- if (iType == PDFOBJ_ARRAY) {
- FX_DWORD dwCount = ((CPDF_Array*)pObject)->GetCount();
+
+ if (const CPDF_Array* pArray = pObject->AsArray()) {
+ FX_DWORD dwCount = pArray->GetCount();
for (FX_DWORD i = 0; i < dwCount; i++) {
- if (((CPDF_Array*)pObject)->GetDict(i) == pGroupDict) {
+ if (pArray->GetDict(i) == pGroupDict)
return i;
- }
}
return -1;
}
- if (pObject->GetDict() == pGroupDict) {
- return 0;
- }
- return -1;
+ return pObject->GetDict() == pGroupDict ? 0 : -1;
}
static FX_BOOL FPDFDOC_OCG_HasIntent(
const CPDF_Dictionary* pDict,
@@ -35,13 +30,12 @@ static FX_BOOL FPDFDOC_OCG_HasIntent(
return csElement == csDef;
}
CFX_ByteString bsIntent;
- if (pIntent->GetType() == PDFOBJ_ARRAY) {
- FX_DWORD dwCount = ((CPDF_Array*)pIntent)->GetCount();
+ if (CPDF_Array* pArray = pIntent->AsArray()) {
+ FX_DWORD dwCount = pArray->GetCount();
for (FX_DWORD i = 0; i < dwCount; i++) {
- bsIntent = ((CPDF_Array*)pIntent)->GetString(i);
- if (bsIntent == FX_BSTRC("All") || bsIntent == csElement) {
+ bsIntent = pArray->GetString(i);
+ if (bsIntent == FX_BSTRC("All") || bsIntent == csElement)
return TRUE;
- }
}
return FALSE;
}
@@ -206,15 +200,12 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression,
CFX_ByteString csOperator = pExpression->GetString(0);
if (csOperator == FX_BSTRC("Not")) {
pOCGObj = pExpression->GetElementValue(1);
- if (pOCGObj == NULL) {
+ if (!pOCGObj)
return FALSE;
- }
- if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
+ if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict));
- }
- if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
- return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
- }
+ if (CPDF_Array* pArray = pOCGObj->AsArray())
+ return !GetOCGVE(pArray, bFromConfig, nLevel + 1);
return FALSE;
}
if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) {
@@ -225,11 +216,11 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression,
continue;
}
FX_BOOL bItem = FALSE;
- if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
+ if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
- } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
- bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
- }
+ else if (CPDF_Array* pArray = pOCGObj->AsArray())
+ bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1);
+
if (i == 1) {
bValue = bItem;
} else {
@@ -253,38 +244,32 @@ FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict,
}
CFX_ByteString csP = pOCMDDict->GetString(FX_BSTRC("P"), FX_BSTRC("AnyOn"));
CPDF_Object* pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs"));
- if (pOCGObj == NULL) {
+ if (!pOCGObj)
return TRUE;
- }
- if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
+ if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
- }
- if (pOCGObj->GetType() != PDFOBJ_ARRAY) {
+
+ CPDF_Array* pArray = pOCGObj->AsArray();
+ if (!pArray)
return TRUE;
- }
+
FX_BOOL bState = FALSE;
if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) {
bState = TRUE;
}
- int32_t iCount = ((CPDF_Array*)pOCGObj)->GetCount();
+ int32_t iCount = pArray->GetCount();
for (int32_t i = 0; i < iCount; i++) {
FX_BOOL bItem = TRUE;
- CPDF_Dictionary* pItemDict = ((CPDF_Array*)pOCGObj)->GetDict(i);
- if (pItemDict) {
+ CPDF_Dictionary* pItemDict = pArray->GetDict(i);
+ if (pItemDict)
bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict);
- }
- if (csP == FX_BSTRC("AnyOn") && bItem) {
- return TRUE;
- }
- if (csP == FX_BSTRC("AnyOff") && !bItem) {
+
+ if ((csP == FX_BSTRC("AnyOn") && bItem) ||
+ (csP == FX_BSTRC("AnyOff") && !bItem))
return TRUE;
- }
- if (csP == FX_BSTRC("AllOn") && !bItem) {
+ if ((csP == FX_BSTRC("AllOn") && !bItem) ||
+ (csP == FX_BSTRC("AllOff") && bItem))
return FALSE;
- }
- if (csP == FX_BSTRC("AllOff") && bItem) {
- return FALSE;
- }
}
return bState;
}
diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp
index ac29d90118..2b20e07bb8 100644
--- a/core/src/fpdfdoc/doc_tagged.cpp
+++ b/core/src/fpdfdoc/doc_tagged.cpp
@@ -46,48 +46,47 @@ CPDF_StructTreeImpl::~CPDF_StructTreeImpl() {
}
}
void CPDF_StructTreeImpl::LoadDocTree() {
- m_pPage = NULL;
- if (m_pTreeRoot == NULL) {
+ m_pPage = nullptr;
+ if (!m_pTreeRoot)
return;
- }
+
CPDF_Object* pKids = m_pTreeRoot->GetElementValue(FX_BSTRC("K"));
- if (pKids == NULL) {
+ if (!pKids)
return;
- }
if (CPDF_Dictionary* pDict = pKids->AsDictionary()) {
CPDF_StructElementImpl* pStructElementImpl =
- new CPDF_StructElementImpl(this, NULL, pDict);
+ new CPDF_StructElementImpl(this, nullptr, pDict);
m_Kids.Add(pStructElementImpl);
return;
}
- if (pKids->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = pKids->AsArray();
+ if (!pArray)
return;
- }
- CPDF_Array* pArray = (CPDF_Array*)pKids;
+
for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
CPDF_Dictionary* pKid = pArray->GetDict(i);
CPDF_StructElementImpl* pStructElementImpl =
- new CPDF_StructElementImpl(this, NULL, pKid);
+ new CPDF_StructElementImpl(this, nullptr, pKid);
m_Kids.Add(pStructElementImpl);
}
}
void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
m_pPage = pPageDict;
- if (m_pTreeRoot == NULL) {
+ if (!m_pTreeRoot)
return;
- }
+
CPDF_Object* pKids = m_pTreeRoot->GetElementValue(FX_BSTRC("K"));
- if (pKids == NULL) {
+ if (!pKids)
return;
- }
+
FX_DWORD dwKids = 0;
- if (pKids->IsDictionary()) {
+ if (pKids->IsDictionary())
dwKids = 1;
- } else if (pKids->GetType() == PDFOBJ_ARRAY) {
- dwKids = ((CPDF_Array*)pKids)->GetCount();
- } else {
+ else if (CPDF_Array* pArray = pKids->AsArray())
+ dwKids = pArray->GetCount();
+ else
return;
- }
+
FX_DWORD i;
m_Kids.SetSize(dwKids);
for (i = 0; i < dwKids; i++) {
@@ -101,11 +100,10 @@ void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
CPDF_NumberTree parent_tree(pParentTree);
int parents_id = pPageDict->GetInteger(FX_BSTRC("StructParents"), -1);
if (parents_id >= 0) {
- CPDF_Object* pParents = parent_tree.LookupValue(parents_id);
- if (pParents == NULL || pParents->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id));
+ if (!pParentArray)
return;
- }
- CPDF_Array* pParentArray = (CPDF_Array*)pParents;
+
for (i = 0; i < pParentArray->GetCount(); i++) {
CPDF_Dictionary* pParent = pParentArray->GetDict(i);
if (pParent == NULL) {
@@ -171,27 +169,23 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict,
return FALSE;
}
}
- if (pObj->GetType() == PDFOBJ_ARRAY) {
- CPDF_Array* pTopKids = (CPDF_Array*)pObj;
+ if (CPDF_Array* pTopKids = pObj->AsArray()) {
FX_DWORD i;
FX_BOOL bSave = FALSE;
for (i = 0; i < pTopKids->GetCount(); i++) {
CPDF_Object* pKidRef = pTopKids->GetElement(i);
- if (pKidRef == NULL || pKidRef->GetType() != PDFOBJ_REFERENCE) {
+ if (!pKidRef || pKidRef->GetType() != PDFOBJ_REFERENCE)
continue;
- }
- if (((CPDF_Reference*)pKidRef)->GetRefObjNum() != pDict->GetObjNum()) {
+ if (((CPDF_Reference*)pKidRef)->GetRefObjNum() != pDict->GetObjNum())
continue;
- }
- if (m_Kids[i]) {
+
+ if (m_Kids[i])
m_Kids[i]->Release();
- }
m_Kids[i] = pElement->Retain();
bSave = TRUE;
}
- if (!bSave) {
+ if (!bSave)
return FALSE;
- }
}
return TRUE;
}
@@ -231,15 +225,14 @@ void CPDF_StructElementImpl::Release() {
void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) {
CPDF_Object* pObj = pDict->GetElement(FX_BSTRC("Pg"));
FX_DWORD PageObjNum = 0;
- if (pObj && pObj->GetType() == PDFOBJ_REFERENCE) {
+ if (pObj && pObj->GetType() == PDFOBJ_REFERENCE)
PageObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum();
- }
+
CPDF_Object* pKids = pDict->GetElementValue(FX_BSTRC("K"));
- if (pKids == NULL) {
+ if (!pKids)
return;
- }
- if (pKids->GetType() == PDFOBJ_ARRAY) {
- CPDF_Array* pArray = (CPDF_Array*)pKids;
+
+ if (CPDF_Array* pArray = pKids->AsArray()) {
m_Kids.SetSize(pArray->GetCount());
for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
CPDF_Object* pKid = pArray->GetElementValue(i);
@@ -316,25 +309,22 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum,
static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs,
const CFX_ByteStringC& owner,
FX_FLOAT nLevel = 0.0F) {
- if (nLevel > nMaxRecursion) {
- return NULL;
- }
- if (pAttrs == NULL) {
- return NULL;
- }
- CPDF_Dictionary* pDict = NULL;
+ if (nLevel > nMaxRecursion)
+ return nullptr;
+ if (!pAttrs)
+ return nullptr;
+
+ CPDF_Dictionary* pDict = nullptr;
if (pAttrs->IsDictionary()) {
pDict = pAttrs->AsDictionary();
} else if (pAttrs->GetType() == PDFOBJ_STREAM) {
pDict = ((CPDF_Stream*)pAttrs)->GetDict();
- } else if (pAttrs->GetType() == PDFOBJ_ARRAY) {
- CPDF_Array* pArray = (CPDF_Array*)pAttrs;
+ } else if (CPDF_Array* pArray = pAttrs->AsArray()) {
for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
CPDF_Object* pElement = pArray->GetElementValue(i);
pDict = FindAttrDict(pElement, owner, nLevel + 1);
- if (pDict) {
+ if (pDict)
return pDict;
- }
}
}
if (pDict && pDict->GetString(FX_BSTRC("O")) == owner) {
@@ -370,44 +360,40 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner,
}
}
CPDF_Object* pC = m_pDict->GetElementValue(FX_BSTRC("C"));
- if (pC == NULL) {
- return NULL;
- }
+ if (!pC)
+ return nullptr;
+
CPDF_Dictionary* pClassMap =
m_pTree->m_pTreeRoot->GetDict(FX_BSTRC("ClassMap"));
- if (pClassMap == NULL) {
- return NULL;
- }
- if (pC->GetType() == PDFOBJ_ARRAY) {
- CPDF_Array* pArray = (CPDF_Array*)pC;
+ if (!pClassMap)
+ return nullptr;
+
+ if (CPDF_Array* pArray = pC->AsArray()) {
for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
CFX_ByteString class_name = pArray->GetString(i);
CPDF_Dictionary* pClassDict = pClassMap->GetDict(class_name);
- if (pClassDict && pClassDict->GetString(FX_BSTRC("O")) == owner) {
+ if (pClassDict && pClassDict->GetString(FX_BSTRC("O")) == owner)
return pClassDict->GetElementValue(name);
- }
}
- return NULL;
+ return nullptr;
}
CFX_ByteString class_name = pC->GetString();
CPDF_Dictionary* pClassDict = pClassMap->GetDict(class_name);
- if (pClassDict && pClassDict->GetString(FX_BSTRC("O")) == owner) {
+ if (pClassDict && pClassDict->GetString(FX_BSTRC("O")) == owner)
return pClassDict->GetElementValue(name);
- }
- return NULL;
+ return nullptr;
}
CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner,
const CFX_ByteStringC& name,
FX_BOOL bInheritable,
int subindex) {
CPDF_Object* pAttr = GetAttr(owner, name, bInheritable);
- if (pAttr == NULL || subindex == -1 || pAttr->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(pAttr);
+ if (!pArray || subindex == -1)
return pAttr;
- }
- CPDF_Array* pArray = (CPDF_Array*)pAttr;
- if (subindex >= (int)pArray->GetCount()) {
+
+ if (subindex >= static_cast<int>(pArray->GetCount()))
return pAttr;
- }
return pArray->GetElementValue(subindex);
}
CFX_ByteString CPDF_StructElementImpl::GetName(
@@ -427,11 +413,9 @@ FX_ARGB CPDF_StructElementImpl::GetColor(const CFX_ByteStringC& owner,
FX_ARGB default_value,
FX_BOOL bInheritable,
int subindex) {
- CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex);
- if (pAttr == NULL || pAttr->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(GetAttr(owner, name, bInheritable, subindex));
+ if (!pArray)
return default_value;
- }
- CPDF_Array* pArray = (CPDF_Array*)pAttr;
return 0xff000000 | ((int)(pArray->GetNumber(0) * 255) << 16) |
((int)(pArray->GetNumber(1) * 255) << 8) |
(int)(pArray->GetNumber(2) * 255);