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 "third_party/base/stl_util.h" |
9 #include "xfa/fde/fde_object.h" | 10 #include "xfa/fde/fde_object.h" |
10 | 11 |
11 bool CFDE_Path::StartFigure() { | 12 bool CFDE_Path::StartFigure() { |
12 return CloseFigure(); | 13 return CloseFigure(); |
13 } | 14 } |
14 | 15 |
15 bool CFDE_Path::CloseFigure() { | 16 bool CFDE_Path::CloseFigure() { |
16 FX_PATHPOINT* pPoint = GetLastPoint(); | 17 FX_PATHPOINT* pPoint = GetLastPoint(); |
17 if (pPoint) | 18 if (pPoint) |
18 pPoint->m_Flag |= FXPT_CLOSEFIGURE; | 19 pPoint->m_Flag |= FXPT_CLOSEFIGURE; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (bStart) | 100 if (bStart) |
100 MoveTo(CFX_PointF(cx + rx * cos_alpha, cy + ry * sin_alpha)); | 101 MoveTo(CFX_PointF(cx + rx * cos_alpha, cy + ry * sin_alpha)); |
101 | 102 |
102 BezierTo(CFX_PointF(cx + rx * (cos_alpha - bcp * sin_alpha), | 103 BezierTo(CFX_PointF(cx + rx * (cos_alpha - bcp * sin_alpha), |
103 cy + ry * (sin_alpha + bcp * cos_alpha)), | 104 cy + ry * (sin_alpha + bcp * cos_alpha)), |
104 CFX_PointF(cx + rx * (cos_beta + bcp * sin_beta), | 105 CFX_PointF(cx + rx * (cos_beta + bcp * sin_beta), |
105 cy + ry * (sin_beta - bcp * cos_beta)), | 106 cy + ry * (sin_beta - bcp * cos_beta)), |
106 CFX_PointF(cx + rx * cos_beta, cy + ry * sin_beta)); | 107 CFX_PointF(cx + rx * cos_beta, cy + ry * sin_beta)); |
107 } | 108 } |
108 | 109 |
109 void CFDE_Path::AddBezier(const CFX_PointsF& points) { | 110 void CFDE_Path::AddBezier(const std::vector<CFX_PointF>& points) { |
110 if (points.GetSize() != 4) | 111 if (points.size() != 4) |
111 return; | 112 return; |
112 | 113 |
113 const CFX_PointF* p = points.GetData(); | 114 MoveTo(points[0]); |
114 MoveTo(p[0]); | 115 BezierTo(points[1], points[2], points[3]); |
115 BezierTo(p[1], p[2], p[3]); | |
116 } | 116 } |
117 | 117 |
118 void CFDE_Path::AddBeziers(const CFX_PointsF& points) { | 118 void CFDE_Path::AddBeziers(const std::vector<CFX_PointF>& points) { |
119 int32_t iCount = points.GetSize(); | 119 int32_t iCount = points.size(); |
120 if (iCount < 4) | 120 if (iCount < 4) |
121 return; | 121 return; |
122 | 122 |
123 const CFX_PointF* p = points.GetData(); | 123 const CFX_PointF* p = points.data(); |
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 std::vector<CFX_PointF>& points, |
131 CFX_PointsF& tangents, | 131 std::vector<CFX_PointF>* tangents, |
132 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 = pdfium::CollectionSize<int32_t>(points); |
135 tangents.SetSize(iCount); | 135 tangents->resize(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.data(); |
141 CFX_PointF* pTangents = tangents.GetData(); | 141 CFX_PointF* pTangents = tangents->data(); |
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 std::vector<CFX_PointF>& points, |
156 bool bClosed, | 156 bool bClosed, |
157 FX_FLOAT fTension) { | 157 FX_FLOAT fTension) { |
158 int32_t iLast = points.GetUpperBound(); | 158 int32_t iLast = pdfium::CollectionSize<int32_t>(points) - 1; |
159 if (iLast < 1) | 159 if (iLast < 1) |
160 return; | 160 return; |
161 | 161 |
162 CFX_PointsF tangents; | 162 std::vector<CFX_PointF> 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.data(); |
165 CFX_PointF* pTangents = tangents.GetData(); | 165 CFX_PointF* pTangents = tangents.data(); |
166 MoveTo(pPoints[0]); | 166 MoveTo(pPoints[0]); |
167 for (int32_t i = 0; i < iLast; ++i) { | 167 for (int32_t i = 0; i < iLast; ++i) { |
168 BezierTo(CFX_PointF(pPoints[i].x + pTangents[i].x, | 168 BezierTo(CFX_PointF(pPoints[i].x + pTangents[i].x, |
169 pPoints[i].y + pTangents[i].y), | 169 pPoints[i].y + pTangents[i].y), |
170 CFX_PointF(pPoints[i + 1].x - pTangents[i + 1].x, | 170 CFX_PointF(pPoints[i + 1].x - pTangents[i + 1].x, |
171 pPoints[i + 1].y - pTangents[i + 1].y), | 171 pPoints[i + 1].y - pTangents[i + 1].y), |
172 CFX_PointF(pPoints[i + 1].x, pPoints[i + 1].y)); | 172 CFX_PointF(pPoints[i + 1].x, pPoints[i + 1].y)); |
173 } | 173 } |
174 if (bClosed) { | 174 if (bClosed) { |
175 BezierTo(CFX_PointF(pPoints[iLast].x + pTangents[iLast].x, | 175 BezierTo(CFX_PointF(pPoints[iLast].x + pTangents[iLast].x, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
215 } | 215 } |
216 | 216 |
217 void CFDE_Path::AddPolygon(const CFX_PointsF& points) { | 217 void CFDE_Path::AddPolygon(const std::vector<CFX_PointF>& points) { |
218 int32_t iCount = points.GetSize(); | 218 size_t iCount = points.size(); |
219 if (iCount < 2) | 219 if (iCount < 2) |
220 return; | 220 return; |
221 | 221 |
222 AddLines(points); | 222 AddLines(points); |
223 const CFX_PointF* p = points.GetData(); | 223 const CFX_PointF* p = points.data(); |
224 if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || | 224 if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || |
225 FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) { | 225 FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) { |
226 LineTo(p[0]); | 226 LineTo(p[0]); |
227 } | 227 } |
228 CloseFigure(); | 228 CloseFigure(); |
229 } | 229 } |
230 | 230 |
231 void CFDE_Path::AddLines(const CFX_PointsF& points) { | 231 void CFDE_Path::AddLines(const std::vector<CFX_PointF>& points) { |
232 int32_t iCount = points.GetSize(); | 232 size_t iCount = points.size(); |
233 if (iCount < 2) | 233 if (iCount < 2) |
234 return; | 234 return; |
235 | 235 |
236 const CFX_PointF* p = points.GetData(); | 236 const CFX_PointF* p = points.data(); |
237 const CFX_PointF* pEnd = p + iCount; | 237 const CFX_PointF* pEnd = p + iCount; |
238 MoveTo(p[0]); | 238 MoveTo(p[0]); |
239 for (++p; p < pEnd; ++p) | 239 for (++p; p < pEnd; ++p) |
240 LineTo(*p); | 240 LineTo(*p); |
241 } | 241 } |
242 | 242 |
243 void CFDE_Path::AddRectangle(const CFX_RectF& rect) { | 243 void CFDE_Path::AddRectangle(const CFX_RectF& rect) { |
244 MoveTo(rect.TopLeft()); | 244 MoveTo(rect.TopLeft()); |
245 LineTo(rect.TopRight()); | 245 LineTo(rect.TopRight()); |
246 LineTo(rect.BottomRight()); | 246 LineTo(rect.BottomRight()); |
247 LineTo(rect.BottomLeft()); | 247 LineTo(rect.BottomLeft()); |
248 CloseFigure(); | 248 CloseFigure(); |
249 } | 249 } |
250 | 250 |
251 void CFDE_Path::GetBBox(CFX_RectF& bbox) const { | 251 void CFDE_Path::GetBBox(CFX_RectF& bbox) const { |
252 CFX_FloatRect rect = m_Path.GetBoundingBox(); | 252 CFX_FloatRect rect = m_Path.GetBoundingBox(); |
253 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); | 253 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); |
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 |