• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BASE_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_BASE_DECLARATION_H
18 
19 #include "core/components/common/properties/svg_paint_state.h"
20 #include "core/components/declaration/common/declaration.h"
21 #include "frameworks/bridge/common/dom/dom_type.h"
22 
23 namespace OHOS::Ace {
24 
25 const char VALUE_NONE[] = "none";
26 
27 struct SvgBaseAttribute : Attribute {
28     bool hasOpacity = false;
29     double opacity = 1.0;
30     FillState fillState;
31     StrokeState strokeState;
32     SvgTextStyle textStyle;
33     std::string transform;
34     std::string transformOrigin;
35     std::string filterId;
36     std::string maskId;
37     std::string href;
38     std::string id;
39     ClipState clipState;
40 };
41 
42 class SvgBaseDeclaration : public Declaration {
43     DECLARE_ACE_TYPE(SvgBaseDeclaration, Declaration);
44 
45 public:
46     SvgBaseDeclaration() = default;
47     ~SvgBaseDeclaration() override = default;
48 
GetFillState()49     const FillState& GetFillState() const
50     {
51         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
52         return attribute.fillState;
53     }
54 
GetStrokeState()55     const StrokeState& GetStrokeState() const
56     {
57         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
58         return attribute.strokeState;
59     }
60 
GetSvgTextStyle()61     const SvgTextStyle& GetSvgTextStyle() const
62     {
63         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
64         return attribute.textStyle;
65     }
66 
GetTransform()67     const std::string& GetTransform() const
68     {
69         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
70         return attribute.transform;
71     }
72 
GetMaskId()73     const std::string& GetMaskId() const
74     {
75         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
76         return attribute.maskId;
77     }
78 
GetFilterId()79     const std::string& GetFilterId() const
80     {
81         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
82         return attribute.filterId;
83     }
84 
GetTransformOrigin()85     const std::string& GetTransformOrigin() const
86     {
87         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
88         return attribute.transformOrigin;
89     }
90 
HasOpacity()91     bool HasOpacity() const
92     {
93         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
94         return attribute.hasOpacity;
95     }
96 
GetOpacity()97     double GetOpacity() const
98     {
99         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
100         return attribute.opacity;
101     }
102 
103     void Inherit(const RefPtr<Declaration>& parent);
104 
SetGradient(const Gradient & gradient)105     void SetGradient(const Gradient& gradient)
106     {
107         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
108         attribute.fillState.SetGradient(gradient);
109     }
110 
GetClipPathHref()111     const std::string& GetClipPathHref() const
112     {
113         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
114         return attribute.clipState.GetHref();
115     }
116 
SetHref(const std::string & href)117     void SetHref(const std::string& href)
118     {
119         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
120         attribute.href = href;
121     }
122 
GetHref()123     const std::string& GetHref() const
124     {
125         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
126         return attribute.href;
127     }
128 
GetClipState()129     const ClipState& GetClipState() const
130     {
131         auto& attribute = static_cast<SvgBaseAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
132         return attribute.clipState;
133     }
134 
GetId()135     const std::string& GetId()
136     {
137         auto& commonAttr = MaybeResetAttribute<CommonAttribute>(AttributeTag::COMMON_ATTR);
138         return commonAttr.id;
139     }
140 
141     LineCapStyle GetLineCapStyle(const std::string& val) const;
142     LineJoinStyle GetLineJoinStyle(const std::string& val) const;
143     Color GetColor(const std::string& value) const;
144 
145     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
146 
147     void ReplaceAttributes(const SvgBaseAttribute& attr);
148 
149 protected:
150     void InitSpecialized() override;
151     bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override;
152     bool SetPresentationAttr(const std::pair<std::string, std::string>& attr);
153 };
154 
155 } // namespace OHOS::Ace
156 
157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_BASE_DECLARATION_H
158