• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
RMoveTo(scalar dx,scalar dy)98 void Path::RMoveTo(scalar dx, scalar dy)
99 {
100     impl_->RMoveTo(dx, dy);
101 }
102 
RLineTo(scalar dx,scalar dy)103 void Path::RLineTo(scalar dx, scalar dy)
104 {
105     impl_->RLineTo(dx, dy);
106 }
107 
RArcTo(scalar rx,scalar ry,scalar angle,PathDirection direction,scalar dx,scalar dy)108 void Path::RArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar dx, scalar dy)
109 {
110     impl_->RArcTo(rx, ry, angle, direction, dx, dy);
111 }
112 
RCubicTo(scalar dx1,scalar dy1,scalar dx2,scalar dy2,scalar dx3,scalar dy3)113 void Path::RCubicTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2, scalar dx3, scalar dy3)
114 {
115     impl_->RCubicTo(dx1, dy1, dx2, dy2, dx3, dy3);
116 }
117 
RQuadTo(scalar dx1,scalar dy1,scalar dx2,scalar dy2)118 void Path::RQuadTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2)
119 {
120     impl_->RQuadTo(dx1, dy1, dx2, dy2);
121 }
122 
AddRect(const Rect & rect,PathDirection dir)123 void Path::AddRect(const Rect& rect, PathDirection dir)
124 {
125     impl_->AddRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), dir);
126 }
127 
AddRect(scalar left,scalar top,scalar right,scalar bottom,PathDirection dir)128 void Path::AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir)
129 {
130     impl_->AddRect(left, top, right, bottom, dir);
131 }
132 
AddOval(const Rect & oval,PathDirection dir)133 void Path::AddOval(const Rect& oval, PathDirection dir)
134 {
135     impl_->AddOval(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), dir);
136 }
137 
AddArc(const Rect & oval,scalar startAngle,scalar sweepAngle)138 void Path::AddArc(const Rect& oval, scalar startAngle, scalar sweepAngle)
139 {
140     impl_->AddArc(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), startAngle, sweepAngle);
141 }
142 
AddPoly(const std::vector<Point> & points,int count,bool close)143 void Path::AddPoly(const std::vector<Point>& points, int count, bool close)
144 {
145     impl_->AddPoly(points, count, close);
146 }
147 
AddCircle(scalar x,scalar y,scalar radius,PathDirection dir)148 void Path::AddCircle(scalar x, scalar y, scalar radius, PathDirection dir)
149 {
150     impl_->AddCircle(x, y, radius, dir);
151 }
152 
AddRoundRect(const Rect & rect,scalar xRadius,scalar yRadius,PathDirection dir)153 void Path::AddRoundRect(const Rect& rect, scalar xRadius, scalar yRadius, PathDirection dir)
154 {
155     impl_->AddRoundRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), xRadius, yRadius, dir);
156 }
157 
AddRoundRect(const RoundRect & rrect,PathDirection dir)158 void Path::AddRoundRect(const RoundRect& rrect, PathDirection dir)
159 {
160     impl_->AddRoundRect(rrect, dir);
161 }
162 
AddPath(const Path & src,scalar dx,scalar dy)163 void Path::AddPath(const Path& src, scalar dx, scalar dy)
164 {
165     impl_->AddPath(src, dx, dy);
166 }
167 
AddPath(const Path & src)168 void Path::AddPath(const Path& src)
169 {
170     impl_->AddPath(src);
171 }
172 
AddPath(const Path & src,const Matrix & matrix)173 void Path::AddPath(const Path& src, const Matrix& matrix)
174 {
175     impl_->AddPathWithMatrix(src, matrix);
176 }
177 
Contains(scalar x,scalar y) const178 bool Path::Contains(scalar x, scalar y) const
179 {
180     return impl_->Contains(x, y);
181 }
182 
ReverseAddPath(const Path & src)183 void Path::ReverseAddPath(const Path& src)
184 {
185     impl_->ReverseAddPath(src);
186 }
187 
GetBounds() const188 Rect Path::GetBounds() const
189 {
190     return impl_->GetBounds();
191 }
192 
SetFillStyle(PathFillType fillstyle)193 void Path::SetFillStyle(PathFillType fillstyle)
194 {
195     impl_->SetFillStyle(fillstyle);
196 }
197 
Interpolate(const Path & ending,scalar weight,Path & out)198 bool Path::Interpolate(const Path& ending, scalar weight, Path& out)
199 {
200     return impl_->Interpolate(ending, weight, out);
201 }
202 
BuildFromInterpolate(const Path & src,const Path & ending,scalar weight)203 bool Path::BuildFromInterpolate(const Path& src, const Path& ending, scalar weight)
204 {
205     return impl_->InitWithInterpolate(src, ending, weight);
206 }
207 
Transform(const Matrix & matrix)208 void Path::Transform(const Matrix& matrix)
209 {
210     impl_->Transform(matrix);
211 }
212 
Offset(scalar dx,scalar dy)213 void Path::Offset(scalar dx, scalar dy)
214 {
215     impl_->Offset(dx, dy);
216 }
217 
Op(const Path & path1,Path & path2,PathOp op)218 bool Path::Op(const Path& path1, Path& path2, PathOp op)
219 {
220     return impl_->OpWith(path1, path2, op);
221 }
222 
IsValid() const223 bool Path::IsValid() const
224 {
225     return impl_->IsValid();
226 }
227 
Reset()228 void Path::Reset()
229 {
230     impl_->Reset();
231 }
232 
Close()233 void Path::Close()
234 {
235     impl_->Close();
236 }
237 
GetLength(bool forceClosed) const238 scalar Path::GetLength(bool forceClosed) const
239 {
240     return impl_->GetLength(forceClosed);
241 }
242 
GetPositionAndTangent(scalar distance,Point & position,Point & tangent,bool forceClosed) const243 bool Path::GetPositionAndTangent(scalar distance, Point& position, Point& tangent, bool forceClosed) const
244 {
245     return impl_->GetPositionAndTangent(distance, position, tangent, forceClosed);
246 }
247 
Serialize() const248 std::shared_ptr<Data> Path::Serialize() const
249 {
250     return impl_->Serialize();
251 }
252 
Deserialize(std::shared_ptr<Data> data)253 bool Path::Deserialize(std::shared_ptr<Data> data)
254 {
255     return impl_->Deserialize(data);
256 }
257 
258 } // namespace Drawing
259 } // namespace Rosen
260 } // namespace OHOS
261