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