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_declaration.h"
17 
18 namespace OHOS::Ace {
19 
20 using namespace Framework;
21 
SetSpecializedAttr(const std::pair<std::string,std::string> & attr)22 bool SvgFeDeclaration::SetSpecializedAttr(const std::pair<std::string, std::string>& attr)
23 {
24     return SetSpecializedValue(attr);
25 }
26 
SetSpecializedStyle(const std::pair<std::string,std::string> & style)27 bool SvgFeDeclaration::SetSpecializedStyle(const std::pair<std::string, std::string>& style)
28 {
29     return SetSpecializedValue(style);
30 }
31 
SetSpecializedValue(const std::pair<std::string,std::string> & attr)32 bool SvgFeDeclaration::SetSpecializedValue(const std::pair<std::string, std::string>& attr)
33 {
34     static const LinearMapNode<void (*)(const std::string&, SvgFeDeclaration&)> attrs[] = {
35         { DOM_SVG_FE_COLOR_INTERPOLATION_FILTERS,
36             [](const std::string& val, SvgFeDeclaration& declaration) {
37                 declaration.SetColorInterpolationType(val);
38             } },
39         { DOM_SVG_HEIGHT,
40             [](const std::string& val, SvgFeDeclaration& declaration) {
41                 declaration.SetHeight(declaration.ParseDimension(val));
42             } },
43         { DOM_SVG_FE_IN,
44             [](const std::string& val, SvgFeDeclaration& declaration) {
45                 declaration.SetIn(val);
46             } },
47         { DOM_SVG_FE_RESULT,
48             [](const std::string& val, SvgFeDeclaration& declaration) {
49                 declaration.SetResult(val);
50             } },
51         { DOM_SVG_WIDTH,
52             [](const std::string& val, SvgFeDeclaration& declaration) {
53                 declaration.SetWidth(declaration.ParseDimension(val));
54             } },
55         { DOM_SVG_X,
56             [](const std::string& val, SvgFeDeclaration& declaration) {
57                 declaration.SetX(declaration.ParseDimension(val));
58             } },
59         { DOM_SVG_Y,
60             [](const std::string& val, SvgFeDeclaration& declaration) {
61                 declaration.SetY(declaration.ParseDimension(val));
62             } },
63     };
64 
65     std::string key = attr.first;
66     StringUtils::TransformStrCase(key, StringUtils::TEXT_CASE_LOWERCASE);
67     auto attrIter = BinarySearchFindIndex(attrs, ArraySize(attrs), key.c_str());
68     if (attrIter != -1) {
69         attrs[attrIter].value(attr.second, *this);
70         return true;
71     }
72     return SvgBaseDeclaration::SetPresentationAttr(attr);
73 }
74 
75 } // namespace OHOS::Ace