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