[Merge to XFA] 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 .
(cherry picked from commit 39869b641511c882d78e17548293cdb458c36f38)
Review URL: https://codereview.chromium.org/1410343003 .
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index b770295..ad8ef8b 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -56,7 +56,8 @@
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 @@
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 @@
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 @@
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_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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 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 @@
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 ||