• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "bridge/declarative_frontend/jsview/models/span_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 
20 namespace OHOS::Ace::Framework {
Create(const std::string & content)21 void SpanModelImpl::Create(const std::string& content)
22 {
23     auto spanComponent = AceType::MakeRefPtr<TextSpanComponent>(content);
24     ViewStackProcessor::GetInstance()->ClaimElementId(spanComponent);
25     ViewStackProcessor::GetInstance()->Push(spanComponent);
26 
27     // Init text style, allowScale is not supported in declarative.
28     auto textStyle = spanComponent->GetTextStyle();
29     textStyle.SetAllowScale(false);
30     spanComponent->SetTextStyle(textStyle);
31 }
32 
Create(const std::u16string & content)33 void SpanModelImpl::Create(const std::u16string& content)
34 {
35     Create(UtfUtils::Str16DebugToStr8(content));
36 }
37 
Create(const std::u16string & content,RefPtr<ResourceObject> & resObj)38 void SpanModelImpl::Create(const std::u16string& content, RefPtr<ResourceObject>& resObj)
39 {
40     Create(UtfUtils::Str16DebugToStr8(content));
41 }
42 
SetFont(const Font & value)43 void SpanModelImpl::SetFont(const Font& value) {}
44 
SetFontSize(const Dimension & value)45 void SpanModelImpl::SetFontSize(const Dimension& value)
46 {
47     auto component = GetComponent();
48     CHECK_NULL_VOID(component);
49 
50     auto textStyle = component->GetTextStyle();
51     textStyle.SetFontSize(value);
52     component->SetTextStyle(textStyle);
53 
54     auto declaration = component->GetDeclaration();
55     if (declaration) {
56         declaration->SetHasSetFontSize(true);
57     }
58 }
59 
SetTextColor(const Color & value)60 void SpanModelImpl::SetTextColor(const Color& value)
61 {
62     auto component = GetComponent();
63     CHECK_NULL_VOID(component);
64     auto textStyle = component->GetTextStyle();
65     textStyle.SetTextColor(value);
66     component->SetTextStyle(textStyle);
67     auto declaration = component->GetDeclaration();
68     if (declaration) {
69         declaration->SetHasSetFontColor(true);
70     }
71 }
72 
SetItalicFontStyle(Ace::FontStyle value)73 void SpanModelImpl::SetItalicFontStyle(Ace::FontStyle value)
74 {
75     auto component = GetComponent();
76     CHECK_NULL_VOID(component);
77     auto textStyle = component->GetTextStyle();
78     textStyle.SetFontStyle(value);
79     component->SetTextStyle(textStyle);
80 
81     auto declaration = component->GetDeclaration();
82     if (declaration) {
83         declaration->SetHasSetFontStyle(true);
84     }
85 }
86 
SetFontWeight(Ace::FontWeight value)87 void SpanModelImpl::SetFontWeight(Ace::FontWeight value)
88 {
89     auto component = GetComponent();
90     CHECK_NULL_VOID(component);
91 
92     auto textStyle = component->GetTextStyle();
93     textStyle.SetFontWeight(value);
94     component->SetTextStyle(textStyle);
95 
96     auto declaration = component->GetDeclaration();
97     if (declaration) {
98         declaration->SetHasSetFontWeight(true);
99     }
100 }
101 
SetFontFamily(const std::vector<std::string> & value)102 void SpanModelImpl::SetFontFamily(const std::vector<std::string>& value)
103 {
104     auto component = GetComponent();
105     CHECK_NULL_VOID(component);
106 
107     auto textStyle = component->GetTextStyle();
108     textStyle.SetFontFamilies(value);
109     component->SetTextStyle(textStyle);
110 
111     auto declaration = component->GetDeclaration();
112     if (declaration) {
113         declaration->SetHasSetFontFamily(true);
114     }
115 }
116 
SetTextDecoration(Ace::TextDecoration value)117 void SpanModelImpl::SetTextDecoration(Ace::TextDecoration value)
118 {
119     auto component = GetComponent();
120     CHECK_NULL_VOID(component);
121     auto textStyle = component->GetTextStyle();
122     textStyle.SetTextDecoration(value);
123     component->SetTextStyle(textStyle);
124 }
125 
SetTextDecorationColor(const Color & value)126 void SpanModelImpl::SetTextDecorationColor(const Color& value)
127 {
128     auto component = GetComponent();
129     CHECK_NULL_VOID(component);
130     auto textStyle = component->GetTextStyle();
131     textStyle.SetTextDecorationColor(value);
132     component->SetTextStyle(textStyle);
133 }
134 
SetTextDecorationStyle(Ace::TextDecorationStyle value)135 void SpanModelImpl::SetTextDecorationStyle(Ace::TextDecorationStyle value)
136 {
137     auto component = GetComponent();
138     CHECK_NULL_VOID(component);
139     auto textStyle = component->GetTextStyle();
140     textStyle.SetTextDecorationStyle(value);
141     component->SetTextStyle(textStyle);
142 }
143 
SetTextCase(Ace::TextCase value)144 void SpanModelImpl::SetTextCase(Ace::TextCase value)
145 {
146     auto component = GetComponent();
147     CHECK_NULL_VOID(component);
148     auto textStyle = component->GetTextStyle();
149     textStyle.SetTextCase(value);
150     component->SetTextStyle(textStyle);
151 
152     auto declaration = component->GetDeclaration();
153     if (declaration) {
154         declaration->SetHasSetTextCase(true);
155     }
156 }
157 
SetLetterSpacing(const Dimension & value)158 void SpanModelImpl::SetLetterSpacing(const Dimension& value)
159 {
160     auto component = GetComponent();
161     CHECK_NULL_VOID(component);
162 
163     auto textStyle = component->GetTextStyle();
164     textStyle.SetLetterSpacing(value);
165     component->SetTextStyle(textStyle);
166 
167     auto declaration = component->GetDeclaration();
168     if (declaration) {
169         declaration->SetHasSetLetterSpacing(true);
170     }
171 }
172 
SetBaselineOffset(const Dimension & value)173 void SpanModelImpl::SetBaselineOffset(const Dimension& value) {}
174 
GetComponent()175 RefPtr<TextSpanComponent> SpanModelImpl::GetComponent()
176 {
177     auto* stack = ViewStackProcessor::GetInstance();
178     return AceType::DynamicCast<TextSpanComponent>(stack->GetMainComponent());
179 }
180 
SetOnClick(std::function<void (BaseEventInfo *)> && click)181 void SpanModelImpl::SetOnClick(std::function<void(BaseEventInfo*)>&& click)
182 {
183     auto component = GetComponent();
184     if (component) {
185         component->SetOnClick(EventMarker(std::move(click)));
186     }
187 }
188 
SetLineHeight(const Dimension & value)189 void SpanModelImpl::SetLineHeight(const Dimension& value) {}
190 
191 } // namespace OHOS::Ace::Framework
192