From 967aa0793c0b0cf2722ec8720e9d797266a9fde7 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 8 May 2018 13:40:20 +0000 Subject: Rename CPDF_Document::GetPage() to GetPageDictionary(). Avoids a conflict should we wish to have the document actually track pages, with a GetPage() that returns CPDF_Page. Do the same thing to CPDF_DataAvail along the way. Add some missing consts as well. Change-Id: I2cb2213cc4c0649662fceab80407ee4a3f4cf30e Reviewed-on: https://pdfium-review.googlesource.com/32158 Commit-Queue: dsinclair Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_data_avail.cpp | 18 ++++++------- core/fpdfapi/parser/cpdf_data_avail.h | 6 ++--- core/fpdfapi/parser/cpdf_document.cpp | 2 +- core/fpdfapi/parser/cpdf_document.h | 2 +- core/fpdfapi/parser/cpdf_document_unittest.cpp | 36 +++++++++++++------------- 5 files changed, 32 insertions(+), 32 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index e871e0a578..3ffe6f6f0b 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -475,7 +475,7 @@ bool CPDF_DataAvail::CheckHintTables() { std::unique_ptr CPDF_DataAvail::ParseIndirectObjectAt( FX_FILESIZE pos, uint32_t objnum, - CPDF_IndirectObjectHolder* pObjList) { + CPDF_IndirectObjectHolder* pObjList) const { const FX_FILESIZE SavedPos = GetSyntaxParser()->GetPos(); GetSyntaxParser()->SetPos(pos); std::unique_ptr result = GetSyntaxParser()->GetIndirectObject( @@ -828,7 +828,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( if (m_pLinearized) { if (dwPage == m_pLinearized->GetFirstPageNo()) { - CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); + auto* pPageDict = m_pDocument->GetPageDictionary(safePage.ValueOrDie()); if (!pPageDict) return DataError; @@ -850,7 +850,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( nResult = m_pHintTables->CheckPage(dwPage); if (nResult != DataAvailable) return nResult; - if (GetPage(dwPage)) { + if (GetPageDictionary(dwPage)) { m_pagesLoadState.insert(dwPage); return DataAvailable; } @@ -879,7 +879,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( if (CheckAcroForm() == DocFormStatus::FormNotAvailable) return DataNotAvailable; - CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); + auto* pPageDict = m_pDocument->GetPageDictionary(safePage.ValueOrDie()); if (!pPageDict) return DataError; @@ -943,10 +943,10 @@ int CPDF_DataAvail::GetPageCount() const { return m_pDocument ? m_pDocument->GetPageCount() : 0; } -CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { +CPDF_Dictionary* CPDF_DataAvail::GetPageDictionary(int index) const { if (!m_pDocument || index < 0 || index >= GetPageCount()) return nullptr; - CPDF_Dictionary* page = m_pDocument->GetPage(index); + CPDF_Dictionary* page = m_pDocument->GetPageDictionary(index); if (page) return page; if (!m_pLinearized || !m_pHintTables) @@ -970,7 +970,7 @@ CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { } if (!ValidatePage(index)) return nullptr; - return m_pDocument->GetPage(index); + return m_pDocument->GetPageDictionary(index); } CPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( @@ -1016,9 +1016,9 @@ CPDF_DataAvail::DocFormStatus CPDF_DataAvail::CheckAcroForm() { return DocFormStatus::FormError; } -bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) { +bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) const { FX_SAFE_INT32 safePage = pdfium::base::checked_cast(dwPage); - CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); + auto* pPageDict = m_pDocument->GetPageDictionary(safePage.ValueOrDie()); if (!pPageDict) return false; CPDF_PageObjectAvail obj_avail(GetValidator().Get(), m_pDocument, pPageDict); diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index dfb1f0cabf..2a0705d33d 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -102,7 +102,7 @@ class CPDF_DataAvail final { DocLinearizationStatus IsLinearizedPDF(); RetainPtr GetFileRead() const; int GetPageCount() const; - CPDF_Dictionary* GetPage(int index); + CPDF_Dictionary* GetPageDictionary(int index) const; RetainPtr GetValidator() const; std::pair> ParseDocument( @@ -139,7 +139,7 @@ class CPDF_DataAvail final { std::unique_ptr ParseIndirectObjectAt( FX_FILESIZE pos, uint32_t objnum, - CPDF_IndirectObjectHolder* pObjList = nullptr); + CPDF_IndirectObjectHolder* pObjList = nullptr) const; std::unique_ptr GetObject(uint32_t objnum, bool* pExistInFile); bool GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); @@ -161,7 +161,7 @@ class CPDF_DataAvail final { bool CheckPageCount(); bool IsFirstCheck(uint32_t dwPage); void ResetFirstCheck(uint32_t dwPage); - bool ValidatePage(uint32_t dwPage); + bool ValidatePage(uint32_t dwPage) const; CPDF_SyntaxParser* GetSyntaxParser() const; FileAvail* const m_pFileAvail; diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 32350b7551..13f5db244b 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -331,7 +331,7 @@ bool CPDF_Document::IsPageLoaded(int iPage) const { return !!m_PageList[iPage]; } -CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { +CPDF_Dictionary* CPDF_Document::GetPageDictionary(int iPage) { if (!pdfium::IndexInBounds(m_PageList, iPage)) return nullptr; diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index 5ee3c77bb5..8690efed80 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -65,7 +65,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { void DeletePage(int iPage); int GetPageCount() const; bool IsPageLoaded(int iPage) const; - CPDF_Dictionary* GetPage(int iPage); + CPDF_Dictionary* GetPageDictionary(int iPage); int GetPageIndex(uint32_t objnum); uint32_t GetUserPermissions() const; diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index d1b8dce74a..f06a7f42d3 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -164,22 +164,22 @@ TEST_F(cpdf_document_test, GetPages) { std::unique_ptr document = pdfium::MakeUnique(); for (int i = 0; i < kNumTestPages; i++) { - CPDF_Dictionary* page = document->GetPage(i); + CPDF_Dictionary* page = document->GetPageDictionary(i); ASSERT_TRUE(page); ASSERT_TRUE(page->KeyExist("PageNumbering")); EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); } - CPDF_Dictionary* page = document->GetPage(kNumTestPages); + CPDF_Dictionary* page = document->GetPageDictionary(kNumTestPages); EXPECT_FALSE(page); } TEST_F(cpdf_document_test, GetPageWithoutObjNumTwice) { auto document = pdfium::MakeUnique(); - const CPDF_Dictionary* page = document->GetPage(2); + CPDF_Dictionary* page = document->GetPageDictionary(2); ASSERT_TRUE(page); ASSERT_EQ(document->inlined_page(), page); - const CPDF_Dictionary* second_call_page = document->GetPage(2); + CPDF_Dictionary* second_call_page = document->GetPageDictionary(2); EXPECT_TRUE(second_call_page); EXPECT_EQ(page, second_call_page); } @@ -188,12 +188,12 @@ TEST_F(cpdf_document_test, GetPagesReverseOrder) { std::unique_ptr document = pdfium::MakeUnique(); for (int i = 6; i >= 0; i--) { - CPDF_Dictionary* page = document->GetPage(i); + CPDF_Dictionary* page = document->GetPageDictionary(i); ASSERT_TRUE(page); ASSERT_TRUE(page->KeyExist("PageNumbering")); EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); } - CPDF_Dictionary* page = document->GetPage(kNumTestPages); + CPDF_Dictionary* page = document->GetPageDictionary(kNumTestPages); EXPECT_FALSE(page); } @@ -201,20 +201,20 @@ TEST_F(cpdf_document_test, GetPagesInDisorder) { std::unique_ptr document = pdfium::MakeUnique(); - CPDF_Dictionary* page = document->GetPage(1); + CPDF_Dictionary* page = document->GetPageDictionary(1); ASSERT_TRUE(page); ASSERT_TRUE(page->KeyExist("PageNumbering")); EXPECT_EQ(1, page->GetIntegerFor("PageNumbering")); - page = document->GetPage(3); + page = document->GetPageDictionary(3); ASSERT_TRUE(page); ASSERT_TRUE(page->KeyExist("PageNumbering")); EXPECT_EQ(3, page->GetIntegerFor("PageNumbering")); - page = document->GetPage(kNumTestPages); + page = document->GetPageDictionary(kNumTestPages); EXPECT_FALSE(page); - page = document->GetPage(6); + page = document->GetPageDictionary(6); ASSERT_TRUE(page); ASSERT_TRUE(page->KeyExist("PageNumbering")); EXPECT_EQ(6, page->GetIntegerFor("PageNumbering")); @@ -237,11 +237,11 @@ TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { const int test_page_num = 33; EXPECT_FALSE(document.IsPageLoaded(test_page_num)); - EXPECT_EQ(nullptr, document.GetPage(test_page_num)); + EXPECT_EQ(nullptr, document.GetPageDictionary(test_page_num)); document.SetPageObjNum(test_page_num, obj_num); EXPECT_TRUE(document.IsPageLoaded(test_page_num)); - EXPECT_EQ(page_stub, document.GetPage(test_page_num)); + EXPECT_EQ(page_stub, document.GetPageDictionary(test_page_num)); } TEST_F(cpdf_document_test, CountGreaterThanPageTree) { @@ -249,19 +249,19 @@ TEST_F(cpdf_document_test, CountGreaterThanPageTree) { pdfium::MakeUnique(); document->SetTreeSize(kNumTestPages + 3); for (int i = 0; i < kNumTestPages; i++) - EXPECT_TRUE(document->GetPage(i)); + EXPECT_TRUE(document->GetPageDictionary(i)); for (int i = kNumTestPages; i < kNumTestPages + 4; i++) - EXPECT_FALSE(document->GetPage(i)); - EXPECT_TRUE(document->GetPage(kNumTestPages - 1)); + EXPECT_FALSE(document->GetPageDictionary(i)); + EXPECT_TRUE(document->GetPageDictionary(kNumTestPages - 1)); } TEST_F(cpdf_document_test, PagesWithoutKids) { // Set up a document with Pages dict without kids, and Count = 3 auto pDoc = pdfium::MakeUnique(); - EXPECT_TRUE(pDoc->GetPage(0)); + EXPECT_TRUE(pDoc->GetPageDictionary(0)); // Test GetPage does not fetch pages out of range for (int i = 1; i < 5; i++) - EXPECT_FALSE(pDoc->GetPage(i)); + EXPECT_FALSE(pDoc->GetPageDictionary(i)); - EXPECT_TRUE(pDoc->GetPage(0)); + EXPECT_TRUE(pDoc->GetPageDictionary(0)); } -- cgit v1.2.3