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 SetHasSetAllowScale(bool isSetAllowScale)130 void SetHasSetAllowScale(bool isSetAllowScale) 131 { 132 isSetAllowScale_ = isSetAllowScale; 133 } HasSetAllowScale()134 bool HasSetAllowScale() const 135 { 136 return isSetAllowScale_; 137 } 138 SetHasSetFontFeatures(bool isSetFontFeatures)139 void SetHasSetFontFeatures(bool isSetFontFeatures) 140 { 141 isSetFontFeatures_ = isSetFontFeatures; 142 } HasSetFontFeatures()143 bool HasSetFontFeatures() const 144 { 145 return isSetFontFeatures_; 146 } 147 SetHasSetLetterSpacing(bool isSetLetterSpacing)148 void SetHasSetLetterSpacing(bool isSetLetterSpacing) 149 { 150 isSetLetterSpacing_ = isSetLetterSpacing; 151 } HasSetLetterSpacing()152 bool HasSetLetterSpacing() const 153 { 154 return isSetLetterSpacing_; 155 } 156 SetHasSetTextCase(bool isSetTextCase)157 void SetHasSetTextCase(bool isSetTextCase) 158 { 159 isSetTextCase_ = isSetTextCase; 160 } HasSetTextCase()161 bool HasSetTextCase() const 162 { 163 return isSetTextCase_; 164 } 165 166 protected: 167 void InitCommonEvent() override; InitCommonAttribute()168 void InitCommonAttribute() override {} InitCommonStyle()169 void InitCommonStyle() override {} InitCommonMethod()170 void InitCommonMethod() override {} 171 void InitSpecialized() override; 172 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 173 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 174 175 bool isSetFontStyle_ = false; 176 bool isSetFontColor_ = false; 177 bool isSetFontWeight_ = false; 178 bool isSetFontSize_ = false; 179 bool isSetFontFamily_ = false; 180 bool isSetTextDecoration_ = false; 181 bool isSetAllowScale_ = false; 182 bool isSetFontFeatures_ = false; 183 bool isSetLetterSpacing_ = false; 184 bool isSetTextCase_ = false; 185 }; 186 187 } // namespace OHOS::Ace 188 189 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SPAN_SPAN_DECLARATION_H 190