1 /*
2  * Copyright (c) 2023-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 #ifndef C_INCLUDE_DRAWING_TEXT_BLOB_H
17 #define C_INCLUDE_DRAWING_TEXT_BLOB_H
18 
19 /**
20  * @addtogroup Drawing
21  * @{
22  *
23  * @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
24  *
25  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
26  *
27  * @since 11
28  * @version 1.0
29  */
30 
31 /**
32  * @file drawing_text_blob.h
33  *
34  * @brief Declares functions related to the <b>textBlob</b> object in the drawing module.
35  *
36  * @kit ArkGraphics2D
37  * @library libnative_drawing.so
38  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
39  * @since 11
40  * @version 1.0
41  */
42 
43 #include "drawing_types.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Creates an <b>OH_Drawing_TextBlobBuilder</b> object.
51  *
52  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
53  * @return Returns the pointer to the <b>OH_Drawing_TextBlobBuilder</b> object created.
54  * @since 11
55  * @version 1.0
56  */
57 OH_Drawing_TextBlobBuilder* OH_Drawing_TextBlobBuilderCreate(void);
58 
59 /**
60  * @brief Creates an <b>OH_Drawing_TextBlob</b> object from text.
61  *
62  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
63  * @param text Indicates the the pointer to text.
64  * @param byteLength Indicates the text length.
65  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
66  * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object.
67  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created.
68  * @since 12
69  * @version 1.0
70  */
71 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromText(const void* text, size_t byteLength,
72     const OH_Drawing_Font*, OH_Drawing_TextEncoding);
73 
74 /**
75  * @brief Creates an <b>OH_Drawing_TextBlob</b> object from pos text.
76  *
77  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
78  * @param text Indicates the the pointer to text.
79  * @param byteLength Indicates the text length.
80  * @param OH_Drawing_Point2D Indicates the pointer to an <b>OH_Drawing_Point2D</b> array object.
81  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
82  * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object.
83  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created.
84  * @since 12
85  * @version 1.0
86  */
87 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromPosText(const void* text, size_t byteLength,
88     OH_Drawing_Point2D*, const OH_Drawing_Font*, OH_Drawing_TextEncoding);
89 
90 /**
91  * @brief Creates an <b>OH_Drawing_TextBlob</b> object from pos text.
92  *
93  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
94  * @param str Indicates the the pointer to text.
95  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
96  * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object.
97  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created.
98  * @since 12
99  * @version 1.0
100  */
101 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromString(const char* str,
102     const OH_Drawing_Font*, OH_Drawing_TextEncoding);
103 
104 /**
105  * @brief Gets the bounds of textblob, assigned to the pointer to an <b>OH_Drawing_Rect</b> object.
106  *
107  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
108  * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
109  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
110  * @since 12
111  * @version 1.0
112  */
113 void OH_Drawing_TextBlobGetBounds(OH_Drawing_TextBlob*, OH_Drawing_Rect*);
114 
115 /**
116  * @brief Gets a non-zero value unique among all <b>OH_Drawing_TextBlob</b> objects.
117  *
118  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
119  * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
120  * @return Returns identifier for the <b>OH_Drawing_TextBlob</b> object.
121  * @since 12
122  * @version 1.0
123  */
124 uint32_t OH_Drawing_TextBlobUniqueID(const OH_Drawing_TextBlob*);
125 
126 /**
127  * @brief Defines a run, supplies storage for glyphs and positions.
128  *
129  * @since 11
130  * @version 1.0
131  */
132 typedef struct {
133     /** storage for glyph indexes in run */
134     uint16_t* glyphs;
135     /** storage for glyph positions in run */
136     float* pos;
137     /** storage for text UTF-8 code units in run */
138     char* utf8text;
139     /** storage for glyph clusters (index of UTF-8 code unit) */
140     uint32_t* clusters;
141 } OH_Drawing_RunBuffer;
142 
143 /**
144  * @brief Alloc run with storage for glyphs and positions. The returned pointer does not need to be managed
145  * by the caller and is forbidden to be used after OH_Drawing_TextBlobBuilderMake is called.
146  *
147  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
148  * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object.
149  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
150  * @param count Indicates the number of glyphs.
151  * @param OH_Drawing_Rect Indicates the optional run bounding box.
152  * @since 11
153  * @version 1.0
154  */
155 const OH_Drawing_RunBuffer* OH_Drawing_TextBlobBuilderAllocRunPos(OH_Drawing_TextBlobBuilder*, const OH_Drawing_Font*,
156     int32_t count, const OH_Drawing_Rect*);
157 
158 /**
159  * @brief Make an <b>OH_Drawing_TextBlob</b> from <b>OH_Drawing_TextBlobBuilder</b>.
160  *
161  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
162  * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object.
163  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object.
164  * @since 11
165  * @version 1.0
166  */
167 OH_Drawing_TextBlob* OH_Drawing_TextBlobBuilderMake(OH_Drawing_TextBlobBuilder*);
168 
169 /**
170  * @brief Destroys an <b>OH_Drawing_TextBlob</b> object and reclaims the memory occupied by the object.
171  *
172  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
173  * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
174  * @since 11
175  * @version 1.0
176  */
177 void OH_Drawing_TextBlobDestroy(OH_Drawing_TextBlob*);
178 
179 /**
180  * @brief Destroys an <b>OH_Drawing_TextBlobBuilder</b> object and reclaims the memory occupied by the object.
181  *
182  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
183  * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object.
184  * @since 11
185  * @version 1.0
186  */
187 void OH_Drawing_TextBlobBuilderDestroy(OH_Drawing_TextBlobBuilder*);
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 /** @} */
193 #endif
194