From c2bfc000e502c42c9a3017038fd9104c7997d126 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 22 Oct 2015 09:31:44 -0400 Subject: 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 . --- core/src/fpdfdoc/doc_basic.cpp | 54 +++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'core/src/fpdfdoc/doc_basic.cpp') 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_ -- cgit v1.2.3