diff options
author | Nicolas Pena <npm@chromium.org> | 2017-02-07 14:21:36 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-07 19:46:09 +0000 |
commit | 79365f7e3d2d62138e79e4403d4959318776c139 (patch) | |
tree | b00196a8cdc6777ee0224653ef70bb2f2f7bb8b9 /core/fpdfapi/edit | |
parent | c222907f453e8a0e6376a86f89354eedb8285854 (diff) | |
download | pdfium-79365f7e3d2d62138e79e4403d4959318776c139.tar.xz |
Use enum class for PathPoint types.
This hopefully makes it less confusing what the description of a point is.
Currently we have defines for the types, which is confusing because a point
can only be one of the three. And it is mixed up with whether the point is
closing a figure or not.
Change-Id: Icd71355d69c77b3d52ca78e03bc379081ff87753
Reviewed-on: https://pdfium-review.googlesource.com/2552
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 19 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 51 |
2 files changed, 43 insertions, 27 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 9dba6e0ceb..a5bd741cc0 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -155,15 +155,16 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, if (i > 0) *buf << " "; *buf << pPoints[i].m_PointX << " " << pPoints[i].m_PointY; - int pointFlag = pPoints[i].m_Flag; - if (pointFlag == FXPT_MOVETO) { + FXPT_TYPE pointType = pPoints[i].m_Type; + if (pointType == FXPT_TYPE::MoveTo) { *buf << " m"; - } else if (pointFlag & FXPT_LINETO) { + } else if (pointType == FXPT_TYPE::LineTo) { *buf << " l"; - } else if (pointFlag & FXPT_BEZIERTO) { - if (i + 2 >= numPoints || pPoints[i].m_Flag != FXPT_BEZIERTO || - pPoints[i + 1].m_Flag != FXPT_BEZIERTO || - (pPoints[i + 2].m_Flag & FXPT_BEZIERTO) == 0) { + } else if (pointType == FXPT_TYPE::BezierTo) { + if (i + 2 >= numPoints || + !pPoints[i].IsTypeAndOpen(FXPT_TYPE::BezierTo) || + !pPoints[i + 1].IsTypeAndOpen(FXPT_TYPE::BezierTo) || + pPoints[i + 2].m_Type != FXPT_TYPE::BezierTo) { // If format is not supported, close the path and paint *buf << " h"; break; @@ -171,11 +172,9 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, *buf << " " << pPoints[i + 1].m_PointX << " " << pPoints[i + 1].m_PointY << " " << pPoints[i + 2].m_PointX << " " << pPoints[i + 2].m_PointY << " c"; - if (pPoints[i + 2].m_Flag & FXPT_CLOSEFIGURE) - *buf << " h"; i += 2; } - if (pointFlag & FXPT_CLOSEFIGURE) + if (pPoints[i].m_CloseFigure) *buf << " h"; } } diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index 41e61b3bab..3267f5218c 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -47,16 +47,20 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { FX_PATHPOINT* pPoints = pPathObj->m_Path.GetMutablePoints(); pPoints[0].m_PointX = 0; pPoints[0].m_PointY = 0; - pPoints[0].m_Flag = FXPT_MOVETO; + pPoints[0].m_Type = FXPT_TYPE::MoveTo; + pPoints[0].m_CloseFigure = false; pPoints[1].m_PointX = 5.2f; pPoints[1].m_PointY = 0; - pPoints[1].m_Flag = FXPT_LINETO; + pPoints[1].m_Type = FXPT_TYPE::LineTo; + pPoints[1].m_CloseFigure = false; pPoints[2].m_PointX = 5.2f; pPoints[2].m_PointY = 3.78f; - pPoints[2].m_Flag = FXPT_LINETO; + pPoints[2].m_Type = FXPT_TYPE::LineTo; + pPoints[2].m_CloseFigure = false; pPoints[3].m_PointX = 0; pPoints[3].m_PointY = 3.78f; - pPoints[3].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; + pPoints[3].m_Type = FXPT_TYPE::LineTo; + pPoints[3].m_CloseFigure = true; pPathObj->m_FillType = 0; pPathObj->m_bStroke = false; buf.Clear(); @@ -70,34 +74,44 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { FX_PATHPOINT* pPoints = pPathObj->m_Path.GetMutablePoints(); pPoints[0].m_PointX = 3.102f; pPoints[0].m_PointY = 4.67f; - pPoints[0].m_Flag = FXPT_MOVETO; + pPoints[0].m_Type = FXPT_TYPE::MoveTo; + pPoints[0].m_CloseFigure = false; pPoints[1].m_PointX = 5.45f; pPoints[1].m_PointY = 0.29f; - pPoints[1].m_Flag = FXPT_LINETO; + pPoints[1].m_Type = FXPT_TYPE::LineTo; + pPoints[1].m_CloseFigure = false; pPoints[2].m_PointX = 4.24f; pPoints[2].m_PointY = 3.15f; - pPoints[2].m_Flag = FXPT_BEZIERTO; + pPoints[2].m_Type = FXPT_TYPE::BezierTo; + pPoints[2].m_CloseFigure = false; pPoints[3].m_PointX = 4.65f; pPoints[3].m_PointY = 2.98f; - pPoints[3].m_Flag = FXPT_BEZIERTO; + pPoints[3].m_Type = FXPT_TYPE::BezierTo; + pPoints[3].m_CloseFigure = false; pPoints[4].m_PointX = 3.456f; pPoints[4].m_PointY = 0.24f; - pPoints[4].m_Flag = FXPT_BEZIERTO; + pPoints[4].m_Type = FXPT_TYPE::BezierTo; + pPoints[4].m_CloseFigure = false; pPoints[5].m_PointX = 10.6f; pPoints[5].m_PointY = 11.15f; - pPoints[5].m_Flag = FXPT_LINETO; + pPoints[5].m_Type = FXPT_TYPE::LineTo; + pPoints[5].m_CloseFigure = false; pPoints[6].m_PointX = 11; pPoints[6].m_PointY = 12.5f; - pPoints[6].m_Flag = FXPT_LINETO; + pPoints[6].m_Type = FXPT_TYPE::LineTo; + pPoints[6].m_CloseFigure = false; pPoints[7].m_PointX = 11.46f; pPoints[7].m_PointY = 12.67f; - pPoints[7].m_Flag = FXPT_BEZIERTO; + pPoints[7].m_Type = FXPT_TYPE::BezierTo; + pPoints[7].m_CloseFigure = false; pPoints[8].m_PointX = 11.84f; pPoints[8].m_PointY = 12.96f; - pPoints[8].m_Flag = FXPT_BEZIERTO; + pPoints[8].m_Type = FXPT_TYPE::BezierTo; + pPoints[8].m_CloseFigure = false; pPoints[9].m_PointX = 12; pPoints[9].m_PointY = 13.64f; - pPoints[9].m_Flag = FXPT_BEZIERTO | FXPT_CLOSEFIGURE; + pPoints[9].m_Type = FXPT_TYPE::BezierTo; + pPoints[9].m_CloseFigure = true; pPathObj->m_FillType = FXFILL_WINDING; pPathObj->m_bStroke = false; auto pTestPage = pdfium::MakeUnique<CPDF_Page>(nullptr, nullptr, false); @@ -116,13 +130,16 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { FX_PATHPOINT* pPoints = pPathObj->m_Path.GetMutablePoints(); pPoints[0].m_PointX = 1; pPoints[0].m_PointY = 2; - pPoints[0].m_Flag = FXPT_MOVETO; + pPoints[0].m_Type = FXPT_TYPE::MoveTo; + pPoints[0].m_CloseFigure = false; pPoints[1].m_PointX = 3; pPoints[1].m_PointY = 4; - pPoints[1].m_Flag = FXPT_LINETO; + pPoints[1].m_Type = FXPT_TYPE::LineTo; + pPoints[1].m_CloseFigure = false; pPoints[2].m_PointX = 5; pPoints[2].m_PointY = 6; - pPoints[2].m_Flag = FXPT_LINETO | FXPT_CLOSEFIGURE; + pPoints[2].m_Type = FXPT_TYPE::LineTo; + pPoints[2].m_CloseFigure = true; pPathObj->m_FillType = FXFILL_WINDING; pPathObj->m_bStroke = true; FX_FLOAT rgb[3] = {0.5f, 0.7f, 0.35f}; |