1 /* 2 * Copyright (c) 2021-2024 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 enum class PathAddMode; 39 enum class PathMeasureMatrixFlags; 40 class PathImpl : public BaseImpl { 41 public: PathImpl()42 PathImpl() noexcept {} ~PathImpl()43 ~PathImpl() override {} 44 PathImpl(const PathImpl& p) = delete; 45 PathImpl &operator=(const PathImpl& p) = delete; 46 virtual PathImpl* Clone() = 0; 47 48 virtual bool InitWithSVGString(const std::string& str) = 0; 49 virtual std::string ConvertToSVGString() const = 0; 50 virtual bool InitWithInterpolate(const Path& srcPath, const Path& endingPath, scalar weight) = 0; 51 virtual void MoveTo(scalar x, scalar y) = 0; 52 virtual void LineTo(scalar x, scalar y) = 0; 53 virtual void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle) = 0; 54 virtual void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY) = 0; 55 virtual void ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius) = 0; 56 virtual void CubicTo( 57 scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY) = 0; 58 virtual void QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY) = 0; 59 virtual void ConicTo(scalar ctrlX, scalar ctrlY, scalar endX, scalar endY, scalar weight) = 0; 60 61 virtual void RMoveTo(scalar dx, scalar dy) = 0; 62 virtual void RLineTo(scalar dx, scalar dy) = 0; 63 virtual void RArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar dx, scalar dy) = 0; 64 virtual void RCubicTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2, scalar dx3, scalar dy3) = 0; 65 virtual void RConicTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY, scalar weight) = 0; 66 virtual void RQuadTo(scalar dx1, scalar dy1, scalar dx2, scalar dy2) = 0; 67 68 virtual void AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir) = 0; 69 virtual void AddRect(const Rect& rect, unsigned start, PathDirection dir) = 0; 70 virtual void AddOval(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir) = 0; 71 virtual void AddOval(scalar left, scalar top, scalar right, scalar bottom, unsigned start, PathDirection dir) = 0; 72 virtual void AddArc(scalar left, scalar top, scalar right, scalar bottom, scalar startAngle, scalar sweepAngle) = 0; 73 virtual void AddPoly(const std::vector<Point>& point, int count, bool close) = 0; 74 virtual void AddCircle(scalar x, scalar y, scalar radius, PathDirection dir) = 0; 75 virtual void AddRoundRect( 76 scalar left, scalar top, scalar right, scalar bottom, scalar xRadius, scalar yRadius, PathDirection dir) = 0; 77 virtual void AddRoundRect(const RoundRect& rrect, PathDirection dir) = 0; 78 79 virtual void AddPath(const Path& src, scalar dx, scalar dy, PathAddMode mode) = 0; 80 virtual void AddPath(const Path& src, PathAddMode mode) = 0; 81 virtual bool Contains(scalar x, scalar y) const = 0; 82 virtual void AddPath(const Path& src, const Matrix& matrix, PathAddMode mode) = 0; 83 virtual void ReverseAddPath(const Path& src) = 0; 84 85 virtual Rect GetBounds() const = 0; 86 virtual void SetFillStyle(PathFillType fillstyle) = 0; 87 88 virtual bool Interpolate(const Path& ending, scalar weight, Path& out) = 0; 89 virtual void Transform(const Matrix& matrix) = 0; 90 virtual void TransformWithPerspectiveClip(const Matrix& matrix, Path* dst, bool applyPerspectiveClip) = 0; 91 virtual void Offset(scalar dx, scalar dy) = 0; 92 virtual void Offset(Path* dst, scalar dx, scalar dy) = 0; 93 virtual bool OpWith(const Path& path1, const Path& path2, PathOp op) = 0; 94 95 virtual bool IsValid() const = 0; 96 virtual void Reset() = 0; 97 98 virtual void Close() = 0; 99 100 virtual scalar GetLength(bool forceClosed) = 0; 101 virtual bool GetPositionAndTangent(scalar distance, Point& position, Point& tangent, bool forceClosed) = 0; 102 virtual bool IsClosed(bool forceClosed) = 0; 103 virtual bool GetMatrix(bool forceClosed, float distance, Matrix* matrix, PathMeasureMatrixFlags flag) = 0; 104 virtual std::shared_ptr<Data> Serialize() const = 0; 105 virtual bool Deserialize(std::shared_ptr<Data> data) = 0; 106 }; 107 } // namespace Drawing 108 } // namespace Rosen 109 } // namespace OHOS 110 #endif 111