summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2017-02-22 19:56:15 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-02-23 01:17:40 +0000
commitb147e07ee36be10ca0796a6566be107077c21a03 (patch)
tree637b1b206000a88fb3e198f648e86a9ee5178f1b /core/fpdfapi
parente3f237740fd8bea50b4a6f37f56455dfa0328546 (diff)
downloadpdfium-b147e07ee36be10ca0796a6566be107077c21a03.tar.xz
Convert point x,y into CFX_PointF
This Cl converts the PointX,PointY pairs into a CFX_PointF. Change-Id: I46897832077c317a5bffb4e568550705decbc40c Reviewed-on: https://pdfium-review.googlesource.com/2821 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp14
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp44
-rw-r--r--core/fpdfapi/page/cpdf_clippath.cpp5
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_path.cpp13
-rw-r--r--core/fpdfapi/page/cpdf_path.h5
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp9
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp10
8 files changed, 55 insertions, 51 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index b5fe4c0f35..35595b3e1f 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -150,14 +150,14 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf,
ProcessGraphics(buf, pPathObj);
auto& pPoints = pPathObj->m_Path.GetPoints();
if (pPathObj->m_Path.IsRect()) {
- *buf << pPoints[0].m_PointX << " " << pPoints[0].m_PointY << " "
- << (pPoints[2].m_PointX - pPoints[0].m_PointX) << " "
- << (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re";
+ CFX_PointF diff = pPoints[2].m_Point - pPoints[0].m_Point;
+ *buf << pPoints[0].m_Point.x << " " << pPoints[0].m_Point.y << " " << diff.x
+ << " " << diff.y << " re";
} else {
for (size_t i = 0; i < pPoints.size(); i++) {
if (i > 0)
*buf << " ";
- *buf << pPoints[i].m_PointX << " " << pPoints[i].m_PointY;
+ *buf << pPoints[i].m_Point.x << " " << pPoints[i].m_Point.y;
FXPT_TYPE pointType = pPoints[i].m_Type;
if (pointType == FXPT_TYPE::MoveTo) {
*buf << " m";
@@ -172,9 +172,9 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf,
*buf << " h";
break;
}
- *buf << " " << pPoints[i + 1].m_PointX << " " << pPoints[i + 1].m_PointY
- << " " << pPoints[i + 2].m_PointX << " " << pPoints[i + 2].m_PointY
- << " c";
+ *buf << " " << pPoints[i + 1].m_Point.x << " "
+ << pPoints[i + 1].m_Point.y << " " << pPoints[i + 2].m_Point.x
+ << " " << pPoints[i + 2].m_Point.y << " c";
i += 2;
}
if (pPoints[i].m_CloseFigure)
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 42e6e2d843..d8813ba30f 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -52,10 +52,11 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) {
EXPECT_EQ("q 10 5 3 25 re B* Q\n", buf.MakeString());
pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
- pPathObj->m_Path.AppendPoint(0, 0, FXPT_TYPE::MoveTo, false);
- pPathObj->m_Path.AppendPoint(5.2f, 0, FXPT_TYPE::LineTo, false);
- pPathObj->m_Path.AppendPoint(5.2f, 3.78f, FXPT_TYPE::LineTo, false);
- pPathObj->m_Path.AppendPoint(0, 3.78f, FXPT_TYPE::LineTo, true);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(0, 0), FXPT_TYPE::MoveTo, false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(5.2f, 0), FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(5.2f, 3.78f), FXPT_TYPE::LineTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(0, 3.78f), FXPT_TYPE::LineTo, true);
pPathObj->m_FillType = 0;
pPathObj->m_bStroke = false;
buf.Clear();
@@ -66,16 +67,25 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) {
TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) {
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
- pPathObj->m_Path.AppendPoint(3.102f, 4.67f, FXPT_TYPE::MoveTo, false);
- pPathObj->m_Path.AppendPoint(5.45f, 0.29f, FXPT_TYPE::LineTo, false);
- pPathObj->m_Path.AppendPoint(4.24f, 3.15f, FXPT_TYPE::BezierTo, false);
- pPathObj->m_Path.AppendPoint(4.65f, 2.98f, FXPT_TYPE::BezierTo, false);
- pPathObj->m_Path.AppendPoint(3.456f, 0.24f, FXPT_TYPE::BezierTo, false);
- pPathObj->m_Path.AppendPoint(10.6f, 11.15f, FXPT_TYPE::LineTo, false);
- pPathObj->m_Path.AppendPoint(11, 12.5f, FXPT_TYPE::LineTo, false);
- pPathObj->m_Path.AppendPoint(11.46f, 12.67f, FXPT_TYPE::BezierTo, false);
- pPathObj->m_Path.AppendPoint(11.84f, 12.96f, FXPT_TYPE::BezierTo, false);
- pPathObj->m_Path.AppendPoint(12, 13.64f, FXPT_TYPE::BezierTo, true);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(3.102f, 4.67f), FXPT_TYPE::MoveTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(5.45f, 0.29f), FXPT_TYPE::LineTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(4.24f, 3.15f), FXPT_TYPE::BezierTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(4.65f, 2.98f), FXPT_TYPE::BezierTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(3.456f, 0.24f), FXPT_TYPE::BezierTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(10.6f, 11.15f), FXPT_TYPE::LineTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(11, 12.5f), FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(11.46f, 12.67f), FXPT_TYPE::BezierTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(11.84f, 12.96f), FXPT_TYPE::BezierTo,
+ false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(12, 13.64f), FXPT_TYPE::BezierTo,
+ true);
pPathObj->m_FillType = FXFILL_WINDING;
pPathObj->m_bStroke = false;
@@ -91,9 +101,9 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) {
TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) {
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
- pPathObj->m_Path.AppendPoint(1, 2, FXPT_TYPE::MoveTo, false);
- pPathObj->m_Path.AppendPoint(3, 4, FXPT_TYPE::LineTo, false);
- pPathObj->m_Path.AppendPoint(5, 6, FXPT_TYPE::LineTo, true);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(1, 2), FXPT_TYPE::MoveTo, false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(3, 4), FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(CFX_PointF(5, 6), FXPT_TYPE::LineTo, true);
pPathObj->m_FillType = FXFILL_WINDING;
pPathObj->m_bStroke = true;
diff --git a/core/fpdfapi/page/cpdf_clippath.cpp b/core/fpdfapi/page/cpdf_clippath.cpp
index cfcd9a1e64..714b56bff3 100644
--- a/core/fpdfapi/page/cpdf_clippath.cpp
+++ b/core/fpdfapi/page/cpdf_clippath.cpp
@@ -84,8 +84,9 @@ void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
if (!pData->m_PathAndTypeList.empty() && bAutoMerge) {
const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first;
if (old_path.IsRect()) {
- CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
- old_path.GetPointX(2), old_path.GetPointY(2));
+ CFX_PointF point0 = old_path.GetPoint(0);
+ CFX_PointF point2 = old_path.GetPoint(2);
+ CFX_FloatRect old_rect(point0.x, point0.y, point2.x, point2.y);
CFX_FloatRect new_rect = path.GetBoundingBox();
if (old_rect.Contains(new_rect))
pData->m_PathAndTypeList.pop_back();
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 7f00eabb86..7ceb509348 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -203,8 +203,10 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
CPDF_Path ClipPath = pObj->m_ClipPath.GetPath(0);
if (!ClipPath.IsRect() || pObj->IsShading())
continue;
- CFX_FloatRect old_rect(ClipPath.GetPointX(0), ClipPath.GetPointY(0),
- ClipPath.GetPointX(2), ClipPath.GetPointY(2));
+
+ 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))
diff --git a/core/fpdfapi/page/cpdf_path.cpp b/core/fpdfapi/page/cpdf_path.cpp
index a95ce1e5bc..ddc6bbd1d6 100644
--- a/core/fpdfapi/page/cpdf_path.cpp
+++ b/core/fpdfapi/page/cpdf_path.cpp
@@ -20,12 +20,8 @@ void CPDF_Path::ClosePath() {
m_Ref.GetPrivateCopy()->ClosePath();
}
-FX_FLOAT CPDF_Path::GetPointX(int index) const {
- return m_Ref.GetObject()->GetPointX(index);
-}
-
-FX_FLOAT CPDF_Path::GetPointY(int index) const {
- return m_Ref.GetObject()->GetPointY(index);
+CFX_PointF CPDF_Path::GetPoint(int index) const {
+ return m_Ref.GetObject()->GetPoint(index);
}
CFX_FloatRect CPDF_Path::GetBoundingBox() const {
@@ -60,11 +56,10 @@ void CPDF_Path::AppendRect(FX_FLOAT left,
m_Ref.GetPrivateCopy()->AppendRect(left, bottom, right, top);
}
-void CPDF_Path::AppendPoint(FX_FLOAT x,
- FX_FLOAT y,
+void CPDF_Path::AppendPoint(const CFX_PointF& point,
FXPT_TYPE type,
bool close) {
CFX_PathData data;
- data.AppendPoint(x, y, type, close);
+ data.AppendPoint(point, type, close);
Append(&data, nullptr);
}
diff --git a/core/fpdfapi/page/cpdf_path.h b/core/fpdfapi/page/cpdf_path.h
index 97dd8fd8a9..b0c5a68a44 100644
--- a/core/fpdfapi/page/cpdf_path.h
+++ b/core/fpdfapi/page/cpdf_path.h
@@ -27,8 +27,7 @@ class CPDF_Path {
const std::vector<FX_PATHPOINT>& GetPoints() const;
void ClosePath();
- FX_FLOAT GetPointX(int index) const;
- FX_FLOAT GetPointY(int index) const;
+ CFX_PointF GetPoint(int index) const;
CFX_FloatRect GetBoundingBox() const;
CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const;
@@ -38,7 +37,7 @@ class CPDF_Path {
void Append(const CPDF_Path& other, const CFX_Matrix* pMatrix);
void Append(const CFX_PathData* pData, const CFX_Matrix* pMatrix);
void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top);
- void AppendPoint(FX_FLOAT x, FX_FLOAT y, FXPT_TYPE type, bool close);
+ void AppendPoint(const CFX_PointF& point, FXPT_TYPE type, bool close);
// TODO(tsepez): Remove when all access thru this class.
const CFX_PathData* GetObject() const { return m_Ref.GetObject(); }
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index b8c9c4c6af..d8e1c1e15d 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -1445,8 +1445,7 @@ void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x,
m_PathStartY = y;
if (m_PathPointCount &&
m_pPathPoints[m_PathPointCount - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) {
- m_pPathPoints[m_PathPointCount - 1].m_PointX = x;
- m_pPathPoints[m_PathPointCount - 1].m_PointY = y;
+ m_pPathPoints[m_PathPointCount - 1].m_Point = CFX_PointF(x, y);
return;
}
} else if (m_PathPointCount == 0) {
@@ -1466,8 +1465,7 @@ void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x,
}
m_pPathPoints[m_PathPointCount - 1].m_Type = type;
m_pPathPoints[m_PathPointCount - 1].m_CloseFigure = close;
- m_pPathPoints[m_PathPointCount - 1].m_PointX = x;
- m_pPathPoints[m_PathPointCount - 1].m_PointY = y;
+ m_pPathPoints[m_PathPointCount - 1].m_Point = CFX_PointF(x, y);
}
void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) {
@@ -1491,8 +1489,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) {
CPDF_Path Path;
for (int i = 0; i < PathPointCount; i++) {
FX_PATHPOINT& point = m_pPathPoints[i];
- Path.AppendPoint(point.m_PointX, point.m_PointY, point.m_Type,
- point.m_CloseFigure);
+ Path.AppendPoint(point.m_Point, point.m_Type, point.m_CloseFigure);
}
CFX_Matrix matrix = m_pCurStates->m_CTM;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index b041a72662..fe04174c28 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -639,11 +639,11 @@ struct Coon_Bezier {
int i;
x.GetPoints(p);
for (i = 0; i < 4; i++)
- pPoints[start_idx + i].m_PointX = p[i];
+ pPoints[start_idx + i].m_Point.x = p[i];
y.GetPoints(p);
for (i = 0; i < 4; i++)
- pPoints[start_idx + i].m_PointY = p[i];
+ pPoints[start_idx + i].m_Point.y = p[i];
}
void GetPointsReverse(std::vector<FX_PATHPOINT>& pPoints, size_t start_idx) {
@@ -651,11 +651,11 @@ struct Coon_Bezier {
int i;
x.GetPointsReverse(p);
for (i = 0; i < 4; i++)
- pPoints[i + start_idx].m_PointX = p[i];
+ pPoints[i + start_idx].m_Point.x = p[i];
y.GetPointsReverse(p);
for (i = 0; i < 4; i++)
- pPoints[i + start_idx].m_PointY = p[i];
+ pPoints[i + start_idx].m_Point.y = p[i];
}
float Distance() { return x.Distance() + y.Distance(); }
@@ -822,7 +822,7 @@ void DrawCoonPatchMeshes(
for (int i = 0; i < 13; i++) {
patch.path.AppendPoint(
- 0, 0, i == 0 ? FXPT_TYPE::MoveTo : FXPT_TYPE::BezierTo, false);
+ CFX_PointF(), i == 0 ? FXPT_TYPE::MoveTo : FXPT_TYPE::BezierTo, false);
}
CFX_PointF coords[16];