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_TEXT_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_TEXT_DECLARATION_H 18 19 #include "core/components/declaration/svg/svg_base_declaration.h" 20 21 namespace OHOS::Ace { 22 23 struct SvgTextAttribute : SvgBaseAttribute { 24 Dimension x; 25 Dimension y; 26 Dimension dx; 27 Dimension dy; 28 double rotate = 0.0; 29 std::string value; 30 }; 31 32 class SvgTextDeclaration : public SvgBaseDeclaration { 33 DECLARE_ACE_TYPE(SvgTextDeclaration, SvgBaseDeclaration); 34 35 public: 36 SvgTextDeclaration() = default; 37 ~SvgTextDeclaration() override = default; 38 void InitializeStyle() override; 39 SetRotate(double rotate)40 void SetRotate(double rotate) 41 { 42 auto& attribute = MaybeResetAttribute<SvgTextAttribute>(AttributeTag::SPECIALIZED_ATTR); 43 attribute.rotate = rotate; 44 } 45 GetRotate()46 double GetRotate() const 47 { 48 auto& attribute = static_cast<SvgTextAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 49 return attribute.rotate; 50 } 51 GetTextData()52 const std::string& GetTextData() const 53 { 54 auto& attribute = static_cast<SvgTextAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 55 return attribute.value; 56 } 57 SetTextData(const std::string & textData)58 void SetTextData(const std::string& textData) 59 { 60 auto& attribute = MaybeResetAttribute<SvgTextAttribute>(AttributeTag::SPECIALIZED_ATTR); 61 attribute.value = textData; 62 } 63 SetX(const Dimension & x)64 void SetX(const Dimension& x) 65 { 66 auto& attribute = MaybeResetAttribute<SvgTextAttribute>(AttributeTag::SPECIALIZED_ATTR); 67 attribute.x = x; 68 } 69 GetX()70 const Dimension& GetX() const 71 { 72 auto& attribute = static_cast<SvgTextAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 73 return attribute.x; 74 } 75 SetY(const Dimension & y)76 void SetY(const Dimension& y) 77 { 78 auto& attribute = MaybeResetAttribute<SvgTextAttribute>(AttributeTag::SPECIALIZED_ATTR); 79 attribute.y = y; 80 } 81 GetY()82 const Dimension& GetY() const 83 { 84 auto& attribute = static_cast<SvgTextAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 85 return attribute.y; 86 } 87 SetDx(const Dimension & dx)88 void SetDx(const Dimension& dx) 89 { 90 auto& attribute = MaybeResetAttribute<SvgTextAttribute>(AttributeTag::SPECIALIZED_ATTR); 91 attribute.dx = dx; 92 } 93 GetDx()94 const Dimension& GetDx() const 95 { 96 auto& attribute = static_cast<SvgTextAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 97 return attribute.dx; 98 } 99 SetDy(const Dimension & dy)100 void SetDy(const Dimension& dy) 101 { 102 auto& attribute = MaybeResetAttribute<SvgTextAttribute>(AttributeTag::SPECIALIZED_ATTR); 103 attribute.dy = dy; 104 } 105 GetDy()106 const Dimension& GetDy() const 107 { 108 auto& attribute = static_cast<SvgTextAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 109 return attribute.dy; 110 } 111 SetHasX(bool hasX)112 void SetHasX(bool hasX) 113 { 114 hasX_ = hasX; 115 } 116 SetHasY(bool hasY)117 void SetHasY(bool hasY) 118 { 119 hasY_ = hasY; 120 } 121 HasX()122 bool HasX() const 123 { 124 return hasX_; 125 } 126 HasY()127 bool HasY() const 128 { 129 return hasY_; 130 } 131 HasRotate()132 bool HasRotate() const 133 { 134 return hasRotate_; 135 } 136 137 protected: 138 void InitSpecialized() override; 139 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 140 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 141 142 private: 143 bool SetSpecializedValue(const std::pair<std::string, std::string>& attr); 144 145 bool hasX_ = false; 146 bool hasY_ = false; 147 bool hasRotate_ = false; 148 }; 149 150 } // namespace OHOS::Ace 151 152 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_TEXT_DECLARATION_H 153