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_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_DECLARATION_H 18 19 #include "core/components/declaration/svg/svg_base_declaration.h" 20 21 namespace OHOS::Ace { 22 23 enum { 24 R_Scale = 0, 25 G_Scale = 6, 26 B_Scale = 12, 27 A_Scale = 18, 28 29 R_Trans = 4, 30 G_Trans = 9, 31 B_Trans = 14, 32 A_Trans = 19, 33 }; 34 35 enum class SvgFeColorMatrixType { 36 Matrix, 37 Saturate, 38 HueRotate, 39 LuminanceToAlpha, 40 }; 41 42 struct SvgAttribute : SvgBaseAttribute { 43 Rect viewBox; 44 Dimension x; 45 Dimension y; 46 Dimension width = -1.0_px; 47 Dimension height = -1.0_px; 48 bool autoMirror = false; 49 }; 50 51 class SvgDeclaration : public SvgBaseDeclaration { 52 DECLARE_ACE_TYPE(SvgDeclaration, SvgBaseDeclaration); 53 54 public: 55 SvgDeclaration() = default; 56 ~SvgDeclaration() override = default; 57 void InitializeStyle() override; 58 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 59 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 60 SetX(const Dimension & x)61 void SetX(const Dimension& x) 62 { 63 auto& attribute = MaybeResetAttribute<SvgAttribute>(AttributeTag::SPECIALIZED_ATTR); 64 attribute.x = x; 65 } 66 GetX()67 const Dimension& GetX() const 68 { 69 auto& attribute = static_cast<SvgAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 70 return attribute.x; 71 } 72 SetY(const Dimension & y)73 void SetY(const Dimension& y) 74 { 75 auto& attribute = MaybeResetAttribute<SvgAttribute>(AttributeTag::SPECIALIZED_ATTR); 76 attribute.y = y; 77 } 78 GetY()79 const Dimension& GetY() const 80 { 81 auto& attribute = static_cast<SvgAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 82 return attribute.y; 83 } 84 SetWidth(const Dimension & width)85 void SetWidth(const Dimension& width) 86 { 87 auto& attribute = MaybeResetAttribute<SvgAttribute>(AttributeTag::SPECIALIZED_ATTR); 88 attribute.width = width; 89 } 90 GetWidth()91 const Dimension& GetWidth() const 92 { 93 auto& attribute = static_cast<SvgAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 94 return attribute.width; 95 } 96 SetHeight(const Dimension & height)97 void SetHeight(const Dimension& height) 98 { 99 auto& attribute = MaybeResetAttribute<SvgAttribute>(AttributeTag::SPECIALIZED_ATTR); 100 attribute.height = height; 101 } 102 GetHeight()103 const Dimension& GetHeight() const 104 { 105 auto& attribute = static_cast<SvgAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 106 return attribute.height; 107 } 108 SetViewBox(const Rect & viewBox)109 void SetViewBox(const Rect& viewBox) 110 { 111 auto& attribute = MaybeResetAttribute<SvgAttribute>(AttributeTag::SPECIALIZED_ATTR); 112 attribute.viewBox = viewBox; 113 } 114 GetViewBox()115 const Rect& GetViewBox() const 116 { 117 auto& attribute = static_cast<SvgAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 118 return attribute.viewBox; 119 } 120 SetAutoMirror(bool autoMirror)121 void SetAutoMirror(bool autoMirror) 122 { 123 auto& attribute = MaybeResetAttribute<SvgAttribute>(AttributeTag::SPECIALIZED_ATTR); 124 attribute.autoMirror = autoMirror; 125 } 126 GetAutoMirror()127 bool GetAutoMirror() const 128 { 129 auto& attribute = static_cast<SvgAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 130 return attribute.autoMirror; 131 } 132 133 protected: 134 void InitSpecialized() override; 135 136 private: 137 bool SetSpecializedValue(const std::pair<std::string, std::string>& attr); 138 }; 139 140 } // namespace OHOS::Ace 141 142 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_DECLARATION_H 143