From b1ec280837cc6e1932754ef40de26d12b77aa910 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 25 May 2018 21:55:24 +0000 Subject: Add proper const/non-const versions of CPDF_Dictionary::GetDictFor(). BUG=pdfium:234 Change-Id: I6fde00c976ad4bb9cab632f465cf292f5b1da3d2 Reviewed-on: https://pdfium-review.googlesource.com/32914 Commit-Queue: Lei Zhang Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_document.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_document.cpp') diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 5264d4e795..5479a06174 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -322,11 +322,16 @@ void CPDF_Document::ResetTraversal() { m_pTreeTraversal.clear(); } -CPDF_Dictionary* CPDF_Document::GetPagesDict() const { +const CPDF_Dictionary* CPDF_Document::GetPagesDict() const { const CPDF_Dictionary* pRoot = GetRoot(); return pRoot ? pRoot->GetDictFor("Pages") : nullptr; } +CPDF_Dictionary* CPDF_Document::GetPagesDict() { + CPDF_Dictionary* pRoot = GetRoot(); + return pRoot ? pRoot->GetDictFor("Pages") : nullptr; +} + bool CPDF_Document::IsPageLoaded(int iPage) const { return !!m_PageList[iPage]; } @@ -363,7 +368,7 @@ void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { m_PageList[iPage] = objNum; } -int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, +int CPDF_Document::FindPageIndex(const CPDF_Dictionary* pNode, uint32_t* skip_count, uint32_t objnum, int* index, @@ -379,7 +384,7 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, return -1; } - CPDF_Array* pKidList = pNode->GetArrayFor("Kids"); + const CPDF_Array* pKidList = pNode->GetArrayFor("Kids"); if (!pKidList) return -1; @@ -395,14 +400,14 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, if (count && count == pKidList->GetCount()) { for (size_t i = 0; i < count; i++) { - CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i)); + const CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i)); if (pKid && pKid->GetRefObjNum() == objnum) return static_cast(*index + i); } } for (size_t i = 0; i < pKidList->GetCount(); i++) { - CPDF_Dictionary* pKid = pKidList->GetDictAt(i); + const CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid || pKid == pNode) continue; @@ -426,7 +431,7 @@ int CPDF_Document::GetPageIndex(uint32_t objnum) { bSkipped = true; } } - CPDF_Dictionary* pPages = GetPagesDict(); + const CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) return -1; @@ -445,7 +450,7 @@ int CPDF_Document::GetPageCount() const { return pdfium::CollectionSize(m_PageList); } -int CPDF_Document::RetrievePageCount() const { +int CPDF_Document::RetrievePageCount() { CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) return 0; @@ -576,7 +581,7 @@ bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, } bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) { - const CPDF_Dictionary* pRoot = GetRoot(); + CPDF_Dictionary* pRoot = GetRoot(); CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr; if (!pPages) return false; -- cgit v1.2.3