• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_v2/inspector/utils.h"
23 
24 namespace OHOS::Ace::NG {
25 constexpr Dimension TEXT_DEFAULT_FONT_SIZE = 16.0_fp;
26 
27 struct FontStyle {
28     ACE_DEFINE_PROPERTY_GROUP_ITEM(FontSize, Dimension);
29     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextColor, Color);
30     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextShadow, Shadow);
31     ACE_DEFINE_PROPERTY_GROUP_ITEM(ItalicFontStyle, Ace::FontStyle);
32     ACE_DEFINE_PROPERTY_GROUP_ITEM(FontWeight, FontWeight);
33     ACE_DEFINE_PROPERTY_GROUP_ITEM(FontFamily, std::vector<std::string>);
34     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecoration, TextDecoration);
35     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecorationColor, Color);
36     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextCase, TextCase);
37     ACE_DEFINE_PROPERTY_GROUP_ITEM(AdaptMinFontSize, Dimension);
38     ACE_DEFINE_PROPERTY_GROUP_ITEM(AdaptMaxFontSize, Dimension);
39     ACE_DEFINE_PROPERTY_GROUP_ITEM(LetterSpacing, Dimension);
40     ACE_DEFINE_PROPERTY_GROUP_ITEM(ForegroundColor, Color);
41 };
42 
43 struct TextLineStyle {
44     ACE_DEFINE_PROPERTY_GROUP_ITEM(LineHeight, Dimension);
45     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextBaseline, TextBaseline);
46     ACE_DEFINE_PROPERTY_GROUP_ITEM(BaselineOffset, Dimension);
47     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextOverflow, TextOverflow);
48     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextAlign, TextAlign);
49     ACE_DEFINE_PROPERTY_GROUP_ITEM(MaxLength, uint32_t);
50     ACE_DEFINE_PROPERTY_GROUP_ITEM(MaxLines, uint32_t);
51     ACE_DEFINE_PROPERTY_GROUP_ITEM(HeightAdaptivePolicy, TextHeightAdaptivePolicy);
52     ACE_DEFINE_PROPERTY_GROUP_ITEM(TextIndent, Dimension);
53 };
54 
55 TextStyle CreateTextStyleUsingTheme(const std::unique_ptr<FontStyle>& fontStyle,
56     const std::unique_ptr<TextLineStyle>& textLineStyle, const RefPtr<TextTheme>& textTheme);
57 
58 TextStyle CreateTextStyleUsingThemeWithText(const RefPtr<FrameNode> frameNode,
59     const std::unique_ptr<FontStyle>& fontStyle, const std::unique_ptr<TextLineStyle>& textLineStyle,
60     const RefPtr<TextTheme>& textTheme);
61 
62 std::string GetFontFamilyInJson(const std::optional<std::vector<std::string>>& value);
63 std::string GetFontStyleInJson(const std::optional<Ace::FontStyle>& value);
64 std::string GetFontWeightInJson(const std::optional<FontWeight>& value);
65 std::string GetFontSizeInJson(const std::optional<Dimension>& value);
66 } // namespace OHOS::Ace::NG
67 
68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_STYLES_H
69