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