diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-02-15 11:07:32 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-15 17:47:57 +0000 |
commit | e4602321f3175fa5addb6761d0e94f5c2fc93d0c (patch) | |
tree | 6671774659645fad6d9ce55a5910b4665a25094f /xfa/fxgraphics/cfx_path_generator.cpp | |
parent | eb55885e9a9eec670ed98cbd12dc96d63e6a6623 (diff) | |
download | pdfium-e4602321f3175fa5addb6761d0e94f5c2fc93d0c.tar.xz |
Cleanup CFX_PathData.
This CL replaces the array of path points with a vector. Cleaning up the usage
as required.
Change-Id: Ifa386a2c847005fef68af748ebe99c4e08961238
Reviewed-on: https://pdfium-review.googlesource.com/2710
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxgraphics/cfx_path_generator.cpp')
-rw-r--r-- | xfa/fxgraphics/cfx_path_generator.cpp | 95 |
1 files changed, 28 insertions, 67 deletions
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); } |