Move CalcBoundingBox() from CPDF_PageObjectHolder to CPDF_Form
It is only ever invokd on objects of the CPDF_Form subclass. It
is, however, called by the font/ layer, so making it part of the
form lays groundwork for the form to someday implement an abstract
interface containing this method.
- Remove a spurious CollectionSize<>() call.
Change-Id: I35855365c0631f136e555b70ba938689fd931518
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/57790
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_form.cpp b/core/fpdfapi/page/cpdf_form.cpp
index a30087a..72c90a8 100644
--- a/core/fpdfapi/page/cpdf_form.cpp
+++ b/core/fpdfapi/page/cpdf_form.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/page/cpdf_form.h"
+#include <algorithm>
+
#include "core/fpdfapi/page/cpdf_contentparser.h"
#include "core/fpdfapi/page/cpdf_imageobject.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
@@ -67,6 +69,24 @@
ContinueParse(nullptr);
}
+CFX_FloatRect CPDF_Form::CalcBoundingBox() const {
+ if (GetPageObjectCount() == 0)
+ return CFX_FloatRect();
+
+ float left = 1000000.0f;
+ float right = -1000000.0f;
+ float bottom = 1000000.0f;
+ float top = -1000000.0f;
+ for (const auto& pObj : *this) {
+ const auto& rect = pObj->GetRect();
+ left = std::min(left, rect.left);
+ right = std::max(right, rect.right);
+ bottom = std::min(bottom, rect.bottom);
+ top = std::max(top, rect.top);
+ }
+ return CFX_FloatRect(left, bottom, right, top);
+}
+
const CPDF_Stream* CPDF_Form::GetStream() const {
return m_pFormStream.Get();
}
diff --git a/core/fpdfapi/page/cpdf_form.h b/core/fpdfapi/page/cpdf_form.h
index 9719476..69bac7d 100644
--- a/core/fpdfapi/page/cpdf_form.h
+++ b/core/fpdfapi/page/cpdf_form.h
@@ -41,6 +41,7 @@
CPDF_Type3Char* pType3Char,
std::set<const uint8_t*>* parsedSet);
+ CFX_FloatRect CalcBoundingBox() const;
const CPDF_Stream* GetStream() const;
// Fast path helper for avoiding a full rendering of form.
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
index 73c3495..c67e408 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
@@ -82,24 +82,6 @@
pObj->Transform(matrix);
}
-CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const {
- if (m_PageObjectList.empty())
- return CFX_FloatRect();
-
- float left = 1000000.0f;
- float right = -1000000.0f;
- float bottom = 1000000.0f;
- float top = -1000000.0f;
- for (const auto& pObj : m_PageObjectList) {
- const auto& rect = pObj->GetRect();
- left = std::min(left, rect.left);
- right = std::max(right, rect.right);
- bottom = std::min(bottom, rect.bottom);
- top = std::max(top, rect.top);
- }
- return CFX_FloatRect(left, bottom, right, top);
-}
-
std::set<int32_t> CPDF_PageObjectHolder::TakeDirtyStreams() {
auto dirty_streams = std::move(m_DirtyStreams);
m_DirtyStreams.clear();
@@ -123,10 +105,6 @@
m_Transparency.SetIsolated();
}
-size_t CPDF_PageObjectHolder::GetPageObjectCount() const {
- return pdfium::CollectionSize<size_t>(m_PageObjectList);
-}
-
CPDF_PageObject* CPDF_PageObjectHolder::GetPageObjectByIndex(
size_t index) const {
return pdfium::IndexInBounds(m_PageObjectList, index)
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h
index fbeaf88..332d912 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.h
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.h
@@ -69,8 +69,7 @@
// TODO(thestig): Can this return nullptr? If not, audit callers and simplify
// the ones that assume it can.
CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
-
- size_t GetPageObjectCount() const;
+ size_t GetPageObjectCount() const { return m_PageObjectList.size(); }
CPDF_PageObject* GetPageObjectByIndex(size_t index) const;
void AppendPageObject(std::unique_ptr<CPDF_PageObject> pPageObj);
bool RemovePageObject(CPDF_PageObject* pPageObj);
@@ -97,7 +96,6 @@
}
void AddImageMaskBoundingBox(const CFX_FloatRect& box);
void Transform(const CFX_Matrix& matrix);
- CFX_FloatRect CalcBoundingBox() const;
bool HasDirtyStreams() const { return !m_DirtyStreams.empty(); }
std::set<int32_t> TakeDirtyStreams();