summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-20 14:57:56 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-20 14:57:56 -0400
commit39869b641511c882d78e17548293cdb458c36f38 (patch)
tree6e7fee229f9c8a5d628c2dfe81b3e9848a9670d2 /fpdfsdk
parent19169dae5bf92813b7419793f61dfca8b4fb9124 (diff)
downloadpdfium-39869b641511c882d78e17548293cdb458c36f38.tar.xz
Revert "Revert "Add type cast definitions for CPDF_Dictionary.""
This reverts commit 937840e1722d1f2b77d80575d6e710d760662c9c. Add type cast definitions for CPDF_Dictionary. This CL adds ToCPDFDictionary type definitions and updates one file to use instead of straight casts. I had to fix two places where we'd casted off the constness of the original pointer. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1420583003 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp8
-rw-r--r--fpdfsdk/src/formfiller/FFL_Utils.cpp2
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp5
-rw-r--r--fpdfsdk/src/fpdf_transformpage.cpp4
-rw-r--r--fpdfsdk/src/fpdfdoc.cpp38
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp7
-rw-r--r--fpdfsdk/src/fpdfppo.cpp18
-rw-r--r--fpdfsdk/src/fpdfview.cpp4
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp3
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp3
10 files changed, 43 insertions, 49 deletions
diff --git a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
index 3a8853cb24..147a0588cc 100644
--- a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
+++ b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
@@ -137,11 +137,9 @@ CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
if (pObj == NULL)
continue;
- CPDF_Object* pDirect = pObj->GetDirect();
- if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY)
+ CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
+ if (!pElement)
continue;
-
- CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
if (pElement->GetString("Type") != "Font")
continue;
@@ -181,7 +179,7 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
// to avoid checkbox and radiobutton
CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
- if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY)
+ if (ToDictionary(pObject))
return;
CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType);
diff --git a/fpdfsdk/src/formfiller/FFL_Utils.cpp b/fpdfsdk/src/formfiller/FFL_Utils.cpp
index d2ce56ac52..a4463b7242 100644
--- a/fpdfsdk/src/formfiller/FFL_Utils.cpp
+++ b/fpdfsdk/src/formfiller/FFL_Utils.cpp
@@ -51,7 +51,7 @@ FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj) {
} break;
case PDFOBJ_DICTIONARY: {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+ CPDF_Dictionary* pDict = pObj->AsDictionary();
FX_POSITION fPos = pDict->GetStartPos();
CFX_ByteString csKey;
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index b2303f36aa..fee93f2663 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -94,11 +94,10 @@ int ParserAnnots(CPDF_Document* pSourceDoc,
FX_DWORD dwSize = pAnnots->GetCount();
for (int i = 0; i < (int)dwSize; i++) {
- CPDF_Object* pObj = pAnnots->GetElementValue(i);
- if (!pObj || pObj->GetType() != PDFOBJ_DICTIONARY)
+ CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetElementValue(i));
+ if (!pAnnotDic)
continue;
- CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
if (sSubtype == "Popup")
continue;
diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp
index cdc646ae7e..1e24b68f08 100644
--- a/fpdfsdk/src/fpdf_transformpage.cpp
+++ b/fpdfsdk/src/fpdf_transformpage.cpp
@@ -166,8 +166,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key);
if (pObj->GetType() == PDFOBJ_REFERENCE)
pObj = pObj->GetDirect();
- if (pObj->GetType() == PDFOBJ_DICTIONARY) {
- pDict = (CPDF_Dictionary*)pObj;
+ if (pObj->IsDictionary()) {
+ pDict = pObj->AsDictionary();
} else if (pObj->GetType() == PDFOBJ_STREAM) {
pDict = ((CPDF_Stream*)pObj)->GetDict();
} else
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index b770295604..ad8ef8bea3 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -56,7 +56,8 @@ FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
if (!pDoc)
return nullptr;
CPDF_BookmarkTree tree(pDoc);
- CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict);
+ CPDF_Bookmark bookmark =
+ CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
return tree.GetFirstChild(bookmark).GetDict();
}
@@ -68,7 +69,8 @@ FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
if (!pDoc)
return nullptr;
CPDF_BookmarkTree tree(pDoc);
- CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict);
+ CPDF_Bookmark bookmark =
+ CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
return tree.GetNextSibling(bookmark).GetDict();
}
@@ -77,7 +79,7 @@ DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict,
unsigned long buflen) {
if (!pDict)
return 0;
- CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
+ CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
CFX_WideString title = bookmark.GetTitle();
CFX_ByteString encodedTitle = title.UTF16LE_Encode();
unsigned long len = encodedTitle.GetLength();
@@ -107,7 +109,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
- CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
+ CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
CPDF_Dest dest = bookmark.GetDest(pDoc);
if (dest)
return dest.GetObject();
@@ -122,7 +124,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) {
if (!pDict)
return NULL;
- CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
+ CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
return bookmark.GetAction().GetDict();
}
@@ -130,7 +132,7 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) {
if (!pDict)
return PDFACTION_UNSUPPORTED;
- CPDF_Action action((CPDF_Dictionary*)pDict);
+ CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
CPDF_Action::ActionType type = action.GetType();
switch (type) {
case CPDF_Action::GoTo:
@@ -153,7 +155,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document,
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
- CPDF_Action action((CPDF_Dictionary*)pDict);
+ CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
return action.GetDest(pDoc).GetObject();
}
@@ -163,7 +165,7 @@ FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) {
if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH)
return 0;
- CPDF_Action action((CPDF_Dictionary*)pDict);
+ CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
CFX_ByteString path = action.GetFilePath().UTF8Encode();
unsigned long len = path.GetLength() + 1;
if (buffer && buflen >= len)
@@ -180,7 +182,7 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document,
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 0;
- CPDF_Action action((CPDF_Dictionary*)pDict);
+ CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
CFX_ByteString path = action.GetURI(pDoc);
unsigned long len = path.GetLength() + 1;
if (buffer && buflen >= len)
@@ -235,7 +237,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document,
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
- CPDF_Link link((CPDF_Dictionary*)pDict);
+ CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict)));
FPDF_DEST dest = link.GetDest(pDoc).GetObject();
if (dest)
return dest;
@@ -250,7 +252,7 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) {
if (!pDict)
return nullptr;
- CPDF_Link link((CPDF_Dictionary*)pDict);
+ CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict)));
return link.GetAction().GetDict();
}
@@ -266,8 +268,9 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page,
if (!pAnnots)
return FALSE;
for (int i = *startPos; i < (int)pAnnots->GetCount(); i++) {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i);
- if (!pDict || pDict->GetType() != PDFOBJ_DICTIONARY)
+ CPDF_Dictionary* pDict =
+ ToDictionary(static_cast<CPDF_Object*>(pAnnots->GetElementValue(i)));
+ if (!pDict)
continue;
if (pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))) {
*startPos = i + 1;
@@ -282,7 +285,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot,
FS_RECTF* rect) {
if (!linkAnnot || !rect)
return FALSE;
- CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
+ CPDF_Dictionary* pAnnotDict =
+ ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect"));
rect->left = rt.left;
rect->bottom = rt.bottom;
@@ -294,7 +298,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot,
DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) {
if (!linkAnnot)
return 0;
- CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
+ CPDF_Dictionary* pAnnotDict =
+ ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
if (!pArray)
return 0;
@@ -306,7 +311,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot,
FS_QUADPOINTSF* quadPoints) {
if (!linkAnnot || !quadPoints)
return FALSE;
- CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
+ CPDF_Dictionary* pAnnotDict =
+ ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
if (pArray) {
if (quadIndex < 0 || quadIndex >= (int)pArray->GetCount() / 8 ||
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index f2d13d6ba1..7b70526b0c 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -103,7 +103,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
else {
if (pDict->KeyExist("Parent")) {
CPDF_Dictionary* pPages =
- (CPDF_Dictionary*)pDict->GetElement("Parent")->GetDirect();
+ ToDictionary(pDict->GetElement("Parent")->GetDirect());
while (pPages) {
if (pPages->KeyExist("Rotate")) {
rotate =
@@ -113,8 +113,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
: 0;
break;
} else if (pPages->KeyExist("Parent"))
- pPages =
- (CPDF_Dictionary*)pPages->GetElement("Parent")->GetDirect();
+ pPages = ToDictionary(pPages->GetElement("Parent")->GetDirect());
else
break;
}
@@ -213,7 +212,7 @@ FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
return TRUE;
CPDF_Dictionary* pSMaskDict =
- pGeneralState ? (CPDF_Dictionary*)pGeneralState->m_pSoftMask : NULL;
+ pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL;
if (pSMaskDict)
return TRUE;
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index 2508adca7b..ab25b76934 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -60,7 +60,7 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
CPDF_Object* pElement = pNewRoot->GetElement("Pages");
CPDF_Dictionary* pNewPages =
- pElement ? (CPDF_Dictionary*)pElement->GetDirect() : nullptr;
+ pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
if (!pNewPages) {
pNewPages = new CPDF_Dictionary;
FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
@@ -183,14 +183,13 @@ CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(
if (pType->GetString().Compare("Page"))
return nullptr;
- CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
- if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY)
+ CPDF_Dictionary* pp = ToDictionary(pDict->GetElement("Parent")->GetDirect());
+ if (!pp)
return nullptr;
if (pDict->KeyExist((const char*)nSrctag))
return pDict->GetElement((const char*)nSrctag);
- CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
while (pp) {
if (pp->KeyExist((const char*)nSrctag)) {
return pp->GetElement((const char*)nSrctag);
@@ -198,12 +197,8 @@ CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(
if (!pp->KeyExist("Parent")) {
break;
}
- pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
- if (pp->GetType() == PDFOBJ_NULL) {
- break;
- }
+ pp = ToDictionary(pp->GetElement("Parent")->GetDirect());
}
-
return nullptr;
}
@@ -220,7 +215,7 @@ FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
break;
}
case PDFOBJ_DICTIONARY: {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+ CPDF_Dictionary* pDict = pObj->AsDictionary();
FX_POSITION pos = pDict->GetStartPos();
while (pos) {
@@ -291,8 +286,7 @@ FX_DWORD CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
if (!pClone)
return 0;
- if (pClone->GetType() == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
+ if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) {
if (pDictClone->KeyExist("Type")) {
CFX_ByteString strType = pDictClone->GetString("Type");
if (!FXSYS_stricmp(strType, "Pages")) {
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 19faea5cc9..0d6dcf29f1 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -882,8 +882,8 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
}
if (!pDestObj)
return NULL;
- if (pDestObj->GetType() == PDFOBJ_DICTIONARY) {
- pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D"));
+ if (CPDF_Dictionary* pDict = pDestObj->AsDictionary()) {
+ pDestObj = pDict->GetArray(FX_BSTRC("D"));
if (!pDestObj)
return NULL;
}
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index 7d0346c797..b4aa822bb6 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -65,8 +65,7 @@ FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
return psub->GetType() == PDFOBJ_STREAM;
case FIELDTYPE_CHECKBOX:
case FIELDTYPE_RADIOBUTTON:
- if (psub->GetType() == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
+ if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
return pSubDict->GetStream(GetAppState()) != NULL;
}
return FALSE;
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 883ad60a93..4cf05a2d79 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -480,8 +480,7 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() {
if (pOpenAction->GetType() == PDFOBJ_ARRAY)
return TRUE;
- if (pOpenAction->GetType() == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pOpenAction;
+ if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) {
CPDF_Action action(pDict);
if (m_pEnv->GetActionHander())
m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);