summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-06 00:32:16 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-06 00:32:16 +0000
commitd9826495fe0e279c6e2d587a656c7452cc2dc71f (patch)
tree0256f8903da70445c5f8e21b62c01d2d70385201 /core/fpdfapi
parenta0032a2a2c53794bbf0ccb412a5c70ce66f052fb (diff)
downloadpdfium-d9826495fe0e279c6e2d587a656c7452cc2dc71f.tar.xz
Encapsulate CPDF_PageObject's rect member.
At the same time, change it from 4 floats to a CFX_FloatRect. Change-Id: I00ded941723d6a264b7a17c73fd337e66b449308 Reviewed-on: https://pdfium-review.googlesource.com/c/43570 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_formobject.cpp7
-rw-r--r--core/fpdfapi/page/cpdf_imageobject.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_pageobject.cpp13
-rw-r--r--core/fpdfapi/page/cpdf_pageobject.h17
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectholder.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_path.h1
-rw-r--r--core/fpdfapi/page/cpdf_pathobject.cpp5
-rw-r--r--core/fpdfapi/page/cpdf_shadingobject.cpp12
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp5
-rw-r--r--core/fpdfapi/page/cpdf_textobject.cpp20
-rw-r--r--core/fpdfapi/render/cpdf_progressiverenderer.cpp8
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp17
13 files changed, 49 insertions, 73 deletions
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 2cbac8f447..3427fe5230 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -234,9 +234,7 @@ CPDF_ContentParser::Stage CPDF_ContentParser::CheckClip() {
CFX_PointF point0 = ClipPath.GetPoint(0);
CFX_PointF point2 = ClipPath.GetPoint(2);
CFX_FloatRect old_rect(point0.x, point0.y, point2.x, point2.y);
- CFX_FloatRect obj_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right,
- pObj->m_Top);
- if (old_rect.Contains(obj_rect))
+ if (old_rect.Contains(pObj->GetRect()))
pObj->m_ClipPath.SetNull();
}
return Stage::kComplete;
diff --git a/core/fpdfapi/page/cpdf_formobject.cpp b/core/fpdfapi/page/cpdf_formobject.cpp
index 22ac0d3823..a7c2643b66 100644
--- a/core/fpdfapi/page/cpdf_formobject.cpp
+++ b/core/fpdfapi/page/cpdf_formobject.cpp
@@ -41,10 +41,5 @@ CPDF_PageObject::Type CPDF_FormObject::GetType() const {
}
void CPDF_FormObject::CalcBoundingBox() {
- CFX_FloatRect form_rect =
- m_FormMatrix.TransformRect(m_pForm->CalcBoundingBox());
- m_Left = form_rect.left;
- m_Bottom = form_rect.bottom;
- m_Right = form_rect.right;
- m_Top = form_rect.top;
+ SetRect(m_FormMatrix.TransformRect(m_pForm->CalcBoundingBox()));
}
diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp
index 516a6e8cad..2b3d7b0de3 100644
--- a/core/fpdfapi/page/cpdf_imageobject.cpp
+++ b/core/fpdfapi/page/cpdf_imageobject.cpp
@@ -44,8 +44,8 @@ const CPDF_ImageObject* CPDF_ImageObject::AsImage() const {
}
void CPDF_ImageObject::CalcBoundingBox() {
- std::tie(m_Left, m_Right, m_Top, m_Bottom) =
- m_Matrix.TransformRect(0.f, 1.f, 1.f, 0.f);
+ static constexpr CFX_FloatRect kRect(0.0f, 0.0f, 1.0f, 1.0f);
+ SetRect(m_Matrix.TransformRect(kRect));
}
void CPDF_ImageObject::SetImage(const RetainPtr<CPDF_Image>& pImage) {
diff --git a/core/fpdfapi/page/cpdf_pageobject.cpp b/core/fpdfapi/page/cpdf_pageobject.cpp
index 0c3a850936..c61a7c333d 100644
--- a/core/fpdfapi/page/cpdf_pageobject.cpp
+++ b/core/fpdfapi/page/cpdf_pageobject.cpp
@@ -9,11 +9,11 @@
constexpr int32_t CPDF_PageObject::kNoContentStream;
CPDF_PageObject::CPDF_PageObject(int32_t content_stream)
- : m_bDirty(false), m_ContentStream(content_stream) {}
+ : m_ContentStream(content_stream) {}
CPDF_PageObject::CPDF_PageObject() : CPDF_PageObject(kNoContentStream) {}
-CPDF_PageObject::~CPDF_PageObject() {}
+CPDF_PageObject::~CPDF_PageObject() = default;
bool CPDF_PageObject::IsText() const {
return false;
@@ -77,21 +77,18 @@ const CPDF_FormObject* CPDF_PageObject::AsForm() const {
void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) {
CopyStates(*pSrc);
- m_Left = pSrc->m_Left;
- m_Right = pSrc->m_Right;
- m_Top = pSrc->m_Top;
- m_Bottom = pSrc->m_Bottom;
+ m_Rect = pSrc->m_Rect;
m_bDirty = true;
}
-void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
+void CPDF_PageObject::TransformClipPath(const CFX_Matrix& matrix) {
if (!m_ClipPath.HasRef())
return;
m_ClipPath.Transform(matrix);
SetDirty(true);
}
-void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
+void CPDF_PageObject::TransformGeneralState(const CFX_Matrix& matrix) {
if (!m_GeneralState.HasRef())
return;
m_GeneralState.GetMutableMatrix()->Concat(matrix);
diff --git a/core/fpdfapi/page/cpdf_pageobject.h b/core/fpdfapi/page/cpdf_pageobject.h
index 1dfe20b6f9..013ef0d03b 100644
--- a/core/fpdfapi/page/cpdf_pageobject.h
+++ b/core/fpdfapi/page/cpdf_pageobject.h
@@ -54,12 +54,11 @@ class CPDF_PageObject : public CPDF_GraphicStates {
void SetDirty(bool value) { m_bDirty = value; }
bool IsDirty() const { return m_bDirty; }
- void TransformClipPath(CFX_Matrix& matrix);
- void TransformGeneralState(CFX_Matrix& matrix);
+ void TransformClipPath(const CFX_Matrix& matrix);
+ void TransformGeneralState(const CFX_Matrix& matrix);
- CFX_FloatRect GetRect() const {
- return CFX_FloatRect(m_Left, m_Bottom, m_Right, m_Top);
- }
+ void SetRect(const CFX_FloatRect& rect) { m_Rect = rect; }
+ const CFX_FloatRect& GetRect() const { return m_Rect; }
FX_RECT GetBBox() const;
FX_RECT GetTransformedBBox(const CFX_Matrix& matrix) const;
@@ -75,20 +74,18 @@ class CPDF_PageObject : public CPDF_GraphicStates {
m_ContentStream = new_content_stream;
}
- float m_Left;
- float m_Right;
- float m_Top;
- float m_Bottom;
CPDF_ContentMark m_ContentMark;
protected:
void CopyData(const CPDF_PageObject* pSrcObject);
+ CFX_FloatRect m_Rect;
+
private:
CPDF_PageObject(const CPDF_PageObject& src) = delete;
void operator=(const CPDF_PageObject& src) = delete;
- bool m_bDirty;
+ bool m_bDirty = false;
int32_t m_ContentStream;
};
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
index 67f68c7c42..c6f310f77b 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
@@ -85,10 +85,11 @@ CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const {
float bottom = 1000000.0f;
float top = -1000000.0f;
for (const auto& pObj : m_PageObjectList) {
- left = std::min(left, pObj->m_Left);
- right = std::max(right, pObj->m_Right);
- bottom = std::min(bottom, pObj->m_Bottom);
- top = std::max(top, pObj->m_Top);
+ 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);
}
diff --git a/core/fpdfapi/page/cpdf_path.h b/core/fpdfapi/page/cpdf_path.h
index 613d715b03..4a984a540c 100644
--- a/core/fpdfapi/page/cpdf_path.h
+++ b/core/fpdfapi/page/cpdf_path.h
@@ -36,6 +36,7 @@ class CPDF_Path {
void Append(const CPDF_Path& other, const CFX_Matrix* pMatrix);
void Append(const CFX_PathData* pData, const CFX_Matrix* pMatrix);
+ // TODO(thestig): Switch to CFX_FloatRect.
void AppendRect(float left, float bottom, float right, float top);
void AppendPoint(const CFX_PointF& point, FXPT_TYPE type, bool close);
diff --git a/core/fpdfapi/page/cpdf_pathobject.cpp b/core/fpdfapi/page/cpdf_pathobject.cpp
index 0882dc17f0..84cf45d7e0 100644
--- a/core/fpdfapi/page/cpdf_pathobject.cpp
+++ b/core/fpdfapi/page/cpdf_pathobject.cpp
@@ -53,8 +53,5 @@ void CPDF_PathObject::CalcBoundingBox() {
rect.bottom += -0.5f;
rect.top += 0.5f;
}
- m_Left = rect.left;
- m_Right = rect.right;
- m_Top = rect.top;
- m_Bottom = rect.bottom;
+ SetRect(rect);
}
diff --git a/core/fpdfapi/page/cpdf_shadingobject.cpp b/core/fpdfapi/page/cpdf_shadingobject.cpp
index 725e2e4591..bdaceaa7e8 100644
--- a/core/fpdfapi/page/cpdf_shadingobject.cpp
+++ b/core/fpdfapi/page/cpdf_shadingobject.cpp
@@ -27,10 +27,10 @@ void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
m_Matrix.Concat(matrix);
if (m_ClipPath.HasRef()) {
CalcBoundingBox();
- } else {
- std::tie(m_Left, m_Right, m_Top, m_Bottom) =
- matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
+ return;
}
+
+ SetRect(matrix.TransformRect(GetRect()));
}
bool CPDF_ShadingObject::IsShading() const {
@@ -48,9 +48,5 @@ const CPDF_ShadingObject* CPDF_ShadingObject::AsShading() const {
void CPDF_ShadingObject::CalcBoundingBox() {
if (!m_ClipPath.HasRef())
return;
- CFX_FloatRect rect = m_ClipPath.GetClipBox();
- m_Left = rect.left;
- m_Bottom = rect.bottom;
- m_Right = rect.right;
- m_Top = rect.top;
+ SetRect(m_ClipPath.GetClipBox());
}
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 0760e150f3..b381705123 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -1106,10 +1106,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
pObj->m_ClipPath.HasRef() ? pObj->m_ClipPath.GetClipBox() : m_BBox;
if (pShading->IsMeshShading())
bbox.Intersect(GetShadingBBox(pShading, pObj->matrix()));
- pObj->m_Left = bbox.left;
- pObj->m_Right = bbox.right;
- pObj->m_Top = bbox.top;
- pObj->m_Bottom = bbox.bottom;
+ pObj->SetRect(bbox);
m_pObjectHolder->AppendPageObject(std::move(pObj));
}
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp
index 84428fee81..b158376293 100644
--- a/core/fpdfapi/page/cpdf_textobject.cpp
+++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -273,17 +273,17 @@ CFX_PointF CPDF_TextObject::CalcPositionData(float horz_scale) {
min_y = min_y * fontsize / 1000;
max_y = max_y * fontsize / 1000;
}
- std::tie(m_Left, m_Right, m_Top, m_Bottom) =
- GetTextMatrix().TransformRect(min_x, max_x, max_y, min_y);
+ SetRect(
+ GetTextMatrix().TransformRect(CFX_FloatRect(min_x, min_y, max_x, max_y)));
if (!TextRenderingModeIsStrokeMode(m_TextState.GetTextMode()))
return ret;
float half_width = m_GraphState.GetLineWidth() / 2;
- m_Left -= half_width;
- m_Right += half_width;
- m_Top += half_width;
- m_Bottom -= half_width;
+ m_Rect.left -= half_width;
+ m_Rect.right += half_width;
+ m_Rect.top += half_width;
+ m_Rect.bottom -= half_width;
return ret;
}
@@ -293,10 +293,10 @@ void CPDF_TextObject::SetPosition(float x, float y) {
float dy = y - m_Pos.y;
m_Pos.x = x;
m_Pos.y = y;
- m_Left += dx;
- m_Right += dx;
- m_Top += dy;
- m_Bottom += dy;
+ m_Rect.left += dx;
+ m_Rect.right += dx;
+ m_Rect.top += dy;
+ m_Rect.bottom += dy;
}
void CPDF_TextObject::RecalcPositionData() {
diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
index 1a38740a42..74b26137d1 100644
--- a/core/fpdfapi/render/cpdf_progressiverenderer.cpp
+++ b/core/fpdfapi/render/cpdf_progressiverenderer.cpp
@@ -78,10 +78,10 @@ void CPDF_ProgressiveRenderer::Continue(PauseIndicatorIface* pPause) {
bool is_mask = false;
while (iter != iterEnd) {
CPDF_PageObject* pCurObj = iter->get();
- if (pCurObj && pCurObj->m_Left <= m_ClipRect.right &&
- pCurObj->m_Right >= m_ClipRect.left &&
- pCurObj->m_Bottom <= m_ClipRect.top &&
- pCurObj->m_Top >= m_ClipRect.bottom) {
+ if (pCurObj && pCurObj->GetRect().left <= m_ClipRect.right &&
+ pCurObj->GetRect().right >= m_ClipRect.left &&
+ pCurObj->GetRect().bottom <= m_ClipRect.top &&
+ pCurObj->GetRect().top >= m_ClipRect.bottom) {
if (m_pOptions->HasFlag(RENDER_BREAKFORMASKS) && pCurObj->IsImage() &&
pCurObj->AsImage()->GetImage()->IsMask()) {
if (m_pDevice->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) {
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 19fea76d70..f77b6c654f 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1040,10 +1040,10 @@ void CPDF_RenderStatus::RenderObjectList(
if (!pCurObj)
continue;
- if (pCurObj->m_Left > clip_rect.right ||
- pCurObj->m_Right < clip_rect.left ||
- pCurObj->m_Bottom > clip_rect.top ||
- pCurObj->m_Top < clip_rect.bottom) {
+ if (pCurObj->GetRect().left > clip_rect.right ||
+ pCurObj->GetRect().right < clip_rect.left ||
+ pCurObj->GetRect().bottom > clip_rect.top ||
+ pCurObj->GetRect().top < clip_rect.bottom) {
continue;
}
RenderSingleObject(pCurObj.get(), mtObj2Device);
@@ -1972,12 +1972,9 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
path.m_ClipPath.AppendTexts(&pCopy);
path.m_ColorState = textobj->m_ColorState;
path.m_GeneralState = textobj->m_GeneralState;
- path.m_Path.AppendRect(textobj->m_Left, textobj->m_Bottom, textobj->m_Right,
- textobj->m_Top);
- path.m_Left = textobj->m_Left;
- path.m_Bottom = textobj->m_Bottom;
- path.m_Right = textobj->m_Right;
- path.m_Top = textobj->m_Top;
+ path.m_Path.AppendRect(textobj->GetRect().left, textobj->GetRect().bottom,
+ textobj->GetRect().right, textobj->GetRect().top);
+ path.SetRect(textobj->GetRect());
AutoRestorer<UnownedPtr<const CPDF_PageObject>> restorer2(&m_pCurObj);
RenderSingleObject(&path, mtObj2Device);