1 /*
2  * Copyright (c) 2021-2022 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 "frameworks/core/components/svg/svg_text_component.h"
17 
18 #include "frameworks/core/components/svg/render_svg_text.h"
19 #include "frameworks/core/components/svg/svg_text_element.h"
20 
21 namespace OHOS::Ace {
22 
SvgTextComponent()23 SvgTextComponent::SvgTextComponent()
24 {
25     InitDeclaration();
26 }
27 
SvgTextComponent(const std::list<RefPtr<Component>> & children)28 SvgTextComponent::SvgTextComponent(const std::list<RefPtr<Component>>& children) : ComponentGroup(children)
29 {
30     InitDeclaration();
31 }
32 
InitDeclaration()33 void SvgTextComponent::InitDeclaration()
34 {
35     if (!declaration_) {
36         declaration_ = AceType::MakeRefPtr<SvgTextDeclaration>();
37         declaration_->Init();
38     }
39 }
40 
CreateElement()41 RefPtr<Element> SvgTextComponent::CreateElement()
42 {
43     return AceType::MakeRefPtr<SvgTextElement>();
44 }
45 
CreateRenderNode()46 RefPtr<RenderNode> SvgTextComponent::CreateRenderNode()
47 {
48     return RenderSvgText::Create();
49 }
50 
GetTextData() const51 const std::string& SvgTextComponent::GetTextData() const
52 {
53     return declaration_->GetTextData();
54 }
55 
SetTextData(const std::string & textData)56 void SvgTextComponent::SetTextData(const std::string& textData)
57 {
58     declaration_->SetTextData(textData);
59 }
60 
SetX(const Dimension & x)61 void SvgTextComponent::SetX(const Dimension& x)
62 {
63     declaration_->SetX(x);
64 }
65 
GetX() const66 const Dimension& SvgTextComponent::GetX() const
67 {
68     return declaration_->GetX();
69 }
70 
SetY(const Dimension & y)71 void SvgTextComponent::SetY(const Dimension& y)
72 {
73     declaration_->SetY(y);
74 }
75 
GetY() const76 const Dimension& SvgTextComponent::GetY() const
77 {
78     return declaration_->GetY();
79 }
80 
SetDx(const Dimension & dx)81 void SvgTextComponent::SetDx(const Dimension& dx)
82 {
83     declaration_->SetDx(dx);
84 }
85 
GetDx() const86 const Dimension& SvgTextComponent::GetDx() const
87 {
88     return declaration_->GetDx();
89 }
90 
SetDy(const Dimension & dy)91 void SvgTextComponent::SetDy(const Dimension& dy)
92 {
93     declaration_->SetDy(dy);
94 }
95 
GetDy() const96 const Dimension& SvgTextComponent::GetDy() const
97 {
98     return declaration_->GetDy();
99 }
100 
SetHasX(bool hasX)101 void SvgTextComponent::SetHasX(bool hasX)
102 {
103     declaration_->SetHasX(hasX);
104 }
105 
GetHasX() const106 bool SvgTextComponent::GetHasX() const
107 {
108     return declaration_->HasX();
109 }
110 
SetHasY(bool hasY)111 void SvgTextComponent::SetHasY(bool hasY)
112 {
113     declaration_->SetHasY(hasY);
114 }
115 
GetHasY() const116 bool SvgTextComponent::GetHasY() const
117 {
118     return declaration_->HasY();
119 }
120 
SetRotate(double rotate)121 void SvgTextComponent::SetRotate(double rotate)
122 {
123     declaration_->SetRotate(rotate);
124 }
125 
GetRotate() const126 double SvgTextComponent::GetRotate() const
127 {
128     return declaration_->GetRotate();
129 }
130 
SetDeclaration(const RefPtr<SvgTextDeclaration> & declaration)131 void SvgTextComponent::SetDeclaration(const RefPtr<SvgTextDeclaration>& declaration)
132 {
133     if (declaration) {
134         declaration_ = declaration;
135     }
136 }
137 
138 } // namespace OHOS::Ace
139