From f1251c1ff2b3452854681d0648b4c1ca4180ff0d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 20 Oct 2015 16:24:45 -0400 Subject: [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 . --- core/src/fpdfdoc/doc_basic.cpp | 49 ++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'core/src/fpdfdoc/doc_basic.cpp') diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp index 39b5788c86..e3b630862c 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")); } -- cgit v1.2.3