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 . --- fpdfsdk/src/fpdfppo.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'fpdfsdk/src/fpdfppo.cpp') 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")) { -- cgit v1.2.3