summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_basic.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-22 15:02:06 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-22 15:02:06 -0400
commit2b11dc1220746d2f6f97a940fc9e4235c8ed4975 (patch)
treee25b2ba13112f4ead789260ee57fe5b40c13b83e /core/src/fpdfdoc/doc_basic.cpp
parentbc6c6723c37772b02de9e6e43fa0fd9439874905 (diff)
downloadpdfium-2b11dc1220746d2f6f97a940fc9e4235c8ed4975.tar.xz
Merge to XFA: Add type cast definitions for CPDF_Array.
This Cl adds ToArray, CPDF_Object::AsArray and CPDF_Object::IsArray and updates the src to use them as needed. BUG=pdfium:201 R=thestig@chromium.org, tsepez@chromium.org Review URL: https://codereview.chromium.org/1417893003 . (cherry picked from commit c2bfc000e502c42c9a3017038fd9104c7997d126) Review URL: https://codereview.chromium.org/1419643005 .
Diffstat (limited to 'core/src/fpdfdoc/doc_basic.cpp')
-rw-r--r--core/src/fpdfdoc/doc_basic.cpp54
1 files changed, 24 insertions, 30 deletions
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_