1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_CLIP_PATH_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_CLIP_PATH_H 18 19 #include <string> 20 #include <vector> 21 22 #include "base/geometry/dimension.h" 23 #include "base/geometry/dimension_offset.h" 24 #include "base/geometry/shape.h" 25 #include "base/memory/ace_type.h" 26 #include "core/components/common/properties/color.h" 27 28 namespace OHOS::Ace { 29 30 enum class GeometryBoxType { 31 NONE, 32 MARGIN_BOX, 33 BORDER_BOX, 34 PADDING_BOX, 35 CONTENT_BOX, 36 }; 37 38 39 enum class LengthMode { 40 HORIZONTAL, 41 VERTICAL, 42 OTHER, 43 }; 44 45 class ACE_EXPORT ClipPath final : public AceType { 46 DECLARE_ACE_TYPE(ClipPath, AceType); 47 48 public: 49 ClipPath() = default; ClipPath(const RefPtr<BasicShape> & basicShape)50 explicit ClipPath(const RefPtr<BasicShape>& basicShape) : basicShape_(basicShape) {} ClipPath(GeometryBoxType geometryBoxType,const RefPtr<BasicShape> & basicShape)51 ClipPath(GeometryBoxType geometryBoxType, const RefPtr<BasicShape>& basicShape) 52 : geometryBoxType_(geometryBoxType), basicShape_(basicShape) 53 {} 54 ~ClipPath() override = default; 55 56 static GeometryBoxType GetGeometryBoxType(const std::string& value); 57 static void GetBasicShapeInfo(const std::string& value, BasicShapeType& basicShapeType, std::string& data); 58 static RefPtr<ClipPath> CreateShape(const std::string& value); 59 SetGeometryBoxType(GeometryBoxType geometryBoxType)60 void SetGeometryBoxType(GeometryBoxType geometryBoxType) 61 { 62 geometryBoxType_ = geometryBoxType; 63 } 64 GetGeometryBoxType()65 GeometryBoxType GetGeometryBoxType() const 66 { 67 return geometryBoxType_; 68 } 69 SetBasicShape(const RefPtr<BasicShape> & basicShape)70 void SetBasicShape(const RefPtr<BasicShape>& basicShape) 71 { 72 basicShape_ = basicShape; 73 } 74 GetBasicShape()75 const RefPtr<BasicShape>& GetBasicShape() const 76 { 77 return basicShape_; 78 } 79 NeedClip()80 bool NeedClip() const 81 { 82 return (basicShape_ && basicShape_->GetBasicShapeType() != BasicShapeType::NONE) || 83 geometryBoxType_ != GeometryBoxType::NONE; 84 } 85 86 private: 87 static RefPtr<Circle> CreateCircle(const std::string& data); 88 static RefPtr<Ellipse> CreateEllipse(const std::string& data); 89 static RefPtr<Ellipse> CreateEllipseSize(const std::string& data); 90 static RefPtr<Inset> CreateInset(const std::string& data); 91 static RefPtr<Inset> CreateInsetSize(const std::string& data); 92 static RefPtr<Polygon> CreatePolygon(const std::string& value); 93 static RefPtr<Path> CreatePath(const std::string& value); 94 95 GeometryBoxType geometryBoxType_ = GeometryBoxType::NONE; 96 RefPtr<BasicShape> basicShape_; 97 }; 98 99 class ACE_EXPORT MaskPath final : public AceType { 100 DECLARE_ACE_TYPE(MaskPath, AceType); 101 102 public: 103 MaskPath() = default; MaskPath(const RefPtr<BasicShape> & basicShape)104 explicit MaskPath(const RefPtr<BasicShape>& basicShape) : basicShape_(basicShape) {} MaskPath(GeometryBoxType geometryBoxType,const RefPtr<BasicShape> & basicShape)105 MaskPath(GeometryBoxType geometryBoxType, const RefPtr<BasicShape>& basicShape) 106 : geometryBoxType_(geometryBoxType), basicShape_(basicShape) 107 {} 108 ~MaskPath() override = default; 109 SetGeometryBoxType(GeometryBoxType geometryBoxType)110 void SetGeometryBoxType(GeometryBoxType geometryBoxType) 111 { 112 geometryBoxType_ = geometryBoxType; 113 } 114 GetGeometryBoxType()115 GeometryBoxType GetGeometryBoxType() const 116 { 117 return geometryBoxType_; 118 } 119 SetBasicShape(const RefPtr<BasicShape> & basicShape)120 void SetBasicShape(const RefPtr<BasicShape>& basicShape) 121 { 122 basicShape_ = basicShape; 123 } 124 GetBasicShape()125 const RefPtr<BasicShape>& GetBasicShape() const 126 { 127 return basicShape_; 128 } 129 130 private: 131 GeometryBoxType geometryBoxType_ = GeometryBoxType::NONE; 132 RefPtr<BasicShape> basicShape_; 133 }; 134 135 } // namespace OHOS::Ace 136 137 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_CLIP_PATH_H 138