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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_SPAN_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_SPAN_MODEL_NG_H
18 
19 #include <functional>
20 #include <string>
21 
22 #include "interfaces/native/node/styled_string.h"
23 
24 #include "core/components_ng/pattern/text/span_model.h"
25 #include "core/components_ng/pattern/text/span_node.h"
26 namespace OHOS::Ace::NG {
27 class ACE_EXPORT SpanModelNG : public SpanModel {
28 public:
29     void Create(const std::string& content) override;
30     void SetFont(const Font& value) override;
31     void SetFontSize(const Dimension& value) override;
32     void SetTextColor(const Color& value) override;
33     void SetItalicFontStyle(Ace::FontStyle value) override;
34     void SetFontWeight(FontWeight value) override;
35     void SetFontFamily(const std::vector<std::string>& value) override;
36     void SetTextDecoration(TextDecoration value) override;
37     void SetTextDecorationStyle(TextDecorationStyle value) override;
38     void SetTextDecorationColor(const Color& value) override;
39     void SetTextCase(TextCase value) override;
40     void SetTextShadow(const std::vector<Shadow>& value) override;
41     void SetLetterSpacing(const Dimension& value) override;
42     void SetBaselineOffset(const Dimension& value) override;
43     void SetLineHeight(const Dimension& value) override;
44     void SetOnClick(std::function<void(BaseEventInfo* info)>&& click) override;
45     void ClearOnClick() override;
46     void SetAccessibilityText(const std::string& text) override;
47     void SetAccessibilityDescription(const std::string& description) override;
48     void SetAccessibilityImportance(const std::string& importance) override;
49 
50     static RefPtr<SpanNode> CreateSpanNode(int32_t nodeId, const std::string& content);
51     static void InitSpan(UINode* uiNode, const std::string& content);
52     static void SetFontWeight(UINode* uiNode, FontWeight value);
53     static void ResetFontWeight(UINode* uiNode);
54     static void SetTextCase(UINode* uiNode, TextCase value);
55     static void ResetTextCase(UINode* uiNode);
56     static void SetItalicFontStyle(UINode* uiNode, Ace::FontStyle value);
57     static void ResetItalicFontStyle(UINode* uiNode);
58     static void SetLineHeight(UINode* uiNode, const Dimension& value);
59     static void ResetLineHeight(UINode* uiNode);
60     static void SetFontSize(UINode* uiNode, const Dimension& value);
61     static void ResetFontSize(UINode* uiNode);
62     static void SetFontFamily(UINode* uiNode, const std::vector<std::string>& value);
63     static void ResetFontFamily(UINode* uiNode);
64     static void SetTextDecoration(UINode* uiNode, TextDecoration value);
65     static void ResetTextDecoration(UINode* uiNode);
66     static void SetTextDecorationStyle(UINode* uiNode, TextDecorationStyle value);
67     static void ResetTextDecorationStyle(UINode* uiNode);
68     static void SetTextDecorationColor(UINode* uiNode, const Color& value);
69     static void ResetTextDecorationColor(UINode* uiNode);
70     static void SetTextColor(UINode* uiNode, const Color& value);
71     static void ResetTextColor(UINode* uiNode);
72     static void SetLetterSpacing(UINode* uiNode, const Dimension& value);
73     static void ResetLetterSpacing(UINode* uiNode);
74     static void SetBaselineOffset(UINode* uiNode, const Dimension& value);
75     static void SetFont(UINode* uiNode, const Font& value);
76     static void ResetFont(UINode* uiNode);
77     static std::string GetContent(UINode* uiNode);
78     static Ace::TextDecoration GetTextDecoration(UINode* uiNode);
79     static Color GetTextDecorationColor(UINode* uiNode);
80     static Ace::TextDecorationStyle GetTextDecorationStyle(UINode* uiNode);
81     static Color GetFontColor(UINode* uiNode);
82     static Dimension GetFontSize(UINode* uiNode);
83     static Ace::FontStyle GetFontStyle(UINode* uiNode);
84     static FontWeight GetFontWeight(UINode* uiNode);
85     static Dimension GetTextLineHeight(UINode* uiNode);
86     static Ace::TextCase GetTextCase(UINode* uiNode);
87     static Dimension GetLetterSpacing(UINode* uiNode);
88     static Dimension GetBaselineOffset(UINode* uiNode);
89     static TextStyle GetDefaultTextStyle();
90     void CreateContainSpan() override;
91     void SetTextBackgroundStyle(const TextBackgroundStyle& style) override;
92     static void SetTextBackgroundStyle(UINode* uiNode, const TextBackgroundStyle& style);
93     static void SetTextBackgroundStyleByBaseSpan(UINode* uiNode, const TextBackgroundStyle& style);
94     static TextBackgroundStyle GetSpanTextBackgroundStyle(UINode* uiNode);
95     static void SetTextShadow(UINode* uiNode, const std::vector<Shadow>& value);
96     static void ResetTextShadow(UINode* uiNode);
97     static std::vector<Shadow> GetTextShadow(UINode* uiNode);
98     static void SetOnClick(UINode* uiNode, GestureEventFunc&& click);
99     static void ClearOnClick(UINode* uiNode);
100     static void SetAccessibilityText(UINode* uiNode, const std::string& text);
101     static void SetAccessibilityDescription(UINode* uiNode, const std::string& description);
102     static void SetAccessibilityImportance(UINode* uiNode, const std::string& importance);
103     static std::vector<std::string> GetSpanFontFamily(UINode* uiNode);
104 #ifdef USE_GRAPHIC_TEXT_GINE
105     // impl in render/adapter/span_model_adapter.cpp
106     static RefPtr<SpanItem> CreateSpanItem(ArkUI_SpanItem* item);
107     static ParagraphStyle CreateParagraphStyle(ArkUI_StyledString* styledString);
108 #endif
109 };
110 } // namespace OHOS::Ace::NG
111 
112 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_SPAN_MODEL_NG_H
113