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