• 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 #ifndef PATH_IMPL_H
17 #define PATH_IMPL_H
18 
19 #include <memory>
20 
21 #include "base_impl.h"
22 
23 #include "utils/matrix.h"
24 #include "utils/point.h"
25 #include "utils/rect.h"
26 #include "utils/round_rect.h"
27 #include "utils/scalar.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 class Data;
33 class Path;
34 enum class PathDirection;
35 enum class PathFillType;
36 enum class PathOp;
37 enum class ArcSize;
38 class PathImpl : public BaseImpl {
39 public:
PathImpl()40     PathImpl() noexcept {}
~PathImpl()41     ~PathImpl() override {}
42     PathImpl(const PathImpl& p) = delete;
43     PathImpl &operator=(const PathImpl& p) = delete;
44     virtual PathImpl* Clone() = 0;
45 
46     virtual bool InitWithSVGString(const std::string& str) = 0;
47     virtual std::string ConvertToSVGString() const = 0;
48     virtual bool InitWithInterpolate(const Path& srcPath, const Path& endingPath, scalar weight) = 0;
49     virtual void MoveTo(scalar x, scalar y) = 0;
50     virtual void LineTo(scalar x, scalar y) = 0;
51     virtual void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle) = 0;
52     virtual void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY) = 0;
53     virtual void ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius) = 0;
54     virtual void CubicTo(
55         scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY) = 0;
56     virtual void QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY) = 0;
57 
58     virtual void RMoveTo(scalar dx, scalar dy) = 0;
59     virtual void RLineTo(scalar dx, scalar dy) = 0;
60     virtual void RArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar dx, scalar dy) = 0;
61     virtual void RCubicTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2, scalar dx3, scalar dy3) = 0;
62     virtual void RQuadTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2) = 0;
63 
64     virtual void AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir) = 0;
65     virtual void AddOval(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir) = 0;
66     virtual void AddArc(scalar left, scalar top, scalar right, scalar bottom, scalar startAngle, scalar sweepAngle) = 0;
67     virtual void AddPoly(const std::vector<Point>& point, int count, bool close) = 0;
68     virtual void AddCircle(scalar x, scalar y, scalar radius, PathDirection dir) = 0;
69     virtual void AddRoundRect(
70         scalar left, scalar top, scalar right, scalar bottom, scalar xRadius, scalar yRadius, PathDirection dir) = 0;
71     virtual void AddRoundRect(const RoundRect& rrect, PathDirection dir) = 0;
72 
73     virtual void AddPath(const Path& src, scalar dx, scalar dy) = 0;
74     virtual void AddPath(const Path& src) = 0;
75     virtual bool Contains(scalar x, scalar y) const = 0;
76     virtual void AddPathWithMatrix(const Path& src, const Matrix& matrix) = 0;
77     virtual void ReverseAddPath(const Path& src) = 0;
78 
79     virtual Rect GetBounds() const = 0;
80     virtual void SetFillStyle(PathFillType fillstyle) = 0;
81 
82     virtual bool Interpolate(const Path& ending, scalar weight, Path& out) = 0;
83     virtual void Transform(const Matrix& matrix) = 0;
84     virtual void Offset(scalar dx, scalar dy) = 0;
85     virtual bool OpWith(const Path& path1, const Path& path2, PathOp op) = 0;
86 
87     virtual bool IsValid() const = 0;
88     virtual void Reset() = 0;
89 
90     virtual void Close() = 0;
91 
92     virtual scalar GetLength(bool forceClosed) const = 0;
93     virtual bool GetPositionAndTangent(scalar distance, Point& position, Point& tangent, bool forceClosed) const = 0;
94     virtual std::shared_ptr<Data> Serialize() const = 0;
95     virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
96 };
97 } // namespace Drawing
98 } // namespace Rosen
99 } // namespace OHOS
100 #endif
101