summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-03-26 20:17:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-26 20:17:29 +0000
commit2c47fb2c9b3db7be3480cbc044fa90fda988b97f (patch)
tree8f221ab1bf47c9b624974907b8ee74f92a528cb4
parentca28cb636331de447125de476decbec333fe613b (diff)
downloadpdfium-2c47fb2c9b3db7be3480cbc044fa90fda988b97f.tar.xz
Do not call CPDF_PageObjectList directly in fpdfeditpage.cpp.
Change-Id: If816c4f532f03513ad06959182b0e0edfd688e39 Reviewed-on: https://pdfium-review.googlesource.com/29170 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp14
-rw-r--r--core/fpdfapi/page/cpdf_page.h1
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectholder.cpp28
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectholder.h6
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectlist.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectlist.h2
-rw-r--r--fpdfsdk/fpdfeditpage.cpp11
7 files changed, 40 insertions, 24 deletions
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<CPDF_PageObject> 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 <algorithm>
+#include <utility>
#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<size_t>(m_PageObjectList);
+}
+
+CPDF_PageObject* CPDF_PageObjectHolder::GetPageObjectByIndex(
+ size_t index) const {
+ return m_PageObjectList.GetPageObjectByIndex(index);
+}
+
+void CPDF_PageObjectHolder::AppendPageObject(
+ std::unique_ptr<CPDF_PageObject> pPageObj) {
+ m_PageObjectList.push_back(std::move(pPageObj));
+}
+
+bool CPDF_PageObjectHolder::RemovePageObject(CPDF_PageObject* pPageObj) {
+ pdfium::FakeUniquePtr<CPDF_PageObject> 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<CPDF_PageObject> 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<std::unique_ptr<CPDF_PageObject>> {
public:
- CPDF_PageObject* GetPageObjectByIndex(int index);
+ CPDF_PageObject* GetPageObjectByIndex(int index) const;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTLIST_H_
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index 800613348b..902aab4dd1 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -175,8 +175,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page,
return;
pPageObj->SetDirty(true);
- // TODO(hnakashima): Move into CPDF_Page.
- pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
+ pPage->AppendPageObject(std::move(pPageObjHolder));
CalcBoundingBox(pPageObj);
}
@@ -190,7 +189,7 @@ FPDFPage_RemoveObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj) {
if (!IsPageObject(pPage))
return false;
- return pPage->RemoveObject(pPageObj);
+ return pPage->RemovePageObject(pPageObj);
}
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_CountObject(FPDF_PAGE page) {
@@ -202,8 +201,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_CountObjects(FPDF_PAGE page) {
if (!IsPageObject(pPage))
return -1;
- // TODO(hnakashima): Move into CPDF_Page.
- return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
+ return pPage->GetPageObjectCount();
}
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page,
@@ -212,8 +210,7 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page,
if (!IsPageObject(pPage))
return nullptr;
- // TODO(hnakashima): Move into CPDF_Page.
- return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
+ return pPage->GetPageObjectByIndex(index);
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_HasTransparency(FPDF_PAGE page) {