• 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_FE_COMPOSITE_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_FE_COMPOSITE_DECLARATION_H
18 
19 #include "core/components/declaration/svg/svg_fe_declaration.h"
20 
21 namespace OHOS::Ace {
22 
23 enum class FeOperatorType {
24     FE_ARITHMETIC,
25     FE_ATOP,
26     FE_IN,
27     FE_LIGHTER,
28     FE_OUT,
29     FE_OVER,
30     FE_XOR
31 };
32 
33 struct SvgFeCompositeAttribute : SvgFeAttribute {
34     FeInType in2 = FeInType::PRIMITIVE;
35     FeOperatorType operatorType = FeOperatorType::FE_OVER;
36     double k1 = 0.0;
37     double k2 = 0.0;
38     double k3 = 0.0;
39     double k4 = 0.0;
40 };
41 
42 class SvgFeCompositeDeclaration : public SvgFeDeclaration {
43     DECLARE_ACE_TYPE(SvgFeCompositeDeclaration, SvgFeDeclaration);
44 
45 public:
46     SvgFeCompositeDeclaration() = default;
47     ~SvgFeCompositeDeclaration() override = default;
48     void InitializeStyle() override;
49 
SetK1(double k1)50     void SetK1(double k1)
51     {
52         auto& attribute = MaybeResetAttribute<SvgFeCompositeAttribute>(AttributeTag::SPECIALIZED_ATTR);
53         attribute.k1 = k1;
54     }
55 
SetK2(double k2)56     void SetK2(double k2)
57     {
58         auto& attribute = MaybeResetAttribute<SvgFeCompositeAttribute>(AttributeTag::SPECIALIZED_ATTR);
59         attribute.k2 = k2;
60     }
61 
SetK3(double k3)62     void SetK3(double k3)
63     {
64         auto& attribute = MaybeResetAttribute<SvgFeCompositeAttribute>(AttributeTag::SPECIALIZED_ATTR);
65         attribute.k3 = k3;
66     }
67 
SetK4(double k4)68     void SetK4(double k4)
69     {
70         auto& attribute = MaybeResetAttribute<SvgFeCompositeAttribute>(AttributeTag::SPECIALIZED_ATTR);
71         attribute.k4 = k4;
72     }
73 
SetIn2(const std::string & In2)74     void SetIn2(const std::string& In2)
75     {
76         static const LinearMapNode<FeInType> IN_TABLE[] = {
77             { "BackgroundAlpha", FeInType::BACKGROUND_ALPHA },
78             { "BackgroundImage", FeInType::BACKGROUND_IMAGE },
79             { "FillPaint", FeInType::FILL_PAINT },
80             { "SourceAlpha", FeInType::SOURCE_ALPHA },
81             { "SourceGraphic", FeInType::SOURCE_GRAPHIC },
82             { "StrokePaint", FeInType::STROKE_PAINT },
83         };
84         int64_t inIndex = BinarySearchFindIndex(IN_TABLE, ArraySize(IN_TABLE), In2.c_str());
85         if (inIndex != -1) {
86             auto& attribute = MaybeResetAttribute<SvgFeCompositeAttribute>(AttributeTag::SPECIALIZED_ATTR);
87             attribute.in2 = IN_TABLE[inIndex].value;
88         }
89     }
90 
SetOperatorType(const std::string & type)91     void SetOperatorType(const std::string& type)
92     {
93         static const LinearMapNode<FeOperatorType> FE_OPERATOR_TABLE[] = {
94             { "arithmetic", FeOperatorType::FE_ARITHMETIC },
95             { "atop", FeOperatorType::FE_ATOP },
96             { "in", FeOperatorType::FE_IN },
97             { "lighter", FeOperatorType::FE_LIGHTER },
98             { "out", FeOperatorType::FE_OUT },
99             { "over", FeOperatorType::FE_OVER },
100             { "xor", FeOperatorType::FE_XOR },
101         };
102         int64_t inIndex = BinarySearchFindIndex(FE_OPERATOR_TABLE, ArraySize(FE_OPERATOR_TABLE), type.c_str());
103         if (inIndex != -1) {
104             auto& attribute = MaybeResetAttribute<SvgFeCompositeAttribute>(AttributeTag::SPECIALIZED_ATTR);
105             attribute.operatorType = FE_OPERATOR_TABLE[inIndex].value;
106         }
107     }
108 
GetK1()109     double GetK1() const
110     {
111         auto& attribute = static_cast<SvgFeCompositeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
112         return attribute.k1;
113     }
114 
GetK2()115     double GetK2() const
116     {
117         auto& attribute = static_cast<SvgFeCompositeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
118         return attribute.k2;
119     }
120 
GetK3()121     double GetK3() const
122     {
123         auto& attribute = static_cast<SvgFeCompositeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
124         return attribute.k3;
125     }
126 
GetK4()127     double GetK4() const
128     {
129         auto& attribute = static_cast<SvgFeCompositeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
130         return attribute.k4;
131     }
132 
GetIn2()133     const FeInType& GetIn2() const
134     {
135         auto& attribute = static_cast<SvgFeCompositeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
136         return attribute.in2;
137     }
138 
GetOperatorType()139     const FeOperatorType& GetOperatorType() const
140     {
141         auto& attribute = static_cast<SvgFeCompositeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
142         return attribute.operatorType;
143     }
144 
145 protected:
146     void InitSpecialized() override;
147     bool SetSpecializedValue(const std::pair<std::string, std::string>& attr) override;
148 };
149 
150 } // namespace OHOS::Ace
151 
152 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_FE_COMPOSITE_DECLARATION_H
153