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_COLORMATRIX_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_FE_COLORMATRIX_DECLARATION_H 18 19 #include "core/components/declaration/svg/svg_declaration.h" 20 #include "core/components/declaration/svg/svg_fe_declaration.h" 21 22 namespace OHOS::Ace { 23 24 struct SvgFeColorMatrixAttribute : SvgFeAttribute { 25 SvgFeColorMatrixType type = SvgFeColorMatrixType::Matrix; 26 std::string values; 27 }; 28 29 class SvgFeColorMatrixDeclaration : public SvgFeDeclaration { 30 DECLARE_ACE_TYPE(SvgFeColorMatrixDeclaration, SvgFeDeclaration); 31 32 public: 33 SvgFeColorMatrixDeclaration() = default; 34 ~SvgFeColorMatrixDeclaration() override = default; 35 void InitializeStyle() override; 36 GetColorMatrixType(const std::string & type)37 SvgFeColorMatrixType GetColorMatrixType(const std::string& type) 38 { 39 if (type == "saturate") { 40 return SvgFeColorMatrixType::Saturate; 41 } else if (type == "hueRotate") { 42 return SvgFeColorMatrixType::HueRotate; 43 } else if (type == "luminanceToAlpha") { 44 return SvgFeColorMatrixType::LuminanceToAlpha; 45 } 46 return SvgFeColorMatrixType::Matrix; 47 } 48 SetType(const std::string & type)49 void SetType(const std::string& type) 50 { 51 auto& attribute = MaybeResetAttribute<SvgFeColorMatrixAttribute>(AttributeTag::SPECIALIZED_ATTR); 52 attribute.type = GetColorMatrixType(type); 53 } 54 SetValues(const std::string & values)55 void SetValues(const std::string& values) 56 { 57 auto& attribute = MaybeResetAttribute<SvgFeColorMatrixAttribute>(AttributeTag::SPECIALIZED_ATTR); 58 attribute.values = values; 59 } 60 GetType()61 SvgFeColorMatrixType GetType() const 62 { 63 auto& attribute = static_cast<SvgFeColorMatrixAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 64 return attribute.type; 65 } 66 GetValues()67 const std::string& GetValues() const 68 { 69 auto& attribute = static_cast<SvgFeColorMatrixAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 70 return attribute.values; 71 } 72 73 protected: 74 void InitSpecialized() override; 75 bool SetSpecializedValue(const std::pair<std::string, std::string>& attr) override; 76 }; 77 78 } // namespace OHOS::Ace 79 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_FE_COLORMATRIX_DECLARATION_H 81