1 /* 2 * Copyright (c) 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_IMAGE_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_IMAGE_DECLARATION_H 18 19 #include "core/components/declaration/svg/svg_base_declaration.h" 20 21 namespace OHOS::Ace { 22 23 struct SvgImageAttribute : SvgBaseAttribute { 24 Dimension x = Dimension(0, DimensionUnit::PX); // x-axis default value 25 Dimension y = Dimension(0, DimensionUnit::PX); // y-axis default value 26 Dimension width = Dimension(0.0, DimensionUnit::PX); // image width default value 27 Dimension height = Dimension(0.0, DimensionUnit::PX); // image height default value 28 std::string href = ""; 29 }; 30 31 class SvgImageDeclaration : public SvgBaseDeclaration { 32 DECLARE_ACE_TYPE(SvgImageDeclaration, SvgBaseDeclaration); 33 34 public: 35 SvgImageDeclaration() = default; 36 ~SvgImageDeclaration() override = default; 37 void InitializeStyle() override; 38 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 39 SetX(const Dimension & x)40 void SetX(const Dimension& x) 41 { 42 auto& attribute = MaybeResetAttribute<SvgImageAttribute>(AttributeTag::SPECIALIZED_ATTR); 43 attribute.x = x; 44 } 45 GetX()46 const Dimension& GetX() const 47 { 48 auto& attribute = static_cast<SvgImageAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 49 return attribute.x; 50 } 51 SetY(const Dimension & y)52 void SetY(const Dimension& y) 53 { 54 auto& attribute = MaybeResetAttribute<SvgImageAttribute>(AttributeTag::SPECIALIZED_ATTR); 55 attribute.y = y; 56 } 57 GetY()58 const Dimension& GetY() const 59 { 60 auto& attribute = static_cast<SvgImageAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 61 return attribute.y; 62 } 63 SetHeight(const Dimension & height)64 void SetHeight(const Dimension& height) 65 { 66 auto& attribute = MaybeResetAttribute<SvgImageAttribute>(AttributeTag::SPECIALIZED_ATTR); 67 attribute.height = height; 68 } 69 GetHeight()70 const Dimension& GetHeight() const 71 { 72 auto& attribute = static_cast<SvgImageAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 73 return attribute.height; 74 } 75 SetWidth(const Dimension & width)76 void SetWidth(const Dimension& width) 77 { 78 auto& attribute = MaybeResetAttribute<SvgImageAttribute>(AttributeTag::SPECIALIZED_ATTR); 79 attribute.width = width; 80 } 81 GetWidth()82 const Dimension& GetWidth() const 83 { 84 auto& attribute = static_cast<SvgImageAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 85 return attribute.width; 86 } 87 SetHref(const std::string & href)88 void SetHref(const std::string& href) 89 { 90 auto& attrs = MaybeResetAttribute<SvgImageAttribute>(AttributeTag::SPECIALIZED_ATTR); 91 attrs.href = href; 92 } 93 GetHref()94 const std::string& GetHref() const 95 { 96 auto& attribute = static_cast<SvgImageAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 97 return attribute.href; 98 } 99 100 protected: 101 void InitSpecialized() override; 102 }; 103 104 } // namespace OHOS::Ace 105 106 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_IMAGE_DECLARATION_H 107