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 "frameworks/bridge/common/dom/dom_svg_text.h"
17 
18 namespace OHOS::Ace::Framework {
19 
DOMSvgText(NodeId nodeId,const std::string & nodeName)20 DOMSvgText::DOMSvgText(NodeId nodeId, const std::string& nodeName) : DOMSvgBase(nodeId, nodeName) {}
21 
GetSpecializedComponent()22 RefPtr<Component> DOMSvgText::GetSpecializedComponent()
23 {
24     return textComponent_;
25 }
26 
OnChildNodeAdded(const RefPtr<DOMNode> & child,int32_t slot)27 void DOMSvgText::OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot)
28 {
29     textComponent_->InsertChild(slot, child->GetSpecializedComponent());
30 }
31 
OnMounted(const RefPtr<DOMNode> & parentNode)32 void DOMSvgText::OnMounted(const RefPtr<DOMNode>& parentNode)
33 {
34     auto declaration = AceType::DynamicCast<SvgTextDeclaration>(declaration_);
35     if (!declaration) {
36         return;
37     }
38     // inherit presentation attributes
39     auto svgNode = AceType::DynamicCast<DOMSvgBase>(parentNode);
40     if (svgNode) {
41         declaration->Inherit(svgNode->GetDeclaration());
42     }
43     // inherit rotate attribute
44     if (!declaration->HasRotate()) {
45         auto svgTextNode = AceType::DynamicCast<DOMSvgText>(parentNode);
46         if (svgTextNode) {
47             declaration->SetRotate(svgTextNode->GetRotate());
48         }
49     }
50 }
51 
PrepareSpecializedComponent()52 void DOMSvgText::PrepareSpecializedComponent()
53 {
54     if (!textComponent_) {
55         textComponent_ = AceType::MakeRefPtr<SvgTextComponent>();
56     }
57     auto declaration = AceType::DynamicCast<SvgTextDeclaration>(declaration_);
58     if (declaration) {
59         textComponent_->SetDeclaration(declaration);
60     }
61 }
62 
GetRotate() const63 double DOMSvgText::GetRotate() const
64 {
65     auto declaration = AceType::DynamicCast<SvgTextDeclaration>(declaration_);
66     if (!declaration) {
67         return 0.0;
68     }
69     return declaration->GetRotate();
70 }
71 
72 } // namespace OHOS::Ace::Framework
73