summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
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.cpp33
-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, 51 insertions, 56 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 0cf7c880af..42ab3eb694 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -107,7 +107,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 =
@@ -117,8 +117,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;
}
@@ -217,7 +216,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 ed2446471e..6521258485 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -59,10 +59,10 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
}
- CPDF_Dictionary* pNewPages =
- (CPDF_Dictionary*)(pNewRoot->GetElement("Pages")
- ? pNewRoot->GetElement("Pages")->GetDirect()
- : NULL);
+ CPDF_Dictionary* pNewPages = ToDictionary(
+ pNewRoot->GetElement("Pages") ? pNewRoot->GetElement("Pages")->GetDirect()
+ : nullptr);
+
if (!pNewPages) {
pNewPages = new CPDF_Dictionary;
FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
@@ -191,29 +191,25 @@ CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(
if (pType->GetString().Compare("Page"))
return NULL;
-
if (!pDict->KeyExist("Parent"))
return NULL;
- CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
- if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY)
- return NULL;
- CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
+ CPDF_Dictionary* pp = ToDictionary(pDict->GetElement("Parent")->GetDirect());
+ if (!pp)
+ return nullptr;
if (pDict->KeyExist((const char*)nSrctag))
return pDict->GetElement((const char*)nSrctag);
+
while (pp) {
if (pp->KeyExist((const char*)nSrctag))
return pp->GetElement((const char*)nSrctag);
- if (pp->KeyExist("Parent")) {
- pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
- if (pp->GetType() == PDFOBJ_NULL)
- break;
- } else
+ if (!pp->KeyExist("Parent")) {
break;
+ }
+ pp = ToDictionary(pp->GetElement("Parent")->GetDirect());
}
-
- return NULL;
+ return nullptr;
}
FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
@@ -229,7 +225,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) {
@@ -300,8 +296,7 @@ int CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
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 cfc2f0db04..c2157e96bd 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -1051,8 +1051,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 3dc48dab53..d7374a6f18 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -538,8 +538,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 fb5df1ea5e..63ed642367 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -485,8 +485,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);