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 | |
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')
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 19 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 51 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_path.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_path.h | 1 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 77 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_renderstatus.cpp | 9 |
7 files changed, 91 insertions, 72 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}; diff --git a/core/fpdfapi/page/cpdf_path.cpp b/core/fpdfapi/page/cpdf_path.cpp index 2bfda75f56..8151ae46d7 100644 --- a/core/fpdfapi/page/cpdf_path.cpp +++ b/core/fpdfapi/page/cpdf_path.cpp @@ -28,10 +28,6 @@ FX_PATHPOINT* CPDF_Path::GetMutablePoints() { return m_Ref.GetPrivateCopy()->GetPoints(); } -int CPDF_Path::GetFlag(int index) const { - return m_Ref.GetObject()->GetFlag(index); -} - FX_FLOAT CPDF_Path::GetPointX(int index) const { return m_Ref.GetObject()->GetPointX(index); } diff --git a/core/fpdfapi/page/cpdf_path.h b/core/fpdfapi/page/cpdf_path.h index 407905e429..252be2673c 100644 --- a/core/fpdfapi/page/cpdf_path.h +++ b/core/fpdfapi/page/cpdf_path.h @@ -27,7 +27,6 @@ class CPDF_Path { const FX_PATHPOINT* GetPoints() const; FX_PATHPOINT* GetMutablePoints(); - int GetFlag(int index) const; FX_FLOAT GetPointX(int index) const; FX_FLOAT GetPointY(int index) const; CFX_FloatRect GetBoundingBox() const; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 0e78612bc9..3dec01a52e 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -586,7 +586,7 @@ void CPDF_StreamContentParser::Handle_FillStrokePath() { } void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath() { - AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE); + AddPathPoint(m_PathStartX, m_PathStartY, FXPT_TYPE::LineTo, true); AddPathObject(FXFILL_ALTERNATE, true); } @@ -682,9 +682,9 @@ void CPDF_StreamContentParser::Handle_BeginText() { } void CPDF_StreamContentParser::Handle_CurveTo_123() { - AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO); - AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); - AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); + AddPathPoint(GetNumber(5), GetNumber(4), FXPT_TYPE::BezierTo, false); + AddPathPoint(GetNumber(3), GetNumber(2), FXPT_TYPE::BezierTo, false); + AddPathPoint(GetNumber(1), GetNumber(0), FXPT_TYPE::BezierTo, false); } void CPDF_StreamContentParser::Handle_ConcatMatrix() { @@ -887,9 +887,9 @@ void CPDF_StreamContentParser::Handle_ClosePath() { return; } if (m_PathStartX != m_PathCurrentX || m_PathStartY != m_PathCurrentY) { - AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE); - } else if (m_pPathPoints[m_PathPointCount - 1].m_Flag != FXPT_MOVETO) { - m_pPathPoints[m_PathPointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; + AddPathPoint(m_PathStartX, m_PathStartY, FXPT_TYPE::LineTo, true); + } else if (m_pPathPoints[m_PathPointCount - 1].m_Type != FXPT_TYPE::MoveTo) { + m_pPathPoints[m_PathPointCount - 1].m_CloseFigure = true; } } @@ -937,14 +937,14 @@ void CPDF_StreamContentParser::Handle_LineTo() { if (m_ParamCount != 2) return; - AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO); + AddPathPoint(GetNumber(1), GetNumber(0), FXPT_TYPE::LineTo, false); } void CPDF_StreamContentParser::Handle_MoveTo() { if (m_ParamCount != 2) return; - AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO); + AddPathPoint(GetNumber(1), GetNumber(0), FXPT_TYPE::MoveTo, false); ParsePathObject(); } @@ -982,11 +982,11 @@ void CPDF_StreamContentParser::AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h) { - AddPathPoint(x, y, FXPT_MOVETO); - AddPathPoint(x + w, y, FXPT_LINETO); - AddPathPoint(x + w, y + h, FXPT_LINETO); - AddPathPoint(x, y + h, FXPT_LINETO); - AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE); + AddPathPoint(x, y, FXPT_TYPE::MoveTo, false); + AddPathPoint(x + w, y, FXPT_TYPE::LineTo, false); + AddPathPoint(x + w, y + h, FXPT_TYPE::LineTo, false); + AddPathPoint(x, y + h, FXPT_TYPE::LineTo, false); + AddPathPoint(x, y, FXPT_TYPE::LineTo, true); } void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() { @@ -1416,9 +1416,9 @@ void CPDF_StreamContentParser::Handle_MoveToNextLine() { } void CPDF_StreamContentParser::Handle_CurveTo_23() { - AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO); - AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); - AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); + AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_TYPE::BezierTo, false); + AddPathPoint(GetNumber(3), GetNumber(2), FXPT_TYPE::BezierTo, false); + AddPathPoint(GetNumber(1), GetNumber(0), FXPT_TYPE::BezierTo, false); } void CPDF_StreamContentParser::Handle_SetLineWidth() { @@ -1434,9 +1434,9 @@ void CPDF_StreamContentParser::Handle_EOClip() { } void CPDF_StreamContentParser::Handle_CurveTo_13() { - AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); - AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); - AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); + AddPathPoint(GetNumber(3), GetNumber(2), FXPT_TYPE::BezierTo, false); + AddPathPoint(GetNumber(1), GetNumber(0), FXPT_TYPE::BezierTo, false); + AddPathPoint(GetNumber(1), GetNumber(0), FXPT_TYPE::BezierTo, false); } void CPDF_StreamContentParser::Handle_NextLineShowText() { @@ -1452,14 +1452,17 @@ void CPDF_StreamContentParser::Handle_NextLineShowText_Space() { void CPDF_StreamContentParser::Handle_Invalid() {} -void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) { +void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, + FX_FLOAT y, + FXPT_TYPE type, + bool close) { m_PathCurrentX = x; m_PathCurrentY = y; - if (flag == FXPT_MOVETO) { + if (type == FXPT_TYPE::MoveTo && !close) { m_PathStartX = x; m_PathStartY = y; if (m_PathPointCount && - m_pPathPoints[m_PathPointCount - 1].m_Flag == FXPT_MOVETO) { + 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; return; @@ -1479,7 +1482,8 @@ void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) { m_pPathPoints = pNewPoints; m_PathAllocSize = newsize; } - m_pPathPoints[m_PathPointCount - 1].m_Flag = flag; + 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; } @@ -1498,7 +1502,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { return; } if (PathPointCount && - m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) { + m_pPathPoints[PathPointCount - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) { PathPointCount--; } CPDF_Path Path; @@ -1576,29 +1580,30 @@ void CPDF_StreamContentParser::ParsePathObject() { if (len == 1) { switch (strc[0]) { case kPathOperatorSubpath: - AddPathPoint(params[0], params[1], FXPT_MOVETO); + AddPathPoint(params[0], params[1], FXPT_TYPE::MoveTo, false); nParams = 0; break; case kPathOperatorLine: - AddPathPoint(params[0], params[1], FXPT_LINETO); + AddPathPoint(params[0], params[1], FXPT_TYPE::LineTo, false); nParams = 0; break; case kPathOperatorCubicBezier1: - AddPathPoint(params[0], params[1], FXPT_BEZIERTO); - AddPathPoint(params[2], params[3], FXPT_BEZIERTO); - AddPathPoint(params[4], params[5], FXPT_BEZIERTO); + AddPathPoint(params[0], params[1], FXPT_TYPE::BezierTo, false); + AddPathPoint(params[2], params[3], FXPT_TYPE::BezierTo, false); + AddPathPoint(params[4], params[5], FXPT_TYPE::BezierTo, false); nParams = 0; break; case kPathOperatorCubicBezier2: - AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO); - AddPathPoint(params[0], params[1], FXPT_BEZIERTO); - AddPathPoint(params[2], params[3], FXPT_BEZIERTO); + AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_TYPE::BezierTo, + false); + AddPathPoint(params[0], params[1], FXPT_TYPE::BezierTo, false); + AddPathPoint(params[2], params[3], FXPT_TYPE::BezierTo, false); nParams = 0; break; case kPathOperatorCubicBezier3: - AddPathPoint(params[0], params[1], FXPT_BEZIERTO); - AddPathPoint(params[2], params[3], FXPT_BEZIERTO); - AddPathPoint(params[2], params[3], FXPT_BEZIERTO); + AddPathPoint(params[0], params[1], FXPT_TYPE::BezierTo, false); + AddPathPoint(params[2], params[3], FXPT_TYPE::BezierTo, false); + AddPathPoint(params[2], params[3], FXPT_TYPE::BezierTo, false); nParams = 0; break; case kPathOperatorClosePath: diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h index e23ae8ea99..ca7ea7c106 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.h +++ b/core/fpdfapi/page/cpdf_streamcontentparser.h @@ -96,7 +96,7 @@ class CPDF_StreamContentParser { void ConvertTextSpace(FX_FLOAT& x, FX_FLOAT& y); void OnChangeTextMatrix(); void ParsePathObject(); - void AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag); + void AddPathPoint(FX_FLOAT x, FX_FLOAT y, FXPT_TYPE type, bool close); void AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h); void AddPathObject(int FillType, bool bStroke); CPDF_ImageObject* AddImage(std::unique_ptr<CPDF_Stream> pStream); diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 35d061616b..8fe7a31ce4 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -816,9 +816,12 @@ void DrawCoonPatchMeshes( patch.fill_mode = fill_mode; patch.path.SetPointCount(13); FX_PATHPOINT* pPoints = patch.path.GetPoints(); - pPoints[0].m_Flag = FXPT_MOVETO; - for (int i = 1; i < 13; i++) - pPoints[i].m_Flag = FXPT_BEZIERTO; + pPoints[0].m_Type = FXPT_TYPE::MoveTo; + pPoints[0].m_CloseFigure = false; + for (int i = 1; i < 13; i++) { + pPoints[i].m_Type = FXPT_TYPE::BezierTo; + pPoints[i].m_CloseFigure = false; + } CFX_PointF coords[16]; int point_count = type == kTensorProductPatchMeshShading ? 16 : 12; while (!stream.BitStream()->IsEOF()) { |