summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fde/cfde_path.cpp68
-rw-r--r--xfa/fde/cfde_path.h5
-rw-r--r--xfa/fxgraphics/cfx_path.cpp4
-rw-r--r--xfa/fxgraphics/cfx_path_generator.cpp95
-rw-r--r--xfa/fxgraphics/cfx_path_generator.h1
5 files changed, 44 insertions, 129 deletions
diff --git a/xfa/fde/cfde_path.cpp b/xfa/fde/cfde_path.cpp
index 825de40bfe..0418513972 100644
--- a/xfa/fde/cfde_path.cpp
+++ b/xfa/fde/cfde_path.cpp
@@ -9,70 +9,29 @@
#include "third_party/base/stl_util.h"
#include "xfa/fde/fde_object.h"
-bool CFDE_Path::StartFigure() {
- return CloseFigure();
-}
-
-bool CFDE_Path::CloseFigure() {
- FX_PATHPOINT* pPoint = GetLastPoint();
- if (pPoint)
- pPoint->m_CloseFigure = true;
- return true;
-}
-
-FX_PATHPOINT* CFDE_Path::GetLastPoint() const {
- int32_t iPoints = m_Path.GetPointCount();
- if (iPoints == 0)
- return nullptr;
- return m_Path.GetPoints() + iPoints - 1;
+void CFDE_Path::CloseFigure() {
+ m_Path.ClosePath();
}
bool CFDE_Path::FigureClosed() const {
- FX_PATHPOINT* pPoint = GetLastPoint();
- return pPoint ? pPoint->m_CloseFigure : true;
-}
-
-FX_PATHPOINT* CFDE_Path::AddPoints(int32_t iCount) {
- if (iCount < 1)
- return nullptr;
-
- int32_t iPoints = m_Path.GetPointCount();
- m_Path.AddPointCount(iCount);
- return m_Path.GetPoints() + iPoints;
+ const std::vector<FX_PATHPOINT>& points = m_Path.GetPoints();
+ return points.empty() ? true : points.back().m_CloseFigure;
}
void CFDE_Path::MoveTo(FX_FLOAT fx, FX_FLOAT fy) {
- FX_PATHPOINT* pPoint = AddPoints(1);
- pPoint->m_PointX = fx;
- pPoint->m_PointY = fy;
- pPoint->m_Type = FXPT_TYPE::MoveTo;
- pPoint->m_CloseFigure = false;
+ m_Path.AppendPoint(fx, fy, FXPT_TYPE::MoveTo, false);
}
void CFDE_Path::LineTo(FX_FLOAT fx, FX_FLOAT fy) {
- FX_PATHPOINT* pPoint = AddPoints(1);
- pPoint->m_PointX = fx;
- pPoint->m_PointY = fy;
- pPoint->m_Type = FXPT_TYPE::LineTo;
- pPoint->m_CloseFigure = false;
+ m_Path.AppendPoint(fx, fy, FXPT_TYPE::LineTo, false);
}
void CFDE_Path::BezierTo(const CFX_PointF& p1,
const CFX_PointF& p2,
const CFX_PointF& p3) {
- FX_PATHPOINT* p = AddPoints(3);
- p[0].m_PointX = p1.x;
- p[0].m_PointY = p1.y;
- p[0].m_Type = FXPT_TYPE::BezierTo;
- p[0].m_CloseFigure = false;
- p[1].m_PointX = p2.x;
- p[1].m_PointY = p2.y;
- p[1].m_Type = FXPT_TYPE::BezierTo;
- p[1].m_CloseFigure = false;
- p[2].m_PointX = p3.x;
- p[2].m_PointY = p3.y;
- p[2].m_Type = FXPT_TYPE::BezierTo;
- p[2].m_CloseFigure = false;
+ m_Path.AppendPoint(p1.x, p1.y, FXPT_TYPE::BezierTo, false);
+ m_Path.AppendPoint(p2.x, p2.y, FXPT_TYPE::BezierTo, false);
+ m_Path.AppendPoint(p3.x, p3.y, FXPT_TYPE::BezierTo, false);
}
void CFDE_Path::ArcTo(bool bStart,
@@ -195,9 +154,9 @@ void CFDE_Path::AddEllipse(const CFX_RectF& rect) {
}
void CFDE_Path::AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2) {
- FX_PATHPOINT* pLast = GetLastPoint();
- if (!pLast || FXSYS_fabs(pLast->m_PointX - pt1.x) > 0.001 ||
- FXSYS_fabs(pLast->m_PointY - pt1.y) > 0.001) {
+ std::vector<FX_PATHPOINT>& points = m_Path.GetPoints();
+ if (points.empty() || FXSYS_fabs(points.back().m_PointX - pt1.x) > 0.001 ||
+ FXSYS_fabs(points.back().m_PointY - pt1.y) > 0.001) {
MoveTo(pt1);
}
LineTo(pt2);
@@ -207,8 +166,7 @@ void CFDE_Path::AddPath(const CFDE_Path* pSrc, bool bConnect) {
if (!pSrc)
return;
- int32_t iCount = pSrc->m_Path.GetPointCount();
- if (iCount < 1)
+ if (pSrc->m_Path.GetPoints().empty())
return;
if (bConnect)
LineTo(pSrc->m_Path.GetPointX(0), pSrc->m_Path.GetPointY(0));
diff --git a/xfa/fde/cfde_path.h b/xfa/fde/cfde_path.h
index ab5995016a..a3a81805bf 100644
--- a/xfa/fde/cfde_path.h
+++ b/xfa/fde/cfde_path.h
@@ -14,8 +14,7 @@
class CFDE_Path {
public:
- bool StartFigure();
- bool CloseFigure();
+ void CloseFigure();
void AddBezier(const std::vector<CFX_PointF>& points);
void AddBeziers(const std::vector<CFX_PointF>& points);
@@ -28,7 +27,6 @@ class CFDE_Path {
void AddPath(const CFDE_Path* pSrc, bool bConnect);
void AddPolygon(const std::vector<CFX_PointF>& points);
void AddRectangle(const CFX_RectF& rect);
- FX_PATHPOINT* AddPoints(int32_t iCount);
CFX_RectF GetBBox() const;
CFX_RectF GetBBox(FX_FLOAT fLineWidth, FX_FLOAT fMiterLimit) const;
@@ -46,7 +44,6 @@ class CFDE_Path {
void MoveTo(const CFX_PointF& p0) { MoveTo(p0.x, p0.y); }
void LineTo(const CFX_PointF& p1) { LineTo(p1.x, p1.y); }
- FX_PATHPOINT* GetLastPoint() const;
void GetCurveTangents(const std::vector<CFX_PointF>& points,
std::vector<CFX_PointF>* tangents,
bool bClosed,
diff --git a/xfa/fxgraphics/cfx_path.cpp b/xfa/fxgraphics/cfx_path.cpp
index 3288631f15..d2e8f94638 100644
--- a/xfa/fxgraphics/cfx_path.cpp
+++ b/xfa/fxgraphics/cfx_path.cpp
@@ -159,14 +159,14 @@ FWL_Error CFX_Path::AddSubpath(CFX_Path* path) {
FWL_Error CFX_Path::Clear() {
if (!m_generator)
return FWL_Error::PropertyInvalid;
- m_generator->GetPathData()->SetPointCount(0);
+ m_generator->GetPathData()->Clear();
return FWL_Error::Succeeded;
}
bool CFX_Path::IsEmpty() const {
if (!m_generator)
return false;
- if (m_generator->GetPathData()->GetPointCount() == 0)
+ if (m_generator->GetPathData()->GetPoints().empty())
return true;
return false;
}
diff --git a/xfa/fxgraphics/cfx_path_generator.cpp b/xfa/fxgraphics/cfx_path_generator.cpp
index c7f4c0b756..8da1b4fe15 100644
--- a/xfa/fxgraphics/cfx_path_generator.cpp
+++ b/xfa/fxgraphics/cfx_path_generator.cpp
@@ -14,33 +14,17 @@ CFX_PathGenerator::CFX_PathGenerator() : m_pPathData(new CFX_PathData) {}
CFX_PathGenerator::~CFX_PathGenerator() {}
void CFX_PathGenerator::AddPathData(CFX_PathData* pPathData) {
- if (pPathData && pPathData->GetPointCount() > 0) {
- int nCount = pPathData->GetPointCount();
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
- AddPathData(pPoints, nCount);
- }
-}
-
-void CFX_PathGenerator::AddPathData(FX_PATHPOINT* pPoints, int nCount) {
- if (pPoints && nCount > 0) {
- int nOldCount = m_pPathData->GetPointCount();
- m_pPathData->AddPointCount(nCount);
- FX_PATHPOINT* pDstPoints = m_pPathData->GetPoints();
- FXSYS_memcpy(pDstPoints + nOldCount, pPoints,
- sizeof(FX_PATHPOINT) * nCount);
- }
+ if (!pPathData)
+ return;
+ m_pPathData->Append(pPathData, nullptr);
}
void CFX_PathGenerator::MoveTo(FX_FLOAT x, FX_FLOAT y) {
- m_pPathData->AddPointCount(1);
- m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1, x, y,
- FXPT_TYPE::MoveTo, false);
+ m_pPathData->AppendPoint(x, y, FXPT_TYPE::MoveTo, false);
}
void CFX_PathGenerator::LineTo(FX_FLOAT x, FX_FLOAT y) {
- m_pPathData->AddPointCount(1);
- m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1, x, y,
- FXPT_TYPE::LineTo, false);
+ m_pPathData->AppendPoint(x, y, FXPT_TYPE::LineTo, false);
}
void CFX_PathGenerator::BezierTo(FX_FLOAT ctrl_x1,
@@ -49,31 +33,21 @@ void CFX_PathGenerator::BezierTo(FX_FLOAT ctrl_x1,
FX_FLOAT ctrl_y2,
FX_FLOAT to_x,
FX_FLOAT to_y) {
- int old_count = m_pPathData->GetPointCount();
- m_pPathData->AddPointCount(3);
- m_pPathData->SetPoint(old_count, ctrl_x1, ctrl_y1, FXPT_TYPE::BezierTo,
- false);
- m_pPathData->SetPoint(old_count + 1, ctrl_x2, ctrl_y2, FXPT_TYPE::BezierTo,
- false);
- m_pPathData->SetPoint(old_count + 2, to_x, to_y, FXPT_TYPE::BezierTo, false);
+ m_pPathData->AppendPoint(ctrl_x1, ctrl_y1, FXPT_TYPE::BezierTo, false);
+ m_pPathData->AppendPoint(ctrl_x2, ctrl_y2, FXPT_TYPE::BezierTo, false);
+ m_pPathData->AppendPoint(to_x, to_y, FXPT_TYPE::BezierTo, false);
}
void CFX_PathGenerator::Close() {
- if (m_pPathData->GetPointCount() > 0) {
- int index = m_pPathData->GetPointCount() - 1;
- FX_PATHPOINT* pPoints = m_pPathData->GetPoints();
- pPoints[index].m_CloseFigure = true;
- }
+ m_pPathData->ClosePath();
}
void CFX_PathGenerator::AddLine(FX_FLOAT x1,
FX_FLOAT y1,
FX_FLOAT x2,
FX_FLOAT y2) {
- int old_count = m_pPathData->GetPointCount();
- m_pPathData->AddPointCount(2);
- m_pPathData->SetPoint(old_count, x1, y1, FXPT_TYPE::MoveTo, false);
- m_pPathData->SetPoint(old_count + 1, x2, y2, FXPT_TYPE::LineTo, false);
+ m_pPathData->AppendPoint(x1, y1, FXPT_TYPE::MoveTo, false);
+ m_pPathData->AppendPoint(x2, y2, FXPT_TYPE::LineTo, false);
}
void CFX_PathGenerator::AddBezier(FX_FLOAT start_x,
@@ -84,15 +58,10 @@ void CFX_PathGenerator::AddBezier(FX_FLOAT start_x,
FX_FLOAT ctrl_y2,
FX_FLOAT end_x,
FX_FLOAT end_y) {
- int old_count = m_pPathData->GetPointCount();
- m_pPathData->AddPointCount(4);
- m_pPathData->SetPoint(old_count, start_x, start_y, FXPT_TYPE::MoveTo, false);
- m_pPathData->SetPoint(old_count + 1, ctrl_x1, ctrl_y1, FXPT_TYPE::BezierTo,
- false);
- m_pPathData->SetPoint(old_count + 2, ctrl_x2, ctrl_y2, FXPT_TYPE::BezierTo,
- false);
- m_pPathData->SetPoint(old_count + 3, end_x, end_y, FXPT_TYPE::BezierTo,
- false);
+ m_pPathData->AppendPoint(start_x, start_y, FXPT_TYPE::MoveTo, false);
+ m_pPathData->AppendPoint(ctrl_x1, ctrl_y1, FXPT_TYPE::BezierTo, false);
+ m_pPathData->AppendPoint(ctrl_x2, ctrl_y2, FXPT_TYPE::BezierTo, false);
+ m_pPathData->AppendPoint(end_x, end_y, FXPT_TYPE::BezierTo, false);
}
void CFX_PathGenerator::AddRectangle(FX_FLOAT x1,
@@ -126,21 +95,17 @@ void CFX_PathGenerator::ArcTo(FX_FLOAT x,
py[1] = ty;
FX_FLOAT sn = FXSYS_sin(start_angle + sweep_angle / 2);
FX_FLOAT cs = FXSYS_cos(start_angle + sweep_angle / 2);
- int old_count = m_pPathData->GetPointCount();
- m_pPathData->AddPointCount(3);
+
FX_FLOAT bezier_x, bezier_y;
bezier_x = x + (width * ((px[0] * cs) - (py[0] * sn)));
bezier_y = y + (height * ((px[0] * sn) + (py[0] * cs)));
- m_pPathData->SetPoint(old_count, bezier_x, bezier_y, FXPT_TYPE::BezierTo,
- false);
+ m_pPathData->AppendPoint(bezier_x, bezier_y, FXPT_TYPE::BezierTo, false);
bezier_x = x + (width * ((px[1] * cs) - (py[1] * sn)));
bezier_y = y + (height * ((px[1] * sn) + (py[1] * cs)));
- m_pPathData->SetPoint(old_count + 1, bezier_x, bezier_y, FXPT_TYPE::BezierTo,
- false);
+ m_pPathData->AppendPoint(bezier_x, bezier_y, FXPT_TYPE::BezierTo, false);
bezier_x = x + (width * FXSYS_cos(start_angle + sweep_angle));
bezier_y = y + (height * FXSYS_sin(start_angle + sweep_angle));
- m_pPathData->SetPoint(old_count + 2, bezier_x, bezier_y, FXPT_TYPE::BezierTo,
- false);
+ m_pPathData->AppendPoint(bezier_x, bezier_y, FXPT_TYPE::BezierTo, false);
}
void CFX_PathGenerator::AddArc(FX_FLOAT x,
@@ -166,10 +131,10 @@ void CFX_PathGenerator::AddArc(FX_FLOAT x,
if (sweep_angle <= -FX_PI * 2) {
sweep_angle = -FX_PI * 2;
}
- m_pPathData->AddPointCount(1);
- m_pPathData->SetPoint(
- m_pPathData->GetPointCount() - 1, x + (width * FXSYS_cos(start_angle)),
- y + (height * FXSYS_sin(start_angle)), FXPT_TYPE::MoveTo, false);
+
+ m_pPathData->AppendPoint(x + (width * FXSYS_cos(start_angle)),
+ y + (height * FXSYS_sin(start_angle)),
+ FXPT_TYPE::MoveTo, false);
FX_FLOAT total_sweep = 0, local_sweep = 0, prev_sweep = 0;
bool done = false;
do {
@@ -202,16 +167,12 @@ void CFX_PathGenerator::AddPie(FX_FLOAT x,
FX_FLOAT start_angle,
FX_FLOAT sweep_angle) {
if (sweep_angle == 0) {
- int old_count = m_pPathData->GetPointCount();
- m_pPathData->AddPointCount(2);
- m_pPathData->SetPoint(old_count, x, y, FXPT_TYPE::MoveTo, false);
- m_pPathData->SetPoint(old_count + 1, x + (width * FXSYS_cos(start_angle)),
- y + (height * FXSYS_sin(start_angle)),
- FXPT_TYPE::LineTo, false);
+ m_pPathData->AppendPoint(x, y, FXPT_TYPE::MoveTo, false);
+ m_pPathData->AppendPoint(x + (width * FXSYS_cos(start_angle)),
+ y + (height * FXSYS_sin(start_angle)),
+ FXPT_TYPE::LineTo, false);
return;
}
AddArc(x, y, width, height, start_angle, sweep_angle);
- m_pPathData->AddPointCount(1);
- m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1, x, y,
- FXPT_TYPE::LineTo, true);
+ m_pPathData->AppendPoint(x, y, FXPT_TYPE::LineTo, true);
}
diff --git a/xfa/fxgraphics/cfx_path_generator.h b/xfa/fxgraphics/cfx_path_generator.h
index 75e3a57633..916400d529 100644
--- a/xfa/fxgraphics/cfx_path_generator.h
+++ b/xfa/fxgraphics/cfx_path_generator.h
@@ -19,7 +19,6 @@ class CFX_PathGenerator {
CFX_PathData* GetPathData() const { return m_pPathData.get(); }
void AddPathData(CFX_PathData* path_data);
- void AddPathData(FX_PATHPOINT* points, int count);
void MoveTo(FX_FLOAT x, FX_FLOAT y);
void LineTo(FX_FLOAT x, FX_FLOAT y);