diff options
Diffstat (limited to 'xfa/fxgraphics')
-rw-r--r-- | xfa/fxgraphics/cfx_path.cpp | 90 | ||||
-rw-r--r-- | xfa/fxgraphics/cfx_path.h | 50 | ||||
-rw-r--r-- | xfa/fxgraphics/cfx_path_generator.cpp | 144 | ||||
-rw-r--r-- | xfa/fxgraphics/cfx_path_generator.h | 47 |
4 files changed, 136 insertions, 195 deletions
diff --git a/xfa/fxgraphics/cfx_path.cpp b/xfa/fxgraphics/cfx_path.cpp index d2e8f94638..3072df2475 100644 --- a/xfa/fxgraphics/cfx_path.cpp +++ b/xfa/fxgraphics/cfx_path.cpp @@ -22,42 +22,38 @@ FWL_Error CFX_Path::Create() { CFX_Path::~CFX_Path() {} -FWL_Error CFX_Path::MoveTo(FX_FLOAT x, FX_FLOAT y) { +FWL_Error CFX_Path::MoveTo(const CFX_PointF& point) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->MoveTo(x, y); + m_generator->MoveTo(point); return FWL_Error::Succeeded; } -FWL_Error CFX_Path::LineTo(FX_FLOAT x, FX_FLOAT y) { +FWL_Error CFX_Path::LineTo(const CFX_PointF& point) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->LineTo(x, y); + m_generator->LineTo(point); return FWL_Error::Succeeded; } -FWL_Error CFX_Path::BezierTo(FX_FLOAT ctrlX1, - FX_FLOAT ctrlY1, - FX_FLOAT ctrlX2, - FX_FLOAT ctrlY2, - FX_FLOAT toX, - FX_FLOAT toY) { +FWL_Error CFX_Path::BezierTo(const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& to) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->BezierTo(ctrlX1, ctrlY1, ctrlX2, ctrlY2, toX, toY); + m_generator->BezierTo(c1, c2, to); return FWL_Error::Succeeded; } -FWL_Error CFX_Path::ArcTo(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height, +FWL_Error CFX_Path::ArcTo(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT startAngle, FX_FLOAT sweepAngle) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->ArcTo(left + width / 2, top + height / 2, width / 2, height / 2, - startAngle, sweepAngle); + CFX_SizeF newSize = size / 2.0f; + m_generator->ArcTo(CFX_PointF(pos.x + newSize.width, pos.y + newSize.height), + newSize, startAngle, sweepAngle); return FWL_Error::Succeeded; } @@ -68,28 +64,20 @@ FWL_Error CFX_Path::Close() { return FWL_Error::Succeeded; } -FWL_Error CFX_Path::AddLine(FX_FLOAT x1, - FX_FLOAT y1, - FX_FLOAT x2, - FX_FLOAT y2) { +FWL_Error CFX_Path::AddLine(const CFX_PointF& p1, const CFX_PointF& p2) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->AddLine(x1, y1, x2, y2); + m_generator->AddLine(p1, p2); return FWL_Error::Succeeded; } -FWL_Error CFX_Path::AddBezier(FX_FLOAT startX, - FX_FLOAT startY, - FX_FLOAT ctrlX1, - FX_FLOAT ctrlY1, - FX_FLOAT ctrlX2, - FX_FLOAT ctrlY2, - FX_FLOAT endX, - FX_FLOAT endY) { +FWL_Error CFX_Path::AddBezier(const CFX_PointF& p1, + const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& p2) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->AddBezier(startX, startY, ctrlX1, ctrlY1, ctrlX2, ctrlY2, endX, - endY); + m_generator->AddBezier(p1, c1, c2, p2); return FWL_Error::Succeeded; } @@ -103,49 +91,45 @@ FWL_Error CFX_Path::AddRectangle(FX_FLOAT left, return FWL_Error::Succeeded; } -FWL_Error CFX_Path::AddEllipse(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height) { +FWL_Error CFX_Path::AddEllipse(const CFX_PointF& pos, const CFX_SizeF& size) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->AddEllipse(left + width / 2, top + height / 2, width / 2, - height / 2); + CFX_SizeF newSize = size / 2.0f; + m_generator->AddEllipse( + CFX_PointF(pos.x + newSize.width, pos.y + newSize.height), newSize); return FWL_Error::Succeeded; } FWL_Error CFX_Path::AddEllipse(const CFX_RectF& rect) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->AddEllipse(rect.left + rect.Width() / 2, - rect.top + rect.Height() / 2, rect.Width() / 2, - rect.Height() / 2); + m_generator->AddEllipse( + CFX_PointF(rect.left + rect.Width() / 2, rect.top + rect.Height() / 2), + CFX_SizeF(rect.Width() / 2, rect.Height() / 2)); return FWL_Error::Succeeded; } -FWL_Error CFX_Path::AddArc(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height, +FWL_Error CFX_Path::AddArc(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT startAngle, FX_FLOAT sweepAngle) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->AddArc(left + width / 2, top + height / 2, width / 2, height / 2, - startAngle, sweepAngle); + CFX_SizeF newSize = size / 2; + m_generator->AddArc(CFX_PointF(pos.x + newSize.width, pos.y + newSize.height), + newSize, startAngle, sweepAngle); return FWL_Error::Succeeded; } -FWL_Error CFX_Path::AddPie(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height, +FWL_Error CFX_Path::AddPie(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT startAngle, FX_FLOAT sweepAngle) { if (!m_generator) return FWL_Error::PropertyInvalid; - m_generator->AddPie(left + width / 2, top + height / 2, width / 2, height / 2, - startAngle, sweepAngle); + CFX_SizeF newSize = size / 2; + m_generator->AddPie(CFX_PointF(pos.x + newSize.width, pos.y + newSize.height), + newSize, startAngle, sweepAngle); return FWL_Error::Succeeded; } diff --git a/xfa/fxgraphics/cfx_path.h b/xfa/fxgraphics/cfx_path.h index 9171a91a00..1dee566788 100644 --- a/xfa/fxgraphics/cfx_path.h +++ b/xfa/fxgraphics/cfx_path.h @@ -21,50 +21,34 @@ class CFX_Path final { ~CFX_Path(); FWL_Error Create(); - FWL_Error MoveTo(FX_FLOAT x, FX_FLOAT y); - FWL_Error LineTo(FX_FLOAT x, FX_FLOAT y); - FWL_Error BezierTo(FX_FLOAT ctrlX1, - FX_FLOAT ctrlY1, - FX_FLOAT ctrlX2, - FX_FLOAT ctrlY2, - FX_FLOAT toX, - FX_FLOAT toY); - FWL_Error ArcTo(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height, + FWL_Error MoveTo(const CFX_PointF& point); + FWL_Error LineTo(const CFX_PointF& point); + FWL_Error BezierTo(const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& to); + FWL_Error ArcTo(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT startAngle, FX_FLOAT sweepAngle); FWL_Error Close(); - FWL_Error AddLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2); - FWL_Error AddBezier(FX_FLOAT startX, - FX_FLOAT startY, - FX_FLOAT ctrlX1, - FX_FLOAT ctrlY1, - FX_FLOAT ctrlX2, - FX_FLOAT ctrlY2, - FX_FLOAT endX, - FX_FLOAT endY); + FWL_Error AddLine(const CFX_PointF& p1, const CFX_PointF& p2); + FWL_Error AddBezier(const CFX_PointF& p1, + const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& p2); FWL_Error AddRectangle(FX_FLOAT left, FX_FLOAT top, FX_FLOAT width, FX_FLOAT height); - FWL_Error AddEllipse(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height); + FWL_Error AddEllipse(const CFX_PointF& pos, const CFX_SizeF& size); FWL_Error AddEllipse(const CFX_RectF& rect); - FWL_Error AddArc(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height, + FWL_Error AddArc(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT startAngle, FX_FLOAT sweepAngle); - FWL_Error AddPie(FX_FLOAT left, - FX_FLOAT top, - FX_FLOAT width, - FX_FLOAT height, + FWL_Error AddPie(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT startAngle, FX_FLOAT sweepAngle); FWL_Error AddSubpath(CFX_Path* path); diff --git a/xfa/fxgraphics/cfx_path_generator.cpp b/xfa/fxgraphics/cfx_path_generator.cpp index 8da1b4fe15..ab3d9d631a 100644 --- a/xfa/fxgraphics/cfx_path_generator.cpp +++ b/xfa/fxgraphics/cfx_path_generator.cpp @@ -19,49 +19,39 @@ void CFX_PathGenerator::AddPathData(CFX_PathData* pPathData) { m_pPathData->Append(pPathData, nullptr); } -void CFX_PathGenerator::MoveTo(FX_FLOAT x, FX_FLOAT y) { - m_pPathData->AppendPoint(x, y, FXPT_TYPE::MoveTo, false); +void CFX_PathGenerator::MoveTo(const CFX_PointF& point) { + m_pPathData->AppendPoint(point, FXPT_TYPE::MoveTo, false); } -void CFX_PathGenerator::LineTo(FX_FLOAT x, FX_FLOAT y) { - m_pPathData->AppendPoint(x, y, FXPT_TYPE::LineTo, false); +void CFX_PathGenerator::LineTo(const CFX_PointF& point) { + m_pPathData->AppendPoint(point, FXPT_TYPE::LineTo, false); } -void CFX_PathGenerator::BezierTo(FX_FLOAT ctrl_x1, - FX_FLOAT ctrl_y1, - FX_FLOAT ctrl_x2, - FX_FLOAT ctrl_y2, - FX_FLOAT to_x, - FX_FLOAT to_y) { - 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::BezierTo(const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& to) { + m_pPathData->AppendPoint(c1, FXPT_TYPE::BezierTo, false); + m_pPathData->AppendPoint(c2, FXPT_TYPE::BezierTo, false); + m_pPathData->AppendPoint(to, FXPT_TYPE::BezierTo, false); } void CFX_PathGenerator::Close() { m_pPathData->ClosePath(); } -void CFX_PathGenerator::AddLine(FX_FLOAT x1, - FX_FLOAT y1, - FX_FLOAT x2, - FX_FLOAT y2) { - m_pPathData->AppendPoint(x1, y1, FXPT_TYPE::MoveTo, false); - m_pPathData->AppendPoint(x2, y2, FXPT_TYPE::LineTo, false); +void CFX_PathGenerator::AddLine(const CFX_PointF& p1, const CFX_PointF& p2) { + m_pPathData->AppendPoint(p1, FXPT_TYPE::MoveTo, false); + m_pPathData->AppendPoint(p2, FXPT_TYPE::LineTo, false); } -void CFX_PathGenerator::AddBezier(FX_FLOAT start_x, - FX_FLOAT start_y, - FX_FLOAT ctrl_x1, - FX_FLOAT ctrl_y1, - FX_FLOAT ctrl_x2, - FX_FLOAT ctrl_y2, - FX_FLOAT end_x, - FX_FLOAT end_y) { - 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::AddBezier(const CFX_PointF& p1, + const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& p2) { + m_pPathData->AppendPoint(p1, FXPT_TYPE::MoveTo, false); + m_pPathData->AppendPoint(c1, FXPT_TYPE::BezierTo, false); + m_pPathData->AppendPoint(c2, FXPT_TYPE::BezierTo, false); + m_pPathData->AppendPoint(p2, FXPT_TYPE::BezierTo, false); } void CFX_PathGenerator::AddRectangle(FX_FLOAT x1, @@ -71,17 +61,13 @@ void CFX_PathGenerator::AddRectangle(FX_FLOAT x1, m_pPathData->AppendRect(x1, y1, x2, y2); } -void CFX_PathGenerator::AddEllipse(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height) { - AddArc(x, y, width, height, 0, FX_PI * 2); +void CFX_PathGenerator::AddEllipse(const CFX_PointF& pos, + const CFX_SizeF& size) { + AddArc(pos, size, 0, FX_PI * 2); } -void CFX_PathGenerator::ArcTo(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height, +void CFX_PathGenerator::ArcTo(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT start_angle, FX_FLOAT sweep_angle) { FX_FLOAT x0 = FXSYS_cos(sweep_angle / 2); @@ -96,46 +82,45 @@ void CFX_PathGenerator::ArcTo(FX_FLOAT x, FX_FLOAT sn = FXSYS_sin(start_angle + sweep_angle / 2); FX_FLOAT cs = FXSYS_cos(start_angle + sweep_angle / 2); - 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->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->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->AppendPoint(bezier_x, bezier_y, FXPT_TYPE::BezierTo, false); + CFX_PointF bezier; + bezier.x = pos.x + (size.width * ((px[0] * cs) - (py[0] * sn))); + bezier.y = pos.y + (size.height * ((px[0] * sn) + (py[0] * cs))); + m_pPathData->AppendPoint(bezier, FXPT_TYPE::BezierTo, false); + + bezier.x = pos.x + (size.width * ((px[1] * cs) - (py[1] * sn))); + bezier.y = pos.y + (size.height * ((px[1] * sn) + (py[1] * cs))); + m_pPathData->AppendPoint(bezier, FXPT_TYPE::BezierTo, false); + + bezier.x = pos.x + (size.width * FXSYS_cos(start_angle + sweep_angle)); + bezier.y = pos.y + (size.height * FXSYS_sin(start_angle + sweep_angle)); + m_pPathData->AppendPoint(bezier, FXPT_TYPE::BezierTo, false); } -void CFX_PathGenerator::AddArc(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height, +void CFX_PathGenerator::AddArc(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT start_angle, FX_FLOAT sweep_angle) { - if (sweep_angle == 0) { + if (sweep_angle == 0) return; - } const FX_FLOAT bezier_arc_angle_epsilon = 0.01f; - while (start_angle > FX_PI * 2) { + while (start_angle > FX_PI * 2) start_angle -= FX_PI * 2; - } - while (start_angle < 0) { + while (start_angle < 0) start_angle += FX_PI * 2; - } - if (sweep_angle >= FX_PI * 2) { + if (sweep_angle >= FX_PI * 2) sweep_angle = FX_PI * 2; - } - if (sweep_angle <= -FX_PI * 2) { + if (sweep_angle <= -FX_PI * 2) sweep_angle = -FX_PI * 2; - } - 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; + m_pPathData->AppendPoint( + pos + CFX_PointF(size.width * FXSYS_cos(start_angle), + size.height * FXSYS_sin(start_angle)), + FXPT_TYPE::MoveTo, false); + + FX_FLOAT total_sweep = 0; + FX_FLOAT local_sweep = 0; + FX_FLOAT prev_sweep = 0; bool done = false; do { if (sweep_angle < 0) { @@ -155,24 +140,25 @@ void CFX_PathGenerator::AddArc(FX_FLOAT x, done = true; } } - ArcTo(x, y, width, height, start_angle, local_sweep); + + ArcTo(pos, size, start_angle, local_sweep); start_angle += local_sweep; } while (!done); } -void CFX_PathGenerator::AddPie(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height, +void CFX_PathGenerator::AddPie(const CFX_PointF& pos, + const CFX_SizeF& size, FX_FLOAT start_angle, FX_FLOAT sweep_angle) { if (sweep_angle == 0) { - 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); + m_pPathData->AppendPoint(pos, FXPT_TYPE::MoveTo, false); + m_pPathData->AppendPoint( + pos + CFX_PointF(size.width * FXSYS_cos(start_angle), + size.height * FXSYS_sin(start_angle)), + FXPT_TYPE::LineTo, false); return; } - AddArc(x, y, width, height, start_angle, sweep_angle); - m_pPathData->AppendPoint(x, y, FXPT_TYPE::LineTo, true); + + AddArc(pos, size, start_angle, sweep_angle); + m_pPathData->AppendPoint(pos, FXPT_TYPE::LineTo, true); } diff --git a/xfa/fxgraphics/cfx_path_generator.h b/xfa/fxgraphics/cfx_path_generator.h index 916400d529..d3ba290f1c 100644 --- a/xfa/fxgraphics/cfx_path_generator.h +++ b/xfa/fxgraphics/cfx_path_generator.h @@ -20,43 +20,30 @@ class CFX_PathGenerator { void AddPathData(CFX_PathData* path_data); - void MoveTo(FX_FLOAT x, FX_FLOAT y); - void LineTo(FX_FLOAT x, FX_FLOAT y); - void BezierTo(FX_FLOAT ctrl_x1, - FX_FLOAT ctrl_y1, - FX_FLOAT ctrl_x2, - FX_FLOAT ctrl_y2, - FX_FLOAT to_x, - FX_FLOAT to_y); + void MoveTo(const CFX_PointF& point); + void LineTo(const CFX_PointF& point); + void BezierTo(const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& to); void Close(); - void ArcTo(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height, + void ArcTo(const CFX_PointF& point, + const CFX_SizeF& size, FX_FLOAT start_angle, FX_FLOAT sweep_angle); - void AddLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2); - void AddBezier(FX_FLOAT start_x, - FX_FLOAT start_y, - FX_FLOAT ctrl_x1, - FX_FLOAT ctrl_y1, - FX_FLOAT ctrl_x2, - FX_FLOAT ctrl_y2, - FX_FLOAT end_x, - FX_FLOAT end_y); + void AddLine(const CFX_PointF& p1, const CFX_PointF& p2); + void AddBezier(const CFX_PointF& p1, + const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& p2); void AddRectangle(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2); - void AddEllipse(FX_FLOAT x, FX_FLOAT y, FX_FLOAT width, FX_FLOAT height); - void AddArc(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height, + void AddEllipse(const CFX_PointF& point, const CFX_SizeF& size); + void AddArc(const CFX_PointF& point, + const CFX_SizeF& size, FX_FLOAT start_angle, FX_FLOAT sweep_angle); - void AddPie(FX_FLOAT x, - FX_FLOAT y, - FX_FLOAT width, - FX_FLOAT height, + void AddPie(const CFX_PointF& point, + const CFX_SizeF& size, FX_FLOAT start_angle, FX_FLOAT sweep_angle); |