summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-22 09:31:44 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-22 09:31:44 -0400
commitc2bfc000e502c42c9a3017038fd9104c7997d126 (patch)
treea693dd82199e7af83fac7b7b19d023e4c5fc5e36 /fpdfsdk/src
parent69ceb6a9761b3ccb228a2405e9a493a3666e0601 (diff)
downloadpdfium-c2bfc000e502c42c9a3017038fd9104c7997d126.tar.xz
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 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp2
-rw-r--r--fpdfsdk/src/fpdf_transformpage.cpp40
-rw-r--r--fpdfsdk/src/fpdfdoc.cpp2
-rw-r--r--fpdfsdk/src/fpdfppo.cpp2
-rw-r--r--fpdfsdk/src/fpdfview.cpp9
-rw-r--r--fpdfsdk/src/fsdk_actionhandler.cpp14
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp2
7 files changed, 37 insertions, 34 deletions
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index fee93f2663..f4d49ce182 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -226,7 +226,7 @@ void SetPageContents(CFX_ByteString key,
}
case PDFOBJ_ARRAY: {
- pContentsArray = (CPDF_Array*)pContentsObj;
+ pContentsArray = pContentsObj->AsArray();
break;
}
default:
diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp
index 1e24b68f08..d2ad26bf64 100644
--- a/fpdfsdk/src/fpdf_transformpage.cpp
+++ b/fpdfsdk/src/fpdf_transformpage.cpp
@@ -109,14 +109,15 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
textBuf << bsMatix;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
- CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL;
+ CPDF_Object* pContentObj =
+ pPageDic ? pPageDic->GetElement("Contents") : nullptr;
if (!pContentObj)
- pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL;
+ pContentObj = pPageDic ? pPageDic->GetArray("Contents") : nullptr;
if (!pContentObj)
return FALSE;
CPDF_Dictionary* pDic = new CPDF_Dictionary;
- CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic);
+ CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
CPDF_Document* pDoc = pPage->m_pDocument;
if (!pDoc)
@@ -124,22 +125,22 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
pDoc->AddIndirectObject(pStream);
pDic = new CPDF_Dictionary;
- CPDF_Stream* pEndStream = new CPDF_Stream(NULL, 0, pDic);
+ CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic);
pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE);
pDoc->AddIndirectObject(pEndStream);
- CPDF_Array* pContentArray = NULL;
- if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) {
- pContentArray = (CPDF_Array*)pContentObj;
+ CPDF_Array* pContentArray = nullptr;
+ if (CPDF_Array* pArray = ToArray(pContentObj)) {
+ pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc, pEndStream);
} else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) {
CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
CPDF_Object* pDirectObj = pReference->GetDirect();
- if (pDirectObj != NULL) {
- if (pDirectObj->GetType() == PDFOBJ_ARRAY) {
- pContentArray = (CPDF_Array*)pDirectObj;
+ if (pDirectObj) {
+ if (CPDF_Array* pArray = pDirectObj->AsArray()) {
+ pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc, pEndStream);
@@ -267,9 +268,10 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
return;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
- CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL;
+ CPDF_Object* pContentObj =
+ pPageDic ? pPageDic->GetElement("Contents") : nullptr;
if (!pContentObj)
- pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL;
+ pContentObj = pPageDic ? pPageDic->GetArray("Contents") : nullptr;
if (!pContentObj)
return;
@@ -291,24 +293,24 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
}
}
CPDF_Dictionary* pDic = new CPDF_Dictionary;
- CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic);
+ CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
CPDF_Document* pDoc = pPage->m_pDocument;
if (!pDoc)
return;
pDoc->AddIndirectObject(pStream);
- CPDF_Array* pContentArray = NULL;
- if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) {
- pContentArray = (CPDF_Array*)pContentObj;
+ CPDF_Array* pContentArray = nullptr;
+ if (CPDF_Array* pArray = ToArray(pContentObj)) {
+ pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
} else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) {
CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
CPDF_Object* pDirectObj = pReference->GetDirect();
- if (pDirectObj != NULL) {
- if (pDirectObj->GetType() == PDFOBJ_ARRAY) {
- pContentArray = (CPDF_Array*)pDirectObj;
+ if (pDirectObj) {
+ if (CPDF_Array* pArray = pDirectObj->AsArray()) {
+ pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
} else if (pDirectObj->GetType() == PDFOBJ_STREAM) {
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index ad8ef8bea3..8a4d619292 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -197,7 +197,7 @@ DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document,
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 0;
- CPDF_Dest dest((CPDF_Array*)pDict);
+ CPDF_Dest dest(static_cast<CPDF_Array*>(pDict));
return dest.GetPageIndex(pDoc);
}
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index d50e98f0ac..7b589b585f 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -235,7 +235,7 @@ FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
break;
}
case PDFOBJ_ARRAY: {
- CPDF_Array* pArray = (CPDF_Array*)pObj;
+ CPDF_Array* pArray = pObj->AsArray();
FX_DWORD count = pArray->GetCount();
for (FX_DWORD i = 0; i < count; ++i) {
CPDF_Object* pNextObj = pArray->GetElement(i);
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index c8c2c73c9a..97da89e296 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -885,14 +885,15 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
pDestObj = nameTree.LookupValue(index, bsName);
}
if (!pDestObj)
- return NULL;
+ return nullptr;
if (CPDF_Dictionary* pDict = pDestObj->AsDictionary()) {
pDestObj = pDict->GetArray(FX_BSTRC("D"));
if (!pDestObj)
- return NULL;
+ return nullptr;
}
- if (pDestObj->GetType() != PDFOBJ_ARRAY)
- return NULL;
+ if (!pDestObj->IsArray())
+ return nullptr;
+
CFX_WideString wsName = PDF_DecodeText(bsName);
CFX_ByteString utf16Name = wsName.UTF16LE_Encode();
unsigned int len = utf16Name.GetLength();
diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp
index 874fcc7ff5..023dc5b2fa 100644
--- a/fpdfsdk/src/fsdk_actionhandler.cpp
+++ b/fpdfsdk/src/fsdk_actionhandler.cpp
@@ -425,7 +425,7 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action,
}
FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) {
- ASSERT(pDocument != NULL);
+ ASSERT(pDocument);
return TRUE;
}
@@ -434,17 +434,15 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
ASSERT(action);
CPDF_Document* pPDFDocument = pDocument->GetDocument();
- ASSERT(pPDFDocument != NULL);
- CPDFDoc_Environment* pApp = pDocument->GetEnv();
- ASSERT(pApp != NULL);
+ ASSERT(pPDFDocument);
CPDF_Dest MyDest = action.GetDest(pPDFDocument);
int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
int nFitType = MyDest.GetZoomMode();
- const CPDF_Array* pMyArray = (CPDF_Array*)MyDest.GetObject();
- float* pPosAry = NULL;
+ const CPDF_Array* pMyArray = ToArray(MyDest.GetObject());
+ float* pPosAry = nullptr;
int sizeOfAry = 0;
- if (pMyArray != NULL) {
+ if (pMyArray) {
pPosAry = new float[pMyArray->GetCount()];
int j = 0;
for (int i = 2; i < (int)pMyArray->GetCount(); i++) {
@@ -452,6 +450,8 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
}
sizeOfAry = j;
}
+
+ CPDFDoc_Environment* pApp = pDocument->GetEnv();
pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
delete[] pPosAry;
}
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index fccfbe9aa2..f43a45b1f7 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -479,7 +479,7 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() {
if (!pOpenAction)
return FALSE;
- if (pOpenAction->GetType() == PDFOBJ_ARRAY)
+ if (pOpenAction->IsArray())
return TRUE;
if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) {