From 2c47fb2c9b3db7be3480cbc044fa90fda988b97f Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Mon, 26 Mar 2018 20:17:29 +0000 Subject: Do not call CPDF_PageObjectList directly in fpdfeditpage.cpp. Change-Id: If816c4f532f03513ad06959182b0e0edfd688e39 Reviewed-on: https://pdfium-review.googlesource.com/29170 Reviewed-by: dsinclair Commit-Queue: Henrique Nakashima --- core/fpdfapi/page/cpdf_page.cpp | 14 -------------- core/fpdfapi/page/cpdf_page.h | 1 - core/fpdfapi/page/cpdf_pageobjectholder.cpp | 28 ++++++++++++++++++++++++++++ core/fpdfapi/page/cpdf_pageobjectholder.h | 6 ++++++ core/fpdfapi/page/cpdf_pageobjectlist.cpp | 2 +- core/fpdfapi/page/cpdf_pageobjectlist.h | 2 +- 6 files changed, 36 insertions(+), 17 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 6518d80aa3..e5d7f381a5 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -186,20 +186,6 @@ int CPDF_Page::GetPageRotation() const { return (rotate < 0) ? (rotate + 4) : rotate; } -bool CPDF_Page::RemoveObject(CPDF_PageObject* pPageObj) { - pdfium::FakeUniquePtr p(pPageObj); - - auto* pPageObjectList = GetPageObjectList(); - auto it = - std::find(std::begin(*pPageObjectList), std::end(*pPageObjectList), p); - if (it == std::end(*pPageObjectList)) - return false; - - it->release(); - pPageObjectList->erase(it); - return true; -} - bool GraphicsData::operator<(const GraphicsData& other) const { if (fillAlpha != other.fillAlpha) return fillAlpha < other.fillAlpha; diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index 995d99cf4e..c7aa12e474 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -54,7 +54,6 @@ class CPDF_Page : public CPDF_PageObjectHolder { View* GetView() const { return m_pView; } void SetView(View* pView) { m_pView = pView; } - bool RemoveObject(CPDF_PageObject* pPageObj); private: void StartParse(); diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 9413ffbfae..67b356fc57 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -7,6 +7,7 @@ #include "core/fpdfapi/page/cpdf_pageobjectholder.h" #include +#include #include "core/fpdfapi/page/cpdf_allstates.h" #include "core/fpdfapi/page/cpdf_contentparser.h" @@ -91,3 +92,30 @@ void CPDF_PageObjectHolder::LoadTransInfo() { m_iTransparency |= PDFTRANS_KNOCKOUT; } } + +size_t CPDF_PageObjectHolder::GetPageObjectCount() const { + return pdfium::CollectionSize(m_PageObjectList); +} + +CPDF_PageObject* CPDF_PageObjectHolder::GetPageObjectByIndex( + size_t index) const { + return m_PageObjectList.GetPageObjectByIndex(index); +} + +void CPDF_PageObjectHolder::AppendPageObject( + std::unique_ptr pPageObj) { + m_PageObjectList.push_back(std::move(pPageObj)); +} + +bool CPDF_PageObjectHolder::RemovePageObject(CPDF_PageObject* pPageObj) { + pdfium::FakeUniquePtr p(pPageObj); + + auto it = + std::find(std::begin(m_PageObjectList), std::end(m_PageObjectList), p); + if (it == std::end(m_PageObjectList)) + return false; + + it->release(); + m_PageObjectList.erase(it); + return true; +} diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h index aac907763c..bf6c476186 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.h +++ b/core/fpdfapi/page/cpdf_pageobjectholder.h @@ -56,6 +56,12 @@ class CPDF_PageObjectHolder { const CPDF_PageObjectList* GetPageObjectList() const { return &m_PageObjectList; } + + size_t GetPageObjectCount() const; + CPDF_PageObject* GetPageObjectByIndex(size_t index) const; + void AppendPageObject(std::unique_ptr pPageObj); + bool RemovePageObject(CPDF_PageObject* pPageObj); + const CFX_Matrix& GetLastCTM() const { return m_LastCTM; } bool BackgroundAlphaNeeded() const { return m_bBackgroundAlphaNeeded; } diff --git a/core/fpdfapi/page/cpdf_pageobjectlist.cpp b/core/fpdfapi/page/cpdf_pageobjectlist.cpp index afd2c98536..2c8e061a73 100644 --- a/core/fpdfapi/page/cpdf_pageobjectlist.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectlist.cpp @@ -8,6 +8,6 @@ #include "third_party/base/stl_util.h" -CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) { +CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) const { return pdfium::IndexInBounds(*this, index) ? (*this)[index].get() : nullptr; } diff --git a/core/fpdfapi/page/cpdf_pageobjectlist.h b/core/fpdfapi/page/cpdf_pageobjectlist.h index b4505371f8..77c7d811e1 100644 --- a/core/fpdfapi/page/cpdf_pageobjectlist.h +++ b/core/fpdfapi/page/cpdf_pageobjectlist.h @@ -15,7 +15,7 @@ class CPDF_PageObject; class CPDF_PageObjectList : public std::deque> { public: - CPDF_PageObject* GetPageObjectByIndex(int index); + CPDF_PageObject* GetPageObjectByIndex(int index) const; }; #endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTLIST_H_ -- cgit v1.2.3