• 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_GAUSSIANBLUR_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_FE_GAUSSIANBLUR_DECLARATION_H
18 
19 #include "core/components/declaration/svg/svg_fe_declaration.h"
20 
21 namespace OHOS::Ace {
22 
23 enum class FeEdgeMode {
24     EDGE_DUPLICATE,
25     EDGE_WRAP,
26     EDGE_NONE
27 };
28 
29 struct SvgFeGaussianBlurAttribute : SvgFeAttribute {
30     double stdDeviation = 0.0;
31     FeEdgeMode edgeMode = FeEdgeMode::EDGE_DUPLICATE;
32 };
33 
34 class SvgFeGaussianBlurDeclaration : public SvgFeDeclaration {
35     DECLARE_ACE_TYPE(SvgFeGaussianBlurDeclaration, SvgFeDeclaration);
36 
37 public:
38     SvgFeGaussianBlurDeclaration() = default;
39     ~SvgFeGaussianBlurDeclaration() override = default;
40     void InitializeStyle() override;
41 
SetStdDeviation(double stdDeviation)42     void SetStdDeviation(double stdDeviation)
43     {
44         auto& attribute = MaybeResetAttribute<SvgFeGaussianBlurAttribute>(AttributeTag::SPECIALIZED_ATTR);
45         attribute.stdDeviation = stdDeviation;
46     }
47 
SetEdgeMode(const std::string & edgeMode)48     void SetEdgeMode(const std::string& edgeMode)
49     {
50         static const LinearMapNode<FeEdgeMode> EDGE_MODE_TABLE[] = {
51             { "duplicate", FeEdgeMode::EDGE_DUPLICATE },
52             { "none", FeEdgeMode::EDGE_NONE },
53             { "wrap", FeEdgeMode::EDGE_WRAP },
54         };
55         int64_t inIndex = BinarySearchFindIndex(EDGE_MODE_TABLE, ArraySize(EDGE_MODE_TABLE), edgeMode.c_str());
56         if (inIndex != -1) {
57             auto& attribute = MaybeResetAttribute<SvgFeGaussianBlurAttribute>(AttributeTag::SPECIALIZED_ATTR);
58             attribute.edgeMode = EDGE_MODE_TABLE[inIndex].value;
59         }
60     }
61 
GetStdDeviation()62     double GetStdDeviation() const
63     {
64         auto& attribute = static_cast<SvgFeGaussianBlurAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
65         return attribute.stdDeviation;
66     }
67 
GetEdgeMode()68     const FeEdgeMode& GetEdgeMode() const
69     {
70         auto& attribute = static_cast<SvgFeGaussianBlurAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
71         return attribute.edgeMode;
72     }
73 
74 protected:
75     void InitSpecialized() override;
76     bool SetSpecializedValue(const std::pair<std::string, std::string>& attr) override;
77 };
78 
79 } // namespace OHOS::Ace
80 
81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_FE_GAUSSIANBLUR_DECLARATION_H
82