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_TEXT_PATH_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_TEXT_PATH_DECLARATION_H
18 
19 #include "core/components/declaration/svg/svg_base_declaration.h"
20 
21 namespace OHOS::Ace {
22 
23 struct SvgTextPathAttribute : SvgBaseAttribute {
24     Dimension startOffset;
25     std::string path;
26     std::string value;
27 };
28 
29 class SvgTextPathDeclaration : public SvgBaseDeclaration {
30     DECLARE_ACE_TYPE(SvgTextPathDeclaration, SvgBaseDeclaration);
31 
32 public:
33     SvgTextPathDeclaration() = default;
34     ~SvgTextPathDeclaration() override = default;
35     void InitializeStyle() override;
36 
GetTextData()37     const std::string& GetTextData() const
38     {
39         auto& attribute = static_cast<SvgTextPathAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
40         return attribute.value;
41     }
42 
SetTextData(const std::string & textData)43     void SetTextData(const std::string& textData)
44     {
45         auto& attribute = MaybeResetAttribute<SvgTextPathAttribute>(AttributeTag::SPECIALIZED_ATTR);
46         attribute.value = textData;
47     }
48 
GetPath()49     const std::string& GetPath() const
50     {
51         auto& attribute = static_cast<SvgTextPathAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
52         return attribute.path;
53     }
54 
SetPath(const std::string & path)55     void SetPath(const std::string& path)
56     {
57         auto& attribute = MaybeResetAttribute<SvgTextPathAttribute>(AttributeTag::SPECIALIZED_ATTR);
58         attribute.path = path;
59     }
60 
SetStartOffset(const Dimension & startOffset)61     void SetStartOffset(const Dimension& startOffset)
62     {
63         auto& attribute = MaybeResetAttribute<SvgTextPathAttribute>(AttributeTag::SPECIALIZED_ATTR);
64         attribute.startOffset = startOffset;
65     }
66 
GetStartOffset()67     const Dimension& GetStartOffset() const
68     {
69         auto& attribute = static_cast<SvgTextPathAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
70         return attribute.startOffset;
71     }
72 
73 protected:
74     void InitSpecialized() override;
75     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
76     bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override;
77 
78 private:
79     bool SetSpecializedValue(const std::pair<std::string, std::string>& attr);
80 };
81 
82 } // namespace OHOS::Ace
83 
84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_TEXT_PATH_DECLARATION_H
85