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 #include "core/components/declaration/svg/svg_fe_gaussianblur_declaration.h"
17 
18 #include "core/components/declaration/common/declaration_constants.h"
19 
20 namespace OHOS::Ace {
21 
22 using namespace Framework;
23 
InitSpecialized()24 void SvgFeGaussianBlurDeclaration::InitSpecialized()
25 {
26     AddSpecializedAttribute(DeclarationConstants::DEFAULT_SVG_FE_GAUSSIAN_BLUR_ATTR);
27 }
28 
InitializeStyle()29 void SvgFeGaussianBlurDeclaration::InitializeStyle()
30 {
31     // self attribute must be initialized first. Otherwise, may be initialized as a base attribute.
32     MaybeResetAttribute<SvgFeGaussianBlurAttribute>(AttributeTag::SPECIALIZED_ATTR);
33 }
34 
SetSpecializedValue(const std::pair<std::string,std::string> & attr)35 bool SvgFeGaussianBlurDeclaration::SetSpecializedValue(const std::pair<std::string, std::string>& attr)
36 {
37     static const LinearMapNode<void (*)(const std::string&, SvgFeGaussianBlurDeclaration&)> attrs[] = {
38         { DOM_SVG_FE_EDGE_MODE,
39             [](const std::string& val, SvgFeGaussianBlurDeclaration& declaration) { declaration.SetEdgeMode(val); } },
40         { DOM_SVG_FE_STD_DEVIATION,
41             [](const std::string& val, SvgFeGaussianBlurDeclaration& declaration) {
42                 std::vector<float> parsedValues;
43                 if (!StringUtils::ParseStringToArray(val, parsedValues)) {
44                     return;
45                 }
46                 declaration.SetStdDeviation(parsedValues);
47             } },
48     };
49     std::string key = attr.first;
50     StringUtils::TransformStrCase(key, StringUtils::TEXT_CASE_LOWERCASE);
51     auto attrIter = BinarySearchFindIndex(attrs, ArraySize(attrs), key.c_str());
52     if (attrIter != -1) {
53         attrs[attrIter].value(attr.second, *this);
54         return true;
55     }
56     return SvgFeDeclaration::SetSpecializedValue(attr);
57 }
58 
59 } // namespace OHOS::Ace