diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-20 16:24:45 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-20 16:24:45 -0400 |
commit | f1251c1ff2b3452854681d0648b4c1ca4180ff0d (patch) | |
tree | dbcff41b8f8a5ea3d1d5280ff0c946b9647c301a /core/src/fpdfdoc | |
parent | 49f88b708d905b052bc00769ac7cb48202cac019 (diff) | |
download | pdfium-f1251c1ff2b3452854681d0648b4c1ca4180ff0d.tar.xz |
[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 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r-- | core/src/fpdfdoc/doc_action.cpp | 20 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_annot.cpp | 10 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_basic.cpp | 49 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 26 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_formcontrol.cpp | 14 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_ocg.cpp | 15 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_tagged.cpp | 18 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_utils.cpp | 49 |
8 files changed, 85 insertions, 116 deletions
diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index 759a06c656..409d050484 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -251,13 +251,10 @@ CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { return CPDF_Action(); } CPDF_Object* pNext = m_pDict->GetElementValue("Next"); - int iObjType = pNext->GetType(); - if (iObjType == PDFOBJ_DICTIONARY) { - CPDF_Dictionary* pDict = static_cast<CPDF_Dictionary*>(pNext); - if (iIndex == 0) { + if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { + if (iIndex == 0) return CPDF_Action(pDict); - } - } else if (iObjType == PDFOBJ_ARRAY) { + } else if (pNext->GetType() == PDFOBJ_ARRAY) { CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext); return CPDF_Action(pArray->GetDict(iIndex)); } @@ -295,9 +292,10 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, return CPDF_Action(); } CPDF_Object* pDirect = pObj->GetDirect(); - if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) { + CPDF_Dictionary* pDict = ToDictionary(pDirect); + if (!pDict) return CPDF_Action(); - } + int i = 0; while (g_sAATypes[i][0] != '\0') { if (csKey == g_sAATypes[i]) { @@ -306,7 +304,7 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, i++; } eType = (AActionType)i; - return CPDF_Action(static_cast<CPDF_Dictionary*>(pDirect)); + return CPDF_Action(pDict); } CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { m_pDocument = pDoc; @@ -321,7 +319,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(int index, ASSERT(m_pDocument != NULL); CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); CPDF_Object* pAction = name_tree.LookupValue(index, csName); - if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { + if (!ToDictionary(pAction)) { return CPDF_Action(); } return CPDF_Action(pAction->GetDict()); @@ -330,7 +328,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { ASSERT(m_pDocument != NULL); CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); CPDF_Object* pAction = name_tree.LookupValue(csName); - if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { + if (!ToDictionary(pAction)) { return CPDF_Action(); } return CPDF_Action(pAction->GetDict()); diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp index 57b0665ec4..ca05d783b8 100644 --- a/core/src/fpdfdoc/doc_annot.cpp +++ b/core/src/fpdfdoc/doc_annot.cpp @@ -23,8 +23,8 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) { CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); FX_BOOL bRegenerateAP = pAcroForm && pAcroForm->GetBoolean("NeedAppearances"); for (FX_DWORD i = 0; i < pAnnots->GetCount(); ++i) { - CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i); - if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) { + CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i)); + if (!pDict) { continue; } FX_DWORD dwObjNum = pDict->GetObjNum(); @@ -205,7 +205,7 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Stream* pStream = NULL; if (psub->GetType() == PDFOBJ_STREAM) { pStream = (CPDF_Stream*)psub; - } else if (psub->GetType() == PDFOBJ_DICTIONARY) { + } else if (CPDF_Dictionary* pDict = psub->AsDictionary()) { CFX_ByteString as = pAnnotDict->GetString("AS"); if (as.IsEmpty()) { CFX_ByteString value = pAnnotDict->GetString(FX_BSTRC("V")); @@ -213,13 +213,13 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Dictionary* pDict = pAnnotDict->GetDict(FX_BSTRC("Parent")); value = pDict ? pDict->GetString(FX_BSTRC("V")) : CFX_ByteString(); } - if (value.IsEmpty() || !((CPDF_Dictionary*)psub)->KeyExist(value)) { + if (value.IsEmpty() || !pDict->KeyExist(value)) { as = FX_BSTRC("Off"); } else { as = value; } } - pStream = ((CPDF_Dictionary*)psub)->GetStream(as); + pStream = pDict->GetStream(as); } return pStream; } 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")); } diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 17f1808444..8078608883 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -854,9 +854,9 @@ CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { if (pArray == NULL) { return NULL; } - CPDF_Object* pElement = pArray->GetElementValue(index); - if (pElement != NULL && pElement->GetType() == PDFOBJ_DICTIONARY) { - return GetFieldByDict((CPDF_Dictionary*)pElement); + if (CPDF_Dictionary* pElement = + ToDictionary(pArray->GetElementValue(index))) { + return GetFieldByDict(pElement); } return NULL; } @@ -1049,25 +1049,24 @@ void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { } } } -CPDF_FormField* CPDF_InterForm::AddTerminalField( - const CPDF_Dictionary* pFieldDict) { +CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { if (!pFieldDict->KeyExist(FX_BSTRC("T"))) { return NULL; } - CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFieldDict; - CFX_WideString csWName = GetFullName(pDict); + CPDF_Dictionary* pDict = pFieldDict; + CFX_WideString csWName = GetFullName(pFieldDict); if (csWName.IsEmpty()) { return NULL; } CPDF_FormField* pField = NULL; pField = m_pFieldTree->GetField(csWName); if (pField == NULL) { - CPDF_Dictionary* pParent = (CPDF_Dictionary*)pFieldDict; + CPDF_Dictionary* pParent = pFieldDict; if (!pFieldDict->KeyExist(FX_BSTRC("T")) && pFieldDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget")) { pParent = pFieldDict->GetDict(FX_BSTRC("Parent")); if (!pParent) { - pParent = (CPDF_Dictionary*)pFieldDict; + pParent = pFieldDict; } } if (pParent && pParent != pFieldDict && @@ -1116,15 +1115,14 @@ CPDF_FormField* CPDF_InterForm::AddTerminalField( } return pField; } -CPDF_FormControl* CPDF_InterForm::AddControl( - const CPDF_FormField* pField, - const CPDF_Dictionary* pWidgetDict) { +CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, + CPDF_Dictionary* pWidgetDict) { const auto it = m_ControlMap.find(pWidgetDict); if (it != m_ControlMap.end()) return it->second; - CPDF_FormControl* pControl = new CPDF_FormControl( - (CPDF_FormField*)pField, (CPDF_Dictionary*)pWidgetDict); + CPDF_FormControl* pControl = + new CPDF_FormControl((CPDF_FormField*)pField, pWidgetDict); m_ControlMap[pWidgetDict] = pControl; ((CPDF_FormField*)pField)->m_ControlList.Add(pControl); return pControl; diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp index 410f9a1f21..c5f47d20cb 100644 --- a/core/src/fpdfdoc/doc_formcontrol.cpp +++ b/core/src/fpdfdoc/doc_formcontrol.cpp @@ -61,10 +61,10 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { continue; } CPDF_Object* pObjDirect1 = pObj1->GetDirect(); - if (pObjDirect1->GetType() != PDFOBJ_DICTIONARY) { + CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); + if (!pSubDict) continue; - } - CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)pObjDirect1; + FX_POSITION pos2 = pSubDict->GetStartPos(); while (pos2) { CFX_ByteString csKey2; @@ -287,8 +287,8 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { return nullptr; CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR"); - if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) { - CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font"); + if (CPDF_Dictionary* pDict = ToDictionary(pObj)) { + CPDF_Dictionary* pFonts = pDict->GetDict("Font"); if (pFonts) { CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag); if (pElement) { @@ -304,8 +304,8 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { CPDF_Dictionary* pPageDict = m_pWidgetDict->GetDict("P"); pObj = FPDF_GetFieldAttr(pPageDict, "Resources"); - if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) { - CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font"); + if (CPDF_Dictionary* pDict = ToDictionary(pObj)) { + CPDF_Dictionary* pFonts = pDict->GetDict("Font"); if (pFonts) { CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag); if (pElement) { diff --git a/core/src/fpdfdoc/doc_ocg.cpp b/core/src/fpdfdoc/doc_ocg.cpp index 70ad9c710d..e66b04489f 100644 --- a/core/src/fpdfdoc/doc_ocg.cpp +++ b/core/src/fpdfdoc/doc_ocg.cpp @@ -209,9 +209,8 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, if (pOCGObj == NULL) { return FALSE; } - if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { - return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) - : GetOCGVisible((CPDF_Dictionary*)pOCGObj)); + if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { + return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); } if (pOCGObj->GetType() == PDFOBJ_ARRAY) { return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); @@ -226,9 +225,8 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, continue; } FX_BOOL bItem = FALSE; - if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { - bItem = bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) - : GetOCGVisible((CPDF_Dictionary*)pOCGObj); + if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { + bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); } @@ -258,9 +256,8 @@ FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, if (pOCGObj == NULL) { return TRUE; } - if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { - return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) - : GetOCGVisible((CPDF_Dictionary*)pOCGObj); + if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { + return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); } if (pOCGObj->GetType() != PDFOBJ_ARRAY) { return TRUE; diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp index facad46886..fb3a05d59f 100644 --- a/core/src/fpdfdoc/doc_tagged.cpp +++ b/core/src/fpdfdoc/doc_tagged.cpp @@ -54,9 +54,9 @@ void CPDF_StructTreeImpl::LoadDocTree() { if (pKids == NULL) { return; } - if (pKids->GetType() == PDFOBJ_DICTIONARY) { + if (CPDF_Dictionary* pDict = pKids->AsDictionary()) { CPDF_StructElementImpl* pStructElementImpl = - new CPDF_StructElementImpl(this, NULL, (CPDF_Dictionary*)pKids); + new CPDF_StructElementImpl(this, NULL, pDict); m_Kids.Add(pStructElementImpl); return; } @@ -81,7 +81,7 @@ void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { return; } FX_DWORD dwKids = 0; - if (pKids->GetType() == PDFOBJ_DICTIONARY) { + if (pKids->IsDictionary()) { dwKids = 1; } else if (pKids->GetType() == PDFOBJ_ARRAY) { dwKids = ((CPDF_Array*)pKids)->GetCount(); @@ -161,7 +161,7 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, if (!pObj) { return FALSE; } - if (pObj->GetType() == PDFOBJ_DICTIONARY) { + if (pObj->IsDictionary()) { if (pObj->GetObjNum() == pDict->GetObjNum()) { if (m_Kids[0]) { m_Kids[0]->Release(); @@ -266,10 +266,10 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum, pKid->m_PageContent.m_PageObjNum = PageObjNum; return; } - if (pKidObj->GetType() != PDFOBJ_DICTIONARY) { + CPDF_Dictionary* pKidDict = pKidObj->AsDictionary(); + if (!pKidDict) return; - } - CPDF_Dictionary* pKidDict = (CPDF_Dictionary*)pKidObj; + CPDF_Object* pPageObj = pKidDict->GetElement(FX_BSTRC("Pg")); if (pPageObj && pPageObj->GetType() == PDFOBJ_REFERENCE) { PageObjNum = ((CPDF_Reference*)pPageObj)->GetRefObjNum(); @@ -322,8 +322,8 @@ static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, return NULL; } CPDF_Dictionary* pDict = NULL; - if (pAttrs->GetType() == PDFOBJ_DICTIONARY) { - pDict = (CPDF_Dictionary*)pAttrs; + if (pAttrs->IsDictionary()) { + pDict = pAttrs->AsDictionary(); } else if (pAttrs->GetType() == PDFOBJ_STREAM) { pDict = ((CPDF_Stream*)pAttrs)->GetDict(); } else if (pAttrs->GetType() == PDFOBJ_ARRAY) { diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp index 1ed0017078..7d3fdf2f23 100644 --- a/core/src/fpdfdoc/doc_utils.cpp +++ b/core/src/fpdfdoc/doc_utils.cpp @@ -290,9 +290,8 @@ FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) { if (pObj == NULL) { continue; } - CPDF_Object* pDirect = pObj->GetDirect(); - if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) { - if (((CPDF_Dictionary*)pDirect)->GetString("Type") == "Font") { + if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { + if (pDirect->GetString("Type") == "Font") { dwCount++; } } @@ -323,14 +322,11 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, 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") { + if (pElement->GetString("Type") != "Font") continue; - } if (dwCount == index) { csNameTag = csKey; return pDocument->LoadFont(pElement); @@ -386,18 +382,16 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, 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") { + if (pElement->GetString("Type") != "Font") continue; - } + CPDF_Font* pFind = pDocument->LoadFont(pElement); - if (pFind == NULL) { + if (!pFind) continue; - } + CFX_ByteString csBaseFont; csBaseFont = pFind->GetBaseFont(); csBaseFont.Remove(' '); @@ -431,14 +425,11 @@ CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, 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") { + if (pElement->GetString("Type") != "Font") continue; - } CPDF_Font* pFind = pDocument->LoadFont(pElement); if (pFind == NULL) { continue; @@ -492,11 +483,9 @@ FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, 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; } @@ -534,11 +523,9 @@ FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, 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; } |