1 /*
2  * Copyright (c) 2024 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 /**
17  * @addtogroup ArkUI_NativeModule
18  * @{
19  *
20  * @brief 提供ArkUI在Native侧的UI能力,如UI组件创建销毁、树节点操作,属性设置,事件监听等。
21  *
22  * @since 12
23  */
24 
25 /**
26  * @file styled_string.h
27  *
28  * @brief 提供ArkUI在Native侧的属性字符串能力。
29  *
30  * @library libace_ndk.z.so
31  * @syscap SystemCapability.ArkUI.ArkUI.Full
32  * @since 12
33  */
34 
35 #ifndef ARKUI_NATIVE_STYLED_STRING_H
36 #define ARKUI_NATIVE_STYLED_STRING_H
37 
38 // should be careful this path is not same in SDK.
39 #include "drawing_text_typography.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @brief 定义文本组件支持的格式化字符串数据对象。
47  *
48  * @since 12
49  */
50 typedef struct ArkUI_StyledString ArkUI_StyledString;
51 
52 /**
53  * @brief 创建指向ArkUI_StyledString对象的指针。
54  *
55  * @param style 指向OH_Drawing_TypographyStyle的指针,由{@link OH_Drawing_CreateTypographyStyle}获取。
56  * @param collection 指向OH_Drawing_FontCollection的指针,由{@link OH_Drawing_CreateFontCollection}获取。
57  * @return 创建指向ArkUI_StyledString对象的指针,异常返回空指针。
58  * @since 12
59  */
60 ArkUI_StyledString* OH_ArkUI_StyledString_Create(
61     OH_Drawing_TypographyStyle* style, OH_Drawing_FontCollection* collection);
62 
63 /**
64  * @brief 释放被ArkUI_StyledString对象占据的内存。
65  *
66  * @param handle 指向ArkUI_StyledString对象的指针。
67  * @since 12
68  */
69 void OH_ArkUI_StyledString_Destroy(ArkUI_StyledString* handle);
70 
71 /**
72  * @brief 将新的排版风格设置到当前格式化字符串样式栈顶。
73  *
74  * @param handle 指向ArkUI_StyledString对象的指针。
75  * @param style 指向OH_Drawing_TextStyle对象的指针。
76  * @since 12
77  */
78 void OH_ArkUI_StyledString_PushTextStyle(ArkUI_StyledString* handle, OH_Drawing_TextStyle* style);
79 
80 /**
81  * @brief 基于当前格式化字符串样式设置对应的文本内容。
82  *
83  * @param handle 指向ArkUI_StyledString对象的指针。
84  * @param content 指向文本内容的指针。
85  * @since 12
86  */
87 void OH_ArkUI_StyledString_AddText(ArkUI_StyledString* handle, const char* content);
88 
89 /**
90  * @brief 将当前格式化字符串对象中栈顶样式出栈。
91  *
92  * @param handle 指向ArkUI_StyledString对象的指针。
93  * @since 12
94  */
95 void OH_ArkUI_StyledString_PopTextStyle(ArkUI_StyledString* handle);
96 
97 /**
98  * @brief 基于格式字符串对象创建指向OH_Drawing_Typography对象的指针,用于提前进行文本测算排版。
99  *
100  * @param handle 指向ArkUI_StyledString对象的指针。
101  * @return 指向OH_Drawing_Typography对象的指针。
102  * @since 12
103  */
104 OH_Drawing_Typography* OH_ArkUI_StyledString_CreateTypography(ArkUI_StyledString* handle);
105 
106 /**
107  * @brief 设置占位符。
108  *
109  * @param handle 指向ArkUI_StyledString对象的指针。
110  * @param placeholder 指向OH_Drawing_PlaceholderSpan对象的指针。
111  * @since 12
112  */
113 void OH_ArkUI_StyledString_AddPlaceholder(ArkUI_StyledString* handle, OH_Drawing_PlaceholderSpan* placeholder);
114 
115 #ifdef __cplusplus
116 };
117 #endif
118 
119 #endif // ARKUI_NATIVE_STYLED_STRING_H