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