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_SPAN_SPAN_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SPAN_SPAN_DECLARATION_H 18 19 #include "core/components/declaration/common/declaration.h" 20 #include "frameworks/bridge/common/dom/dom_type.h" 21 22 namespace OHOS::Ace { 23 24 struct SpanAttribute : Attribute { 25 std::string spanData; 26 bool isShow = true; 27 }; 28 29 struct SpanStyle : Style { 30 TextStyle spanStyle; 31 }; 32 33 class ACE_EXPORT SpanDeclaration : public Declaration { 34 DECLARE_ACE_TYPE(SpanDeclaration, Declaration); 35 36 public: 37 SpanDeclaration() = default; 38 ~SpanDeclaration() override = default; 39 GetSpanData()40 const std::string& GetSpanData() const 41 { 42 auto& attribute = static_cast<SpanAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 43 return attribute.spanData; 44 } 45 SetSpanData(const std::string & spanData)46 void SetSpanData(const std::string& spanData) 47 { 48 auto& attribute = MaybeResetAttribute<SpanAttribute>(AttributeTag::SPECIALIZED_ATTR); 49 attribute.spanData = spanData; 50 } 51 GetSpanStyle()52 const TextStyle& GetSpanStyle() 53 { 54 auto& style = static_cast<SpanStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 55 return style.spanStyle; 56 } 57 SetTextStyle(const TextStyle & spanStyle)58 void SetTextStyle(const TextStyle& spanStyle) 59 { 60 auto& style = MaybeResetStyle<SpanStyle>(StyleTag::SPECIALIZED_STYLE); 61 style.spanStyle = spanStyle; 62 } 63 IsShow()64 bool IsShow() const 65 { 66 auto& attribute = static_cast<SpanAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 67 return attribute.isShow; 68 } 69 SetIsShow(bool isShow)70 void SetIsShow(bool isShow) 71 { 72 auto& attribute = MaybeResetAttribute<SpanAttribute>(AttributeTag::SPECIALIZED_ATTR); 73 attribute.isShow = isShow; 74 } 75 SetHasSetFontStyle(bool isSetFontStyle)76 void SetHasSetFontStyle(bool isSetFontStyle) 77 { 78 isSetFontStyle_ = isSetFontStyle; 79 } HasSetFontStyle()80 bool HasSetFontStyle() const 81 { 82 return isSetFontStyle_; 83 } 84 SetHasSetFontColor(bool isSetFontColor)85 void SetHasSetFontColor(bool isSetFontColor) 86 { 87 isSetFontColor_ = isSetFontColor; 88 } HasSetFontColor()89 bool HasSetFontColor() const 90 { 91 return isSetFontColor_; 92 } 93 SetHasSetFontWeight(bool isSetFontWeight)94 void SetHasSetFontWeight(bool isSetFontWeight) 95 { 96 isSetFontWeight_ = isSetFontWeight; 97 } HasSetFontWeight()98 bool HasSetFontWeight() const 99 { 100 return isSetFontWeight_; 101 } 102 SetHasSetFontSize(bool isSetFontSize)103 void SetHasSetFontSize(bool isSetFontSize) 104 { 105 isSetFontSize_ = isSetFontSize; 106 } HasSetFontSize()107 bool HasSetFontSize() const 108 { 109 return isSetFontSize_; 110 } 111 SetHasSetFontFamily(bool isSetFontFamily)112 void SetHasSetFontFamily(bool isSetFontFamily) 113 { 114 isSetFontFamily_ = isSetFontFamily; 115 } HasSetFontFamily()116 bool HasSetFontFamily() const 117 { 118 return isSetFontFamily_; 119 } 120 SetHasSetTextDecoration(bool isSetTextDecoration)121 void SetHasSetTextDecoration(bool isSetTextDecoration) 122 { 123 isSetTextDecoration_ = isSetTextDecoration; 124 } HasSetTextDecoration()125 bool HasSetTextDecoration() const 126 { 127 return isSetTextDecoration_; 128 } 129 SetHasSetTextDecorationColor(bool isSetTextDecorationColor)130 void SetHasSetTextDecorationColor(bool isSetTextDecorationColor) 131 { 132 isSetTextDecorationColor_ = isSetTextDecorationColor; 133 } HasSetTextDecorationColor()134 bool HasSetTextDecorationColor() const 135 { 136 return isSetTextDecorationColor_; 137 } 138 SetHasSetTextDecorationStyle(bool isSetTextDecorationStyle)139 void SetHasSetTextDecorationStyle(bool isSetTextDecorationStyle) 140 { 141 isSetTextDecorationStyle_ = isSetTextDecorationStyle; 142 } HasSetTextDecorationStyle()143 bool HasSetTextDecorationStyle() const 144 { 145 return isSetTextDecorationStyle_; 146 } 147 SetHasSetAllowScale(bool isSetAllowScale)148 void SetHasSetAllowScale(bool isSetAllowScale) 149 { 150 isSetAllowScale_ = isSetAllowScale; 151 } HasSetAllowScale()152 bool HasSetAllowScale() const 153 { 154 return isSetAllowScale_; 155 } 156 SetHasSetFontFeatures(bool isSetFontFeatures)157 void SetHasSetFontFeatures(bool isSetFontFeatures) 158 { 159 isSetFontFeatures_ = isSetFontFeatures; 160 } HasSetFontFeatures()161 bool HasSetFontFeatures() const 162 { 163 return isSetFontFeatures_; 164 } 165 SetHasSetLetterSpacing(bool isSetLetterSpacing)166 void SetHasSetLetterSpacing(bool isSetLetterSpacing) 167 { 168 isSetLetterSpacing_ = isSetLetterSpacing; 169 } HasSetLetterSpacing()170 bool HasSetLetterSpacing() const 171 { 172 return isSetLetterSpacing_; 173 } 174 SetHasSetBaselineOffset(bool isSetBaselineOffset)175 void SetHasSetBaselineOffset(bool isSetBaselineOffset) 176 { 177 isBaselineOffset_ = isSetBaselineOffset; 178 } HasSetBaselineOffset()179 bool HasSetBaselineOffset() const 180 { 181 return isBaselineOffset_; 182 } 183 SetHasSetTextCase(bool isSetTextCase)184 void SetHasSetTextCase(bool isSetTextCase) 185 { 186 isSetTextCase_ = isSetTextCase; 187 } HasSetTextCase()188 bool HasSetTextCase() const 189 { 190 return isSetTextCase_; 191 } 192 193 protected: 194 void InitCommonEvent() override; InitCommonAttribute()195 void InitCommonAttribute() override {} InitCommonStyle()196 void InitCommonStyle() override {} InitCommonMethod()197 void InitCommonMethod() override {} 198 void InitSpecialized() override; 199 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 200 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 201 202 bool isSetFontStyle_ = false; 203 bool isSetFontColor_ = false; 204 bool isSetFontWeight_ = false; 205 bool isSetFontSize_ = false; 206 bool isSetFontFamily_ = false; 207 bool isSetTextDecoration_ = false; 208 bool isSetTextDecorationColor_ = false; 209 bool isSetTextDecorationStyle_ = false; 210 bool isSetAllowScale_ = false; 211 bool isSetFontFeatures_ = false; 212 bool isSetLetterSpacing_ = false; 213 bool isBaselineOffset_ = false; 214 bool isSetTextCase_ = false; 215 }; 216 217 } // namespace OHOS::Ace 218 219 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SPAN_SPAN_DECLARATION_H 220