• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 SKIA_PATH_H
17 #define SKIA_PATH_H
18 
19 #include <unordered_map>
20 
21 #include "include/core/SkPath.h"
22 #include "include/core/SkPathMeasure.h"
23 
24 #include "impl_interface/path_impl.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class DRAWING_API SkiaPath : public PathImpl {
30 public:
31     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
32 
SkiaPath()33     SkiaPath() noexcept {};
~SkiaPath()34     ~SkiaPath() override {};
35     SkiaPath(const SkiaPath& p) noexcept;
36     SkiaPath &operator=(const SkiaPath& p) noexcept;
37 
GetType()38     AdapterType GetType() const override
39     {
40         return AdapterType::SKIA_ADAPTER;
41     }
42 
43     PathImpl* Clone() override;
44 
45     bool InitWithSVGString(const std::string& str) override;
46     std::string ConvertToSVGString() const override;
47 
48     bool InitWithInterpolate(const Path& srcPath, const Path& endingPath, scalar weight) override;
49 
50     void MoveTo(scalar x, scalar y) override;
51     void LineTo(scalar x, scalar y) override;
52     void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle) override;
53     void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY) override;
54     void ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius) override;
55     void CubicTo(
56         scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY) override;
57     void QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY) override;
58     void ConicTo(scalar ctrlX, scalar ctrlY, scalar endX, scalar endY, scalar weight) override;
59 
60     void RMoveTo(scalar dx, scalar dy) override;
61     void RLineTo(scalar dx, scalar dy) override;
62     void RArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar dx, scalar dy) override;
63     void RCubicTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2, scalar dx3, scalar dy3) override;
64     void RConicTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY, scalar weight) override;
65     void RQuadTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2) override;
66 
67     void AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir) override;
68     void AddRect(const Rect& rect, unsigned start, PathDirection dir) override;
69     void AddOval(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir) override;
70     void AddOval(scalar left, scalar top, scalar right, scalar bottom, unsigned start, PathDirection dir) override;
71     void AddArc(scalar left, scalar top, scalar right, scalar bottom, scalar startAngle, scalar sweepAngle) override;
72     void AddPoly(const std::vector<Point>& points, int count, bool close) override;
73     void AddCircle(scalar x, scalar y, scalar radius, PathDirection dir) override;
74     void AddRoundRect(scalar left, scalar top, scalar right, scalar bottom, scalar xRadius, scalar yRadius,
75         PathDirection dir) override;
76     void AddRoundRect(const RoundRect& rrect, PathDirection dir) override;
77 
78     void AddPath(const Path& src, scalar dx, scalar dy, PathAddMode mode) override;
79     void AddPath(const Path& src, PathAddMode mode) override;
80     bool Contains(scalar x, scalar y) const override;
81     void AddPath(const Path& src, const Matrix& matrix, PathAddMode mode) override;
82     void ReverseAddPath(const Path& src) override;
83 
84     Rect GetBounds() const override;
85     void SetFillStyle(PathFillType fillstyle) override;
86     PathFillType GetFillStyle() const override;
87 
88     bool Interpolate(const Path& ending, scalar weight, Path& out) override;
89     int CountVerbs() const override;
90     Point GetPoint(int index) const override;
91     bool IsInterpolate(const Path& other) override;
92     void Transform(const Matrix& matrix) override;
93     void TransformWithPerspectiveClip(const Matrix& matrix, Path* dst, bool applyPerspectiveClip) override;
94     void Offset(scalar dx, scalar dy) override;
95     void Offset(Path* dst, scalar dx, scalar dy) override;
96     bool OpWith(const Path& path1, const Path& path2, PathOp op) override;
97 
98     bool IsValid() const override;
99     void Reset() override;
100     void ReWind() override;
101     void SetLastPoint(scalar x, scalar y) override;
102 
103     void Close() override;
104 
105     void SetPath(const SkPath& path);
106 
107     const SkPath& GetPath() const;
108 
109     SkPath& GetMutablePath();
110 
111     void PathMeasureUpdate(bool forceClosed);
112     scalar GetLength(bool forceClosed) override;
113     bool GetPositionAndTangent(scalar distance, Point& position, Point& tangent, bool forceClosed) override;
114     bool GetSegment(scalar start, scalar stop, Path* dst, bool startWithMoveTo, bool forceClosed) override;
115     bool IsClosed(bool forceClosed) override;
116     bool IsEmpty() override;
117     bool IsRect(Rect* rect, bool* isClosed, PathDirection* direction) override;
118     void SetPath(const Path& path) override;
119     bool GetMatrix(bool forceClosed, float distance, Matrix* matrix, PathMeasureMatrixFlags flag) override;
120 
121     std::shared_ptr<Data> Serialize() const override;
122     bool Deserialize(std::shared_ptr<Data> data) override;
123 private:
124     SkPath path_;
125     std::unique_ptr<SkPathMeasure> pathMeasure_ = nullptr;
126 
127     // Records if Path has changed, and if it is true, update pathmeasure if needed.
128     bool isChanged_ = true;
129     bool forceClosed_ = false;
130 };
131 } // namespace Drawing
132 } // namespace Rosen
133 } // namespace OHOS
134 #endif
135