OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fde/cfde_path.h" | 7 #include "xfa/fde/cfde_path.h" |
8 | 8 |
9 #include "xfa/fde/fde_object.h" | 9 #include "xfa/fde/fde_object.h" |
10 | 10 |
11 FX_BOOL CFDE_Path::StartFigure() { | 11 bool CFDE_Path::StartFigure() { |
12 return CloseFigure(); | 12 return CloseFigure(); |
13 } | 13 } |
14 | 14 |
15 FX_BOOL CFDE_Path::CloseFigure() { | 15 bool CFDE_Path::CloseFigure() { |
16 FX_PATHPOINT* pPoint = GetLastPoint(); | 16 FX_PATHPOINT* pPoint = GetLastPoint(); |
17 if (pPoint) | 17 if (pPoint) |
18 pPoint->m_Flag |= FXPT_CLOSEFIGURE; | 18 pPoint->m_Flag |= FXPT_CLOSEFIGURE; |
19 return TRUE; | 19 return true; |
20 } | 20 } |
21 | 21 |
22 FX_PATHPOINT* CFDE_Path::GetLastPoint(int32_t iCount) const { | 22 FX_PATHPOINT* CFDE_Path::GetLastPoint(int32_t iCount) const { |
23 if (iCount < 1) | 23 if (iCount < 1) |
24 return nullptr; | 24 return nullptr; |
25 | 25 |
26 int32_t iPoints = m_Path.GetPointCount(); | 26 int32_t iPoints = m_Path.GetPointCount(); |
27 if (iCount > iPoints) | 27 if (iCount > iPoints) |
28 return nullptr; | 28 return nullptr; |
29 return m_Path.GetPoints() + iPoints - iCount; | 29 return m_Path.GetPoints() + iPoints - iCount; |
30 } | 30 } |
31 | 31 |
32 FX_BOOL CFDE_Path::FigureClosed() const { | 32 bool CFDE_Path::FigureClosed() const { |
33 FX_PATHPOINT* pPoint = GetLastPoint(); | 33 FX_PATHPOINT* pPoint = GetLastPoint(); |
34 return pPoint ? (pPoint->m_Flag & FXPT_CLOSEFIGURE) : TRUE; | 34 return pPoint ? (pPoint->m_Flag & FXPT_CLOSEFIGURE) : true; |
35 } | 35 } |
36 | 36 |
37 FX_PATHPOINT* CFDE_Path::AddPoints(int32_t iCount) { | 37 FX_PATHPOINT* CFDE_Path::AddPoints(int32_t iCount) { |
38 if (iCount < 1) | 38 if (iCount < 1) |
39 return nullptr; | 39 return nullptr; |
40 | 40 |
41 int32_t iPoints = m_Path.GetPointCount(); | 41 int32_t iPoints = m_Path.GetPointCount(); |
42 m_Path.AddPointCount(iCount); | 42 m_Path.AddPointCount(iCount); |
43 return m_Path.GetPoints() + iPoints; | 43 return m_Path.GetPoints() + iPoints; |
44 } | 44 } |
(...skipping 20 matching lines...) Expand all Loading... |
65 p[0].m_PointY = p1.y; | 65 p[0].m_PointY = p1.y; |
66 p[0].m_Flag = FXPT_BEZIERTO; | 66 p[0].m_Flag = FXPT_BEZIERTO; |
67 p[1].m_PointX = p2.x; | 67 p[1].m_PointX = p2.x; |
68 p[1].m_PointY = p2.y; | 68 p[1].m_PointY = p2.y; |
69 p[1].m_Flag = FXPT_BEZIERTO; | 69 p[1].m_Flag = FXPT_BEZIERTO; |
70 p[2].m_PointX = p3.x; | 70 p[2].m_PointX = p3.x; |
71 p[2].m_PointY = p3.y; | 71 p[2].m_PointY = p3.y; |
72 p[2].m_Flag = FXPT_BEZIERTO; | 72 p[2].m_Flag = FXPT_BEZIERTO; |
73 } | 73 } |
74 | 74 |
75 void CFDE_Path::ArcTo(FX_BOOL bStart, | 75 void CFDE_Path::ArcTo(bool bStart, |
76 const CFX_RectF& rect, | 76 const CFX_RectF& rect, |
77 FX_FLOAT startAngle, | 77 FX_FLOAT startAngle, |
78 FX_FLOAT endAngle) { | 78 FX_FLOAT endAngle) { |
79 FX_FLOAT rx = rect.width / 2; | 79 FX_FLOAT rx = rect.width / 2; |
80 FX_FLOAT ry = rect.height / 2; | 80 FX_FLOAT ry = rect.height / 2; |
81 FX_FLOAT cx = rect.left + rx; | 81 FX_FLOAT cx = rect.left + rx; |
82 FX_FLOAT cy = rect.top + ry; | 82 FX_FLOAT cy = rect.top + ry; |
83 FX_FLOAT alpha = | 83 FX_FLOAT alpha = |
84 FXSYS_atan2(rx * FXSYS_sin(startAngle), ry * FXSYS_cos(startAngle)); | 84 FXSYS_atan2(rx * FXSYS_sin(startAngle), ry * FXSYS_cos(startAngle)); |
85 FX_FLOAT beta = | 85 FX_FLOAT beta = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 const CFX_PointF* p = points.GetData(); | 123 const CFX_PointF* p = points.GetData(); |
124 const CFX_PointF* pEnd = p + iCount; | 124 const CFX_PointF* pEnd = p + iCount; |
125 MoveTo(p[0]); | 125 MoveTo(p[0]); |
126 for (++p; p <= pEnd - 3; p += 3) | 126 for (++p; p <= pEnd - 3; p += 3) |
127 BezierTo(p[0], p[1], p[2]); | 127 BezierTo(p[0], p[1], p[2]); |
128 } | 128 } |
129 | 129 |
130 void CFDE_Path::GetCurveTangents(const CFX_PointsF& points, | 130 void CFDE_Path::GetCurveTangents(const CFX_PointsF& points, |
131 CFX_PointsF& tangents, | 131 CFX_PointsF& tangents, |
132 FX_BOOL bClosed, | 132 bool bClosed, |
133 FX_FLOAT fTension) const { | 133 FX_FLOAT fTension) const { |
134 int32_t iCount = points.GetSize(); | 134 int32_t iCount = points.GetSize(); |
135 tangents.SetSize(iCount); | 135 tangents.SetSize(iCount); |
136 if (iCount < 3) | 136 if (iCount < 3) |
137 return; | 137 return; |
138 | 138 |
139 FX_FLOAT fCoefficient = fTension / 3.0f; | 139 FX_FLOAT fCoefficient = fTension / 3.0f; |
140 const CFX_PointF* pPoints = points.GetData(); | 140 const CFX_PointF* pPoints = points.GetData(); |
141 CFX_PointF* pTangents = tangents.GetData(); | 141 CFX_PointF* pTangents = tangents.GetData(); |
142 for (int32_t i = 0; i < iCount; ++i) { | 142 for (int32_t i = 0; i < iCount; ++i) { |
143 int32_t r = i + 1; | 143 int32_t r = i + 1; |
144 int32_t s = i - 1; | 144 int32_t s = i - 1; |
145 if (r >= iCount) | 145 if (r >= iCount) |
146 r = bClosed ? (r - iCount) : (iCount - 1); | 146 r = bClosed ? (r - iCount) : (iCount - 1); |
147 if (s < 0) | 147 if (s < 0) |
148 s = bClosed ? (s + iCount) : 0; | 148 s = bClosed ? (s + iCount) : 0; |
149 | 149 |
150 pTangents[i].x += (fCoefficient * (pPoints[r].x - pPoints[s].x)); | 150 pTangents[i].x += (fCoefficient * (pPoints[r].x - pPoints[s].x)); |
151 pTangents[i].y += (fCoefficient * (pPoints[r].y - pPoints[s].y)); | 151 pTangents[i].y += (fCoefficient * (pPoints[r].y - pPoints[s].y)); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 void CFDE_Path::AddCurve(const CFX_PointsF& points, | 155 void CFDE_Path::AddCurve(const CFX_PointsF& points, |
156 FX_BOOL bClosed, | 156 bool bClosed, |
157 FX_FLOAT fTension) { | 157 FX_FLOAT fTension) { |
158 int32_t iLast = points.GetUpperBound(); | 158 int32_t iLast = points.GetUpperBound(); |
159 if (iLast < 1) | 159 if (iLast < 1) |
160 return; | 160 return; |
161 | 161 |
162 CFX_PointsF tangents; | 162 CFX_PointsF tangents; |
163 GetCurveTangents(points, tangents, bClosed, fTension); | 163 GetCurveTangents(points, tangents, bClosed, fTension); |
164 const CFX_PointF* pPoints = points.GetData(); | 164 const CFX_PointF* pPoints = points.GetData(); |
165 CFX_PointF* pTangents = tangents.GetData(); | 165 CFX_PointF* pTangents = tangents.GetData(); |
166 MoveTo(pPoints[0]); | 166 MoveTo(pPoints[0]); |
(...skipping 27 matching lines...) Expand all Loading... |
194 | 194 |
195 void CFDE_Path::AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2) { | 195 void CFDE_Path::AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2) { |
196 FX_PATHPOINT* pLast = GetLastPoint(); | 196 FX_PATHPOINT* pLast = GetLastPoint(); |
197 if (!pLast || FXSYS_fabs(pLast->m_PointX - pt1.x) > 0.001 || | 197 if (!pLast || FXSYS_fabs(pLast->m_PointX - pt1.x) > 0.001 || |
198 FXSYS_fabs(pLast->m_PointY - pt1.y) > 0.001) { | 198 FXSYS_fabs(pLast->m_PointY - pt1.y) > 0.001) { |
199 MoveTo(pt1); | 199 MoveTo(pt1); |
200 } | 200 } |
201 LineTo(pt2); | 201 LineTo(pt2); |
202 } | 202 } |
203 | 203 |
204 void CFDE_Path::AddPath(const CFDE_Path* pSrc, FX_BOOL bConnect) { | 204 void CFDE_Path::AddPath(const CFDE_Path* pSrc, bool bConnect) { |
205 if (!pSrc) | 205 if (!pSrc) |
206 return; | 206 return; |
207 | 207 |
208 int32_t iCount = pSrc->m_Path.GetPointCount(); | 208 int32_t iCount = pSrc->m_Path.GetPointCount(); |
209 if (iCount < 1) | 209 if (iCount < 1) |
210 return; | 210 return; |
211 if (bConnect) | 211 if (bConnect) |
212 LineTo(pSrc->m_Path.GetPointX(0), pSrc->m_Path.GetPointY(0)); | 212 LineTo(pSrc->m_Path.GetPointX(0), pSrc->m_Path.GetPointY(0)); |
213 | 213 |
214 m_Path.Append(&pSrc->m_Path, nullptr); | 214 m_Path.Append(&pSrc->m_Path, nullptr); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 bbox.Normalize(); | 254 bbox.Normalize(); |
255 } | 255 } |
256 | 256 |
257 void CFDE_Path::GetBBox(CFX_RectF& bbox, | 257 void CFDE_Path::GetBBox(CFX_RectF& bbox, |
258 FX_FLOAT fLineWidth, | 258 FX_FLOAT fLineWidth, |
259 FX_FLOAT fMiterLimit) const { | 259 FX_FLOAT fMiterLimit) const { |
260 CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit); | 260 CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit); |
261 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); | 261 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); |
262 bbox.Normalize(); | 262 bbox.Normalize(); |
263 } | 263 } |
OLD | NEW |