1 /* 2 * Copyright (c) 2022-2023 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_NG_PATTERNS_TEXT_TEXT_STYLES_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_STYLES_H 18 19 #include "core/components/common/properties/text_style.h" 20 #include "core/components/text/text_theme.h" 21 #include "core/components_ng/property/property.h" 22 #include "core/components_ng/render/paragraph.h" 23 #include "core/components_v2/inspector/utils.h" 24 25 namespace OHOS::Ace::NG { 26 constexpr Dimension TEXT_DEFAULT_FONT_SIZE = 16.0_fp; 27 using FONT_FEATURES_MAP = std::unordered_map<std::string, int32_t>; 28 struct FontStyle { 29 ACE_DEFINE_PROPERTY_GROUP_ITEM(FontSize, Dimension); 30 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextColor, Color); 31 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextShadow, std::vector<Shadow>); 32 ACE_DEFINE_PROPERTY_GROUP_ITEM(ItalicFontStyle, Ace::FontStyle); 33 ACE_DEFINE_PROPERTY_GROUP_ITEM(FontWeight, FontWeight); 34 ACE_DEFINE_PROPERTY_GROUP_ITEM(FontFamily, std::vector<std::string>); 35 ACE_DEFINE_PROPERTY_GROUP_ITEM(FontFeature, FONT_FEATURES_MAP); 36 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecoration, TextDecoration); 37 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecorationColor, Color); 38 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecorationStyle, TextDecorationStyle); 39 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextCase, TextCase); 40 ACE_DEFINE_PROPERTY_GROUP_ITEM(AdaptMinFontSize, Dimension); 41 ACE_DEFINE_PROPERTY_GROUP_ITEM(AdaptMaxFontSize, Dimension); 42 ACE_DEFINE_PROPERTY_GROUP_ITEM(LetterSpacing, Dimension); 43 ACE_DEFINE_PROPERTY_GROUP_ITEM(ForegroundColor, Color); 44 ACE_DEFINE_PROPERTY_GROUP_ITEM(SymbolColorList, std::vector<Color>); 45 ACE_DEFINE_PROPERTY_GROUP_ITEM(SymbolRenderingStrategy, uint32_t); 46 ACE_DEFINE_PROPERTY_GROUP_ITEM(SymbolEffectStrategy, uint32_t); 47 }; 48 49 struct TextLineStyle { 50 ACE_DEFINE_PROPERTY_GROUP_ITEM(LineHeight, Dimension); 51 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextBaseline, TextBaseline); 52 ACE_DEFINE_PROPERTY_GROUP_ITEM(BaselineOffset, Dimension); 53 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextOverflow, TextOverflow); 54 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextAlign, TextAlign); 55 ACE_DEFINE_PROPERTY_GROUP_ITEM(MaxLength, uint32_t); 56 ACE_DEFINE_PROPERTY_GROUP_ITEM(MaxLines, uint32_t); 57 ACE_DEFINE_PROPERTY_GROUP_ITEM(HeightAdaptivePolicy, TextHeightAdaptivePolicy); 58 ACE_DEFINE_PROPERTY_GROUP_ITEM(TextIndent, Dimension); 59 ACE_DEFINE_PROPERTY_GROUP_ITEM(LeadingMargin, LeadingMargin); 60 ACE_DEFINE_PROPERTY_GROUP_ITEM(WordBreak, WordBreak); 61 ACE_DEFINE_PROPERTY_GROUP_ITEM(EllipsisMode, EllipsisMode); 62 }; 63 64 struct HandleInfoNG { UpdateOffsetHandleInfoNG65 void UpdateOffset(const OffsetF& offset) 66 { 67 rect.SetOffset(offset); 68 } 69 AddOffsetHandleInfoNG70 void AddOffset(float x, float y) 71 { 72 auto offset = rect.GetOffset(); 73 offset.AddX(x); 74 offset.AddY(y); 75 UpdateOffset(offset); 76 } 77 78 bool operator==(const HandleInfoNG& handleInfo) const 79 { 80 81 return rect == handleInfo.rect && index == handleInfo.index; 82 } 83 84 bool operator!=(const HandleInfoNG& handleInfo) const 85 { 86 return !operator==(handleInfo); 87 } 88 89 int32_t index = 0; 90 RectF rect; 91 }; 92 93 TextStyle CreateTextStyleUsingTheme(const std::unique_ptr<FontStyle>& fontStyle, 94 const std::unique_ptr<TextLineStyle>& textLineStyle, const RefPtr<TextTheme>& textTheme); 95 96 TextStyle CreateTextStyleUsingThemeWithText(const RefPtr<FrameNode> frameNode, 97 const std::unique_ptr<FontStyle>& fontStyle, const std::unique_ptr<TextLineStyle>& textLineStyle, 98 const RefPtr<TextTheme>& textTheme); 99 100 std::string GetFontFamilyInJson(const std::optional<std::vector<std::string>>& value); 101 std::string GetFontStyleInJson(const std::optional<Ace::FontStyle>& value); 102 std::string GetFontWeightInJson(const std::optional<FontWeight>& value); 103 std::string GetFontSizeInJson(const std::optional<Dimension>& value); 104 std::string GetSymbolRenderingStrategyInJson(const std::optional<uint32_t>& value); 105 std::string GetSymbolEffectStrategyInJson(const std::optional<uint32_t>& value); 106 } // namespace OHOS::Ace::NG 107 108 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_STYLES_H 109