1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "draw/path.h"
17
18 #include "impl_factory.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
Path()23 Path::Path() noexcept : impl_(ImplFactory::CreatePathImpl()) {}
24
Path(const Path & other)25 Path::Path(const Path& other) noexcept
26 {
27 impl_.reset(other.impl_->Clone());
28 }
29
operator =(const Path & other)30 Path& Path::operator=(const Path &other) noexcept
31 {
32 impl_.reset(other.impl_->Clone());
33 return *this;
34 }
35
~Path()36 Path::~Path() {}
37
BuildFromSVGString(const std::string & str)38 bool Path::BuildFromSVGString(const std::string& str)
39 {
40 return impl_->InitWithSVGString(str);
41 }
42
ConvertToSVGString() const43 std::string Path::ConvertToSVGString() const
44 {
45 return impl_->ConvertToSVGString();
46 }
47
MoveTo(scalar x,scalar y)48 void Path::MoveTo(scalar x, scalar y)
49 {
50 impl_->MoveTo(x, y);
51 }
52
LineTo(scalar x,scalar y)53 void Path::LineTo(scalar x, scalar y)
54 {
55 impl_->LineTo(x, y);
56 }
57
ArcTo(scalar pt1X,scalar pt1Y,scalar pt2X,scalar pt2Y,scalar startAngle,scalar sweepAngle)58 void Path::ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle)
59 {
60 impl_->ArcTo(pt1X, pt1Y, pt2X, pt2Y, startAngle, sweepAngle);
61 }
62
ArcTo(const Point & pt1,const Point & pt2,scalar startAngle,scalar sweepAngle)63 void Path::ArcTo(const Point& pt1, const Point& pt2, scalar startAngle, scalar sweepAngle)
64 {
65 impl_->ArcTo(pt1.GetX(), pt1.GetY(), pt2.GetX(), pt2.GetY(), startAngle, sweepAngle);
66 }
67
ArcTo(scalar rx,scalar ry,scalar angle,PathDirection direction,scalar endX,scalar endY)68 void Path::ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY)
69 {
70 impl_->ArcTo(rx, ry, angle, direction, endX, endY);
71 }
72
ArcTo(scalar x1,scalar y1,scalar x2,scalar y2,scalar radius)73 void Path::ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius)
74 {
75 impl_->ArcTo(x1, y1, x2, y2, radius);
76 }
77
CubicTo(scalar ctrlPt1X,scalar ctrlPt1Y,scalar ctrlPt2X,scalar ctrlPt2Y,scalar endPtX,scalar endPtY)78 void Path::CubicTo(scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY)
79 {
80 impl_->CubicTo(ctrlPt1X, ctrlPt1Y, ctrlPt2X, ctrlPt2Y, endPtX, endPtY);
81 }
82
CubicTo(const Point & ctrlPt1,const Point & ctrlPt2,const Point & endPt)83 void Path::CubicTo(const Point& ctrlPt1, const Point& ctrlPt2, const Point& endPt)
84 {
85 impl_->CubicTo(ctrlPt1.GetX(), ctrlPt1.GetY(), ctrlPt2.GetX(), ctrlPt2.GetY(), endPt.GetX(), endPt.GetY());
86 }
87
QuadTo(scalar ctrlPtX,scalar ctrlPtY,scalar endPtX,scalar endPtY)88 void Path::QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY)
89 {
90 impl_->QuadTo(ctrlPtX, ctrlPtY, endPtX, endPtY);
91 }
92
QuadTo(const Point & ctrlPt,const Point endPt)93 void Path::QuadTo(const Point& ctrlPt, const Point endPt)
94 {
95 impl_->QuadTo(ctrlPt.GetX(), ctrlPt.GetY(), endPt.GetX(), endPt.GetY());
96 }
97
ConicTo(scalar ctrlX,scalar ctrlY,scalar endX,scalar endY,scalar weight)98 void Path::ConicTo(scalar ctrlX, scalar ctrlY, scalar endX, scalar endY, scalar weight)
99 {
100 impl_->ConicTo(ctrlX, ctrlY, endX, endY, weight);
101 }
102
RMoveTo(scalar dx,scalar dy)103 void Path::RMoveTo(scalar dx, scalar dy)
104 {
105 impl_->RMoveTo(dx, dy);
106 }
107
RLineTo(scalar dx,scalar dy)108 void Path::RLineTo(scalar dx, scalar dy)
109 {
110 impl_->RLineTo(dx, dy);
111 }
112
RArcTo(scalar rx,scalar ry,scalar angle,PathDirection direction,scalar dx,scalar dy)113 void Path::RArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar dx, scalar dy)
114 {
115 impl_->RArcTo(rx, ry, angle, direction, dx, dy);
116 }
117
RCubicTo(scalar dx1,scalar dy1,scalar dx2,scalar dy2,scalar dx3,scalar dy3)118 void Path::RCubicTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2, scalar dx3, scalar dy3)
119 {
120 impl_->RCubicTo(dx1, dy1, dx2, dy2, dx3, dy3);
121 }
122
RConicTo(scalar ctrlPtX,scalar ctrlPtY,scalar endPtX,scalar endPtY,scalar weight)123 void Path::RConicTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY, scalar weight)
124 {
125 impl_->RConicTo(ctrlPtX, ctrlPtY, endPtX, endPtY, weight);
126 }
127
RQuadTo(scalar dx1,scalar dy1,scalar dx2,scalar dy2)128 void Path::RQuadTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2)
129 {
130 impl_->RQuadTo(dx1, dy1, dx2, dy2);
131 }
132
AddRect(const Rect & rect,PathDirection dir)133 void Path::AddRect(const Rect& rect, PathDirection dir)
134 {
135 impl_->AddRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), dir);
136 }
137
AddRect(const Rect & rect,unsigned start,PathDirection dir)138 void Path::AddRect(const Rect& rect, unsigned start, PathDirection dir)
139 {
140 impl_->AddRect(rect, start, dir);
141 }
142
AddRect(scalar left,scalar top,scalar right,scalar bottom,PathDirection dir)143 void Path::AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir)
144 {
145 impl_->AddRect(left, top, right, bottom, dir);
146 }
147
AddOval(const Rect & oval,PathDirection dir)148 void Path::AddOval(const Rect& oval, PathDirection dir)
149 {
150 impl_->AddOval(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), dir);
151 }
152
AddOval(const Rect & oval,unsigned start,PathDirection dir)153 void Path::AddOval(const Rect& oval, unsigned start, PathDirection dir)
154 {
155 impl_->AddOval(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), start, dir);
156 }
157
AddArc(const Rect & oval,scalar startAngle,scalar sweepAngle)158 void Path::AddArc(const Rect& oval, scalar startAngle, scalar sweepAngle)
159 {
160 impl_->AddArc(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), startAngle, sweepAngle);
161 }
162
AddPoly(const std::vector<Point> & points,int count,bool close)163 void Path::AddPoly(const std::vector<Point>& points, int count, bool close)
164 {
165 impl_->AddPoly(points, count, close);
166 }
167
AddCircle(scalar x,scalar y,scalar radius,PathDirection dir)168 void Path::AddCircle(scalar x, scalar y, scalar radius, PathDirection dir)
169 {
170 impl_->AddCircle(x, y, radius, dir);
171 }
172
AddRoundRect(const Rect & rect,scalar xRadius,scalar yRadius,PathDirection dir)173 void Path::AddRoundRect(const Rect& rect, scalar xRadius, scalar yRadius, PathDirection dir)
174 {
175 impl_->AddRoundRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), xRadius, yRadius, dir);
176 }
177
AddRoundRect(const RoundRect & rrect,PathDirection dir)178 void Path::AddRoundRect(const RoundRect& rrect, PathDirection dir)
179 {
180 impl_->AddRoundRect(rrect, dir);
181 }
182
AddPath(const Path & src,scalar dx,scalar dy,PathAddMode mode)183 void Path::AddPath(const Path& src, scalar dx, scalar dy, PathAddMode mode)
184 {
185 impl_->AddPath(src, dx, dy, mode);
186 }
187
AddPath(const Path & src,PathAddMode mode)188 void Path::AddPath(const Path& src, PathAddMode mode)
189 {
190 impl_->AddPath(src, mode);
191 }
192
AddPath(const Path & src,const Matrix & matrix,PathAddMode mode)193 void Path::AddPath(const Path& src, const Matrix& matrix, PathAddMode mode)
194 {
195 impl_->AddPath(src, matrix, mode);
196 }
197
Contains(scalar x,scalar y) const198 bool Path::Contains(scalar x, scalar y) const
199 {
200 return impl_->Contains(x, y);
201 }
202
ReverseAddPath(const Path & src)203 void Path::ReverseAddPath(const Path& src)
204 {
205 impl_->ReverseAddPath(src);
206 }
207
GetBounds() const208 Rect Path::GetBounds() const
209 {
210 return impl_->GetBounds();
211 }
212
SetFillStyle(PathFillType fillstyle)213 void Path::SetFillStyle(PathFillType fillstyle)
214 {
215 impl_->SetFillStyle(fillstyle);
216 }
217
Interpolate(const Path & ending,scalar weight,Path & out)218 bool Path::Interpolate(const Path& ending, scalar weight, Path& out)
219 {
220 return impl_->Interpolate(ending, weight, out);
221 }
222
BuildFromInterpolate(const Path & src,const Path & ending,scalar weight)223 bool Path::BuildFromInterpolate(const Path& src, const Path& ending, scalar weight)
224 {
225 return impl_->InitWithInterpolate(src, ending, weight);
226 }
227
TransformWithPerspectiveClip(const Matrix & matrix,Path * dst,bool applyPerspectiveClip)228 void Path::TransformWithPerspectiveClip(const Matrix& matrix, Path* dst, bool applyPerspectiveClip)
229 {
230 impl_->TransformWithPerspectiveClip(matrix, dst, applyPerspectiveClip);
231 }
232
Transform(const Matrix & matrix)233 void Path::Transform(const Matrix& matrix)
234 {
235 impl_->Transform(matrix);
236 }
237
Offset(scalar dx,scalar dy)238 void Path::Offset(scalar dx, scalar dy)
239 {
240 impl_->Offset(dx, dy);
241 }
242
Offset(Path * dst,scalar dx,scalar dy)243 void Path::Offset(Path* dst, scalar dx, scalar dy)
244 {
245 impl_->Offset(dst, dx, dy);
246 }
247
Op(const Path & path1,Path & path2,PathOp op)248 bool Path::Op(const Path& path1, Path& path2, PathOp op)
249 {
250 return impl_->OpWith(path1, path2, op);
251 }
252
IsValid() const253 bool Path::IsValid() const
254 {
255 return impl_->IsValid();
256 }
257
Reset()258 void Path::Reset()
259 {
260 impl_->Reset();
261 }
262
Close()263 void Path::Close()
264 {
265 impl_->Close();
266 }
267
GetLength(bool forceClosed) const268 scalar Path::GetLength(bool forceClosed) const
269 {
270 return impl_->GetLength(forceClosed);
271 }
272
GetPositionAndTangent(scalar distance,Point & position,Point & tangent,bool forceClosed) const273 bool Path::GetPositionAndTangent(scalar distance, Point& position, Point& tangent, bool forceClosed) const
274 {
275 return impl_->GetPositionAndTangent(distance, position, tangent, forceClosed);
276 }
277
IsClosed(bool forceClosed) const278 bool Path::IsClosed(bool forceClosed) const
279 {
280 return impl_->IsClosed(forceClosed);
281 }
282
GetMatrix(bool forceClosed,float distance,Matrix * matrix,PathMeasureMatrixFlags flag)283 bool Path::GetMatrix(bool forceClosed, float distance, Matrix* matrix, PathMeasureMatrixFlags flag)
284 {
285 return impl_->GetMatrix(forceClosed, distance, matrix, flag);
286 }
287
Serialize() const288 std::shared_ptr<Data> Path::Serialize() const
289 {
290 return impl_->Serialize();
291 }
292
Deserialize(std::shared_ptr<Data> data)293 bool Path::Deserialize(std::shared_ptr<Data> data)
294 {
295 return impl_->Deserialize(data);
296 }
297
298 } // namespace Drawing
299 } // namespace Rosen
300 } // namespace OHOS
301