Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: xfa/fde/cfde_path.cpp

Issue 2645523006: Remove CFX_Points, CFX_PointsF in favor of std::vector (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/cfde_path.h ('k') | xfa/fde/fde_gedevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 const CFX_PointF* p = points.data();
npm 2017/01/20 19:37:33 Why do we need this variable? points[0] etc could
Tom Sepez 2017/01/20 20:01:15 Prolly because in the old way, this avoided a boun
114 MoveTo(p[0]); 115 MoveTo(p[0]);
115 BezierTo(p[1], p[2], p[3]); 116 BezierTo(p[1], p[2], p[3]);
116 } 117 }
117 118
118 void CFDE_Path::AddBeziers(const CFX_PointsF& points) { 119 void CFDE_Path::AddBeziers(const std::vector<CFX_PointF>& points) {
119 int32_t iCount = points.GetSize(); 120 int32_t iCount = points.size();
120 if (iCount < 4) 121 if (iCount < 4)
121 return; 122 return;
122 123
123 const CFX_PointF* p = points.GetData(); 124 const CFX_PointF* p = points.data();
124 const CFX_PointF* pEnd = p + iCount; 125 const CFX_PointF* pEnd = p + iCount;
125 MoveTo(p[0]); 126 MoveTo(p[0]);
126 for (++p; p <= pEnd - 3; p += 3) 127 for (++p; p <= pEnd - 3; p += 3)
npm 2017/01/20 19:37:33 Kind of similarly here, could be simplified
Tom Sepez 2017/01/20 20:01:15 Left as-is to avoid thinking about the logic.
127 BezierTo(p[0], p[1], p[2]); 128 BezierTo(p[0], p[1], p[2]);
128 } 129 }
129 130
130 void CFDE_Path::GetCurveTangents(const CFX_PointsF& points, 131 void CFDE_Path::GetCurveTangents(const std::vector<CFX_PointF>& points,
131 CFX_PointsF& tangents, 132 std::vector<CFX_PointF>& tangents,
npm 2017/01/20 19:37:33 It would be better to have a pointer here
Tom Sepez 2017/01/20 20:01:15 Done.
132 bool bClosed, 133 bool bClosed,
133 FX_FLOAT fTension) const { 134 FX_FLOAT fTension) const {
134 int32_t iCount = points.GetSize(); 135 int32_t iCount = pdfium::CollectionSize<int32_t>(points);
135 tangents.SetSize(iCount); 136 tangents.resize(iCount);
136 if (iCount < 3) 137 if (iCount < 3)
137 return; 138 return;
138 139
139 FX_FLOAT fCoefficient = fTension / 3.0f; 140 FX_FLOAT fCoefficient = fTension / 3.0f;
140 const CFX_PointF* pPoints = points.GetData(); 141 const CFX_PointF* pPoints = points.data();
141 CFX_PointF* pTangents = tangents.GetData(); 142 CFX_PointF* pTangents = tangents.data();
142 for (int32_t i = 0; i < iCount; ++i) { 143 for (int32_t i = 0; i < iCount; ++i) {
143 int32_t r = i + 1; 144 int32_t r = i + 1;
144 int32_t s = i - 1; 145 int32_t s = i - 1;
145 if (r >= iCount) 146 if (r >= iCount)
146 r = bClosed ? (r - iCount) : (iCount - 1); 147 r = bClosed ? (r - iCount) : (iCount - 1);
147 if (s < 0) 148 if (s < 0)
148 s = bClosed ? (s + iCount) : 0; 149 s = bClosed ? (s + iCount) : 0;
149 150
150 pTangents[i].x += (fCoefficient * (pPoints[r].x - pPoints[s].x)); 151 pTangents[i].x += (fCoefficient * (pPoints[r].x - pPoints[s].x));
151 pTangents[i].y += (fCoefficient * (pPoints[r].y - pPoints[s].y)); 152 pTangents[i].y += (fCoefficient * (pPoints[r].y - pPoints[s].y));
152 } 153 }
153 } 154 }
154 155
155 void CFDE_Path::AddCurve(const CFX_PointsF& points, 156 void CFDE_Path::AddCurve(const std::vector<CFX_PointF>& points,
156 bool bClosed, 157 bool bClosed,
157 FX_FLOAT fTension) { 158 FX_FLOAT fTension) {
158 int32_t iLast = points.GetUpperBound(); 159 int32_t iLast = pdfium::CollectionSize<int32_t>(points) - 1;
159 if (iLast < 1) 160 if (iLast < 1)
160 return; 161 return;
161 162
162 CFX_PointsF tangents; 163 std::vector<CFX_PointF> tangents;
163 GetCurveTangents(points, tangents, bClosed, fTension); 164 GetCurveTangents(points, tangents, bClosed, fTension);
164 const CFX_PointF* pPoints = points.GetData(); 165 const CFX_PointF* pPoints = points.data();
165 CFX_PointF* pTangents = tangents.GetData(); 166 CFX_PointF* pTangents = tangents.data();
166 MoveTo(pPoints[0]); 167 MoveTo(pPoints[0]);
167 for (int32_t i = 0; i < iLast; ++i) { 168 for (int32_t i = 0; i < iLast; ++i) {
168 BezierTo(CFX_PointF(pPoints[i].x + pTangents[i].x, 169 BezierTo(CFX_PointF(pPoints[i].x + pTangents[i].x,
169 pPoints[i].y + pTangents[i].y), 170 pPoints[i].y + pTangents[i].y),
170 CFX_PointF(pPoints[i + 1].x - pTangents[i + 1].x, 171 CFX_PointF(pPoints[i + 1].x - pTangents[i + 1].x,
171 pPoints[i + 1].y - pTangents[i + 1].y), 172 pPoints[i + 1].y - pTangents[i + 1].y),
172 CFX_PointF(pPoints[i + 1].x, pPoints[i + 1].y)); 173 CFX_PointF(pPoints[i + 1].x, pPoints[i + 1].y));
173 } 174 }
174 if (bClosed) { 175 if (bClosed) {
175 BezierTo(CFX_PointF(pPoints[iLast].x + pTangents[iLast].x, 176 BezierTo(CFX_PointF(pPoints[iLast].x + pTangents[iLast].x,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 208
208 int32_t iCount = pSrc->m_Path.GetPointCount(); 209 int32_t iCount = pSrc->m_Path.GetPointCount();
209 if (iCount < 1) 210 if (iCount < 1)
210 return; 211 return;
211 if (bConnect) 212 if (bConnect)
212 LineTo(pSrc->m_Path.GetPointX(0), pSrc->m_Path.GetPointY(0)); 213 LineTo(pSrc->m_Path.GetPointX(0), pSrc->m_Path.GetPointY(0));
213 214
214 m_Path.Append(&pSrc->m_Path, nullptr); 215 m_Path.Append(&pSrc->m_Path, nullptr);
215 } 216 }
216 217
217 void CFDE_Path::AddPolygon(const CFX_PointsF& points) { 218 void CFDE_Path::AddPolygon(const std::vector<CFX_PointF>& points) {
218 int32_t iCount = points.GetSize(); 219 size_t iCount = points.size();
219 if (iCount < 2) 220 if (iCount < 2)
220 return; 221 return;
221 222
222 AddLines(points); 223 AddLines(points);
223 const CFX_PointF* p = points.GetData(); 224 const CFX_PointF* p = points.data();
224 if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || 225 if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f ||
225 FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) { 226 FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) {
226 LineTo(p[0]); 227 LineTo(p[0]);
227 } 228 }
228 CloseFigure(); 229 CloseFigure();
229 } 230 }
230 231
231 void CFDE_Path::AddLines(const CFX_PointsF& points) { 232 void CFDE_Path::AddLines(const std::vector<CFX_PointF>& points) {
232 int32_t iCount = points.GetSize(); 233 size_t iCount = points.size();
233 if (iCount < 2) 234 if (iCount < 2)
234 return; 235 return;
235 236
236 const CFX_PointF* p = points.GetData(); 237 const CFX_PointF* p = points.data();
237 const CFX_PointF* pEnd = p + iCount; 238 const CFX_PointF* pEnd = p + iCount;
238 MoveTo(p[0]); 239 MoveTo(p[0]);
239 for (++p; p < pEnd; ++p) 240 for (++p; p < pEnd; ++p)
240 LineTo(*p); 241 LineTo(*p);
241 } 242 }
242 243
243 void CFDE_Path::AddRectangle(const CFX_RectF& rect) { 244 void CFDE_Path::AddRectangle(const CFX_RectF& rect) {
244 MoveTo(rect.TopLeft()); 245 MoveTo(rect.TopLeft());
245 LineTo(rect.TopRight()); 246 LineTo(rect.TopRight());
246 LineTo(rect.BottomRight()); 247 LineTo(rect.BottomRight());
247 LineTo(rect.BottomLeft()); 248 LineTo(rect.BottomLeft());
248 CloseFigure(); 249 CloseFigure();
249 } 250 }
250 251
251 void CFDE_Path::GetBBox(CFX_RectF& bbox) const { 252 void CFDE_Path::GetBBox(CFX_RectF& bbox) const {
252 CFX_FloatRect rect = m_Path.GetBoundingBox(); 253 CFX_FloatRect rect = m_Path.GetBoundingBox();
253 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); 254 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height());
254 bbox.Normalize(); 255 bbox.Normalize();
255 } 256 }
256 257
257 void CFDE_Path::GetBBox(CFX_RectF& bbox, 258 void CFDE_Path::GetBBox(CFX_RectF& bbox,
258 FX_FLOAT fLineWidth, 259 FX_FLOAT fLineWidth,
259 FX_FLOAT fMiterLimit) const { 260 FX_FLOAT fMiterLimit) const {
260 CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit); 261 CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit);
261 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); 262 bbox.Set(rect.left, rect.top, rect.Width(), rect.Height());
262 bbox.Normalize(); 263 bbox.Normalize();
263 } 264 }
OLDNEW
« no previous file with comments | « xfa/fde/cfde_path.h ('k') | xfa/fde/fde_gedevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698