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_DECLARATION_SVG_SVG_LINE_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_LINE_DECLARATION_H 18 19 #include "core/components/declaration/svg/svg_base_declaration.h" 20 21 namespace OHOS::Ace { 22 23 struct SvgLineAttribute : SvgBaseAttribute { 24 Dimension x1; 25 Dimension y1; 26 Dimension x2; 27 Dimension y2; 28 }; 29 30 class SvgLineDeclaration : public SvgBaseDeclaration { 31 DECLARE_ACE_TYPE(SvgLineDeclaration, SvgBaseDeclaration); 32 33 public: 34 SvgLineDeclaration() = default; 35 ~SvgLineDeclaration() override = default; 36 void InitializeStyle() override; 37 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 38 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 39 SetX1(const Dimension & x1)40 void SetX1(const Dimension& x1) 41 { 42 auto& attribute = MaybeResetAttribute<SvgLineAttribute>(AttributeTag::SPECIALIZED_ATTR); 43 attribute.x1 = x1; 44 } 45 SetX2(const Dimension & x2)46 void SetX2(const Dimension& x2) 47 { 48 auto& attribute = MaybeResetAttribute<SvgLineAttribute>(AttributeTag::SPECIALIZED_ATTR); 49 attribute.x2 = x2; 50 } 51 SetY1(const Dimension & y1)52 void SetY1(const Dimension& y1) 53 { 54 auto& attribute = MaybeResetAttribute<SvgLineAttribute>(AttributeTag::SPECIALIZED_ATTR); 55 attribute.y1 = y1; 56 } 57 SetY2(const Dimension & y2)58 void SetY2(const Dimension& y2) 59 { 60 auto& attribute = MaybeResetAttribute<SvgLineAttribute>(AttributeTag::SPECIALIZED_ATTR); 61 attribute.y2 = y2; 62 } 63 GetX1()64 const Dimension& GetX1() const 65 { 66 auto& attribute = static_cast<SvgLineAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 67 return attribute.x1; 68 } 69 GetX2()70 const Dimension& GetX2() const 71 { 72 auto& attribute = static_cast<SvgLineAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 73 return attribute.x2; 74 } 75 GetY1()76 const Dimension& GetY1() const 77 { 78 auto& attribute = static_cast<SvgLineAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 79 return attribute.y1; 80 } 81 GetY2()82 const Dimension& GetY2() const 83 { 84 auto& attribute = static_cast<SvgLineAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 85 return attribute.y2; 86 } 87 88 protected: 89 void InitSpecialized() override; 90 91 private: 92 bool SetSpecializedValue(const std::pair<std::string, std::string>& attr); 93 }; 94 95 } // namespace OHOS::Ace 96 97 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_LINE_DECLARATION_H 98