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
CubicTo(scalar ctrlPt1X,scalar ctrlPt1Y,scalar ctrlPt2X,scalar ctrlPt2Y,scalar endPtX,scalar endPtY)73 void Path::CubicTo(scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY)
74 {
75 impl_->CubicTo(ctrlPt1X, ctrlPt1Y, ctrlPt2X, ctrlPt2Y, endPtX, endPtY);
76 }
77
CubicTo(const Point & ctrlPt1,const Point & ctrlPt2,const Point & endPt)78 void Path::CubicTo(const Point& ctrlPt1, const Point& ctrlPt2, const Point& endPt)
79 {
80 impl_->CubicTo(ctrlPt1.GetX(), ctrlPt1.GetY(), ctrlPt2.GetX(), ctrlPt2.GetY(), endPt.GetX(), endPt.GetY());
81 }
82
QuadTo(scalar ctrlPtX,scalar ctrlPtY,scalar endPtX,scalar endPtY)83 void Path::QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY)
84 {
85 impl_->QuadTo(ctrlPtX, ctrlPtY, endPtX, endPtY);
86 }
87
QuadTo(const Point & ctrlPt,const Point endPt)88 void Path::QuadTo(const Point& ctrlPt, const Point endPt)
89 {
90 impl_->QuadTo(ctrlPt.GetX(), ctrlPt.GetY(), endPt.GetX(), endPt.GetY());
91 }
92
AddRect(const Rect & rect,PathDirection dir)93 void Path::AddRect(const Rect& rect, PathDirection dir)
94 {
95 impl_->AddRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), dir);
96 }
97
AddRect(scalar left,scalar top,scalar right,scalar bottom,PathDirection dir)98 void Path::AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir)
99 {
100 impl_->AddRect(left, top, right, bottom, dir);
101 }
102
AddOval(const Rect & oval,PathDirection dir)103 void Path::AddOval(const Rect& oval, PathDirection dir)
104 {
105 impl_->AddOval(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), dir);
106 }
107
AddArc(const Rect & oval,scalar startAngle,scalar sweepAngle)108 void Path::AddArc(const Rect& oval, scalar startAngle, scalar sweepAngle)
109 {
110 impl_->AddArc(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), startAngle, sweepAngle);
111 }
112
AddPoly(const std::vector<Point> & points,int count,bool close)113 void Path::AddPoly(const std::vector<Point>& points, int count, bool close)
114 {
115 impl_->AddPoly(points, count, close);
116 }
117
AddCircle(scalar x,scalar y,scalar radius,PathDirection dir)118 void Path::AddCircle(scalar x, scalar y, scalar radius, PathDirection dir)
119 {
120 impl_->AddCircle(x, y, radius, dir);
121 }
122
AddRoundRect(const Rect & rect,scalar xRadius,scalar yRadius,PathDirection dir)123 void Path::AddRoundRect(const Rect& rect, scalar xRadius, scalar yRadius, PathDirection dir)
124 {
125 impl_->AddRoundRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), xRadius, yRadius, dir);
126 }
127
AddRoundRect(const RoundRect & rrect,PathDirection dir)128 void Path::AddRoundRect(const RoundRect& rrect, PathDirection dir)
129 {
130 impl_->AddRoundRect(rrect, dir);
131 }
132
AddPath(const Path & src,scalar dx,scalar dy)133 void Path::AddPath(const Path& src, scalar dx, scalar dy)
134 {
135 impl_->AddPath(src, dx, dy);
136 }
137
AddPath(const Path & src)138 void Path::AddPath(const Path& src)
139 {
140 impl_->AddPath(src);
141 }
142
AddPath(const Path & src,const Matrix & matrix)143 void Path::AddPath(const Path& src, const Matrix& matrix)
144 {
145 impl_->AddPathWithMatrix(src, matrix);
146 }
147
ReverseAddPath(const Path & src)148 void Path::ReverseAddPath(const Path& src)
149 {
150 impl_->ReverseAddPath(src);
151 }
152
GetBounds() const153 Rect Path::GetBounds() const
154 {
155 return impl_->GetBounds();
156 }
157
SetFillStyle(PathFillType fillstyle)158 void Path::SetFillStyle(PathFillType fillstyle)
159 {
160 impl_->SetFillStyle(fillstyle);
161 }
162
Interpolate(const Path & ending,scalar weight,Path & out)163 bool Path::Interpolate(const Path& ending, scalar weight, Path& out)
164 {
165 return impl_->Interpolate(ending, weight, out);
166 }
167
BuildFromInterpolate(const Path & src,const Path & ending,scalar weight)168 bool Path::BuildFromInterpolate(const Path& src, const Path& ending, scalar weight)
169 {
170 return impl_->InitWithInterpolate(src, ending, weight);
171 }
172
Transform(const Matrix & matrix)173 void Path::Transform(const Matrix& matrix)
174 {
175 impl_->Transform(matrix);
176 }
177
Offset(scalar dx,scalar dy)178 void Path::Offset(scalar dx, scalar dy)
179 {
180 impl_->Offset(dx, dy);
181 }
182
Op(const Path & path1,Path & path2,PathOp op)183 bool Path::Op(const Path& path1, Path& path2, PathOp op)
184 {
185 return impl_->OpWith(path1, path2, op);
186 }
187
IsValid() const188 bool Path::IsValid() const
189 {
190 return impl_->IsValid();
191 }
192
Reset()193 void Path::Reset()
194 {
195 impl_->Reset();
196 }
197
Close()198 void Path::Close()
199 {
200 impl_->Close();
201 }
202
GetLength(bool forceClosed) const203 scalar Path::GetLength(bool forceClosed) const
204 {
205 return impl_->GetLength(forceClosed);
206 }
207
GetPositionAndTangent(scalar distance,Point & position,Point & tangent,bool forceClosed) const208 bool Path::GetPositionAndTangent(scalar distance, Point& position, Point& tangent, bool forceClosed) const
209 {
210 return impl_->GetPositionAndTangent(distance, position, tangent, forceClosed);
211 }
212
213 } // namespace Drawing
214 } // namespace Rosen
215 } // namespace OHOS
216