Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2087)

Unified Diff: core/src/fpdfdoc/doc_basic.cpp

Issue 1420583003: Revert "Revert "Add type cast definitions for CPDF_Dictionary."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdfdoc/doc_form.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfdoc/doc_basic.cpp
diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp
index 39b5788c86c0543bf46a881e0d1777ce603ed0a3..e3b630862c4e140e7c71530b9ff8837348715dea 100644
--- a/core/src/fpdfdoc/doc_basic.cpp
+++ b/core/src/fpdfdoc/doc_basic.cpp
@@ -17,7 +17,7 @@ int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
if (pPage->GetType() == PDFOBJ_NUMBER) {
return pPage->GetInteger();
}
- if (pPage->GetType() != PDFOBJ_DICTIONARY) {
+ if (!pPage->IsDictionary()) {
return 0;
}
return pDoc->GetPageIndex(pPage->GetObjNum());
@@ -33,7 +33,7 @@ FX_DWORD CPDF_Dest::GetPageObjNum() {
if (pPage->GetType() == PDFOBJ_NUMBER) {
return pPage->GetInteger();
}
- if (pPage->GetType() == PDFOBJ_DICTIONARY) {
+ if (pPage->IsDictionary()) {
return pPage->GetObjNum();
}
return 0;
@@ -243,8 +243,8 @@ CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
if (pValue->GetType() == PDFOBJ_ARRAY) {
return (CPDF_Array*)pValue;
}
- if (pValue->GetType() == PDFOBJ_DICTIONARY) {
- return ((CPDF_Dictionary*)pValue)->GetArray(FX_BSTRC("D"));
+ if (CPDF_Dictionary* pDict = pValue->AsDictionary()) {
+ return pDict->GetArray(FX_BSTRC("D"));
}
return NULL;
}
@@ -311,11 +311,10 @@ static CFX_WideString FILESPEC_DecodeFileName(const CFX_WideStringC& filepath) {
#endif
}
FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const {
- if (m_pObj == NULL) {
+ if (!m_pObj) {
return FALSE;
}
- if (m_pObj->GetType() == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj;
+ if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) {
csFileName = pDict->GetUnicodeText(FX_BSTRC("UF"));
if (csFileName.IsEmpty()) {
csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F")));
@@ -345,20 +344,15 @@ FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const {
}
CPDF_FileSpec::CPDF_FileSpec() {
m_pObj = CPDF_Dictionary::Create();
- if (m_pObj != NULL) {
- ((CPDF_Dictionary*)m_pObj)
- ->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec"));
+ if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) {
+ pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec"));
}
}
FX_BOOL CPDF_FileSpec::IsURL() const {
- if (m_pObj == NULL) {
- return FALSE;
- }
- if (m_pObj->GetType() != PDFOBJ_DICTIONARY) {
- return FALSE;
+ if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) {
+ return pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL");
}
- return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) ==
- FX_BSTRC("URL");
+ return FALSE;
}
CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) {
if (filepath.GetLength() <= 1) {
@@ -402,15 +396,10 @@ CPDF_Stream* CPDF_FileSpec::GetFileStream() const {
return NULL;
}
int32_t iType = m_pObj->GetType();
- if (iType == PDFOBJ_STREAM) {
+ if (iType == PDFOBJ_STREAM)
return (CPDF_Stream*)m_pObj;
- } else if (iType == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF"));
- if (pEF == NULL) {
- return NULL;
- }
+ if (CPDF_Dictionary* pEF = m_pObj->AsDictionary()->GetDict(FX_BSTRC("EF")))
return pEF->GetStream(FX_BSTRC("F"));
- }
return NULL;
}
static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj,
@@ -426,8 +415,7 @@ static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj,
int32_t iType = pObj->GetType();
if (iType == PDFOBJ_STRING) {
pObj->SetString(CFX_ByteString::FromUnicode(wsStr));
- } else if (iType == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+ } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) {
pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr));
pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr));
}
@@ -435,8 +423,10 @@ static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj,
void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName,
FX_BOOL bURL) {
ASSERT(m_pObj != NULL);
- if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) {
- ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL");
+ if (bURL) {
+ if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) {
+ pDict->SetAtName(FX_BSTRC("FS"), "URL");
+ }
}
FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL);
}
@@ -517,8 +507,7 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
}
if (pValue != NULL) {
pValue = pValue->GetDirect();
- if (pValue->GetType() == PDFOBJ_DICTIONARY) {
- CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue;
+ if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) {
if (pLabel->KeyExist(FX_BSTRC("P"))) {
wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P"));
}
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdfdoc/doc_form.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698