• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 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  * @since 11
37  * @version 1.0
38  */
39 
40 #include "drawing_types.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Enumerates text encoding.
48  * @since 12
49  * @version 1.0
50  */
51 typedef enum {
52     /** uses bytes to represent UTF-8 or ASCII */
53     TEXT_ENCODING_UTF8,
54     /** uses two byte words to represent most of Unicode */
55     TEXT_ENCODING_UTF16,
56     /** uses four byte words to represent all of Unicode */
57     TEXT_ENCODING_UTF32,
58     /** uses two byte words to represent glyph indices */
59     TEXT_ENCODING_GLYPH_ID,
60 } OH_Drawing_TextEncoding;
61 
62 /**
63  * @brief Creates an <b>OH_Drawing_TextBlobBuilder</b> object.
64  *
65  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
66  * @return Returns the pointer to the <b>OH_Drawing_TextBlobBuilder</b> object created.
67  * @since 11
68  * @version 1.0
69  */
70 OH_Drawing_TextBlobBuilder* OH_Drawing_TextBlobBuilderCreate(void);
71 
72 /**
73  * @brief Creates an <b>OH_Drawing_TextBlob</b> object from text.
74  *
75  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
76  * @param text Indicates the the pointer to text.
77  * @param byteLength Indicates the text length.
78  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
79  * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object.
80  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created.
81  * @since 12
82  * @version 1.0
83  */
84 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromText(const void* text, size_t byteLength,
85     const OH_Drawing_Font*, OH_Drawing_TextEncoding);
86 
87 /**
88  * @brief Creates an <b>OH_Drawing_TextBlob</b> object from pos text.
89  *
90  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
91  * @param text Indicates the the pointer to text.
92  * @param byteLength Indicates the text length.
93  * @param OH_Drawing_Point Indicates the points.
94  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
95  * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object.
96  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created.
97  * @since 12
98  * @version 1.0
99  */
100 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromPosText(const void* text, size_t byteLength,
101     OH_Drawing_Point* points, const OH_Drawing_Font*, OH_Drawing_TextEncoding);
102 
103 /**
104  * @brief Creates an <b>OH_Drawing_TextBlob</b> object from pos text.
105  *
106  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
107  * @param str Indicates the the pointer to text.
108  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
109  * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object.
110  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created.
111  * @since 12
112  * @version 1.0
113  */
114 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromString(const char* str,
115     const OH_Drawing_Font*, OH_Drawing_TextEncoding);
116 
117 /**
118  * @brief Gets the bounds of textblob, assigned to the pointer to an <b>OH_Drawing_Rect</b> object.
119  *
120  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
121  * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
122  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
123  * @since 12
124  * @version 1.0
125  */
126 void OH_Drawing_TextBlobGetBounds(OH_Drawing_TextBlob*, OH_Drawing_Rect*);
127 
128 /**
129  * @brief Defines a run, supplies storage for glyphs and positions.
130  *
131  * @since 11
132  * @version 1.0
133  */
134 typedef struct {
135     /** storage for glyph indexes in run */
136     uint16_t* glyphs;
137     /** storage for glyph positions in run */
138     float* pos;
139     /** storage for text UTF-8 code units in run */
140     char* utf8text;
141     /** storage for glyph clusters (index of UTF-8 code unit) */
142     uint32_t* clusters;
143 } OH_Drawing_RunBuffer;
144 
145 /**
146  * @brief Alloc run with storage for glyphs and positions. The returned pointer does not need to be managed
147  * by the caller and is forbidden to be used after OH_Drawing_TextBlobBuilderMake is called.
148  *
149  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
150  * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object.
151  * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
152  * @param count Indicates the number of glyphs.
153  * @param OH_Drawing_Rect Indicates the optional run bounding box.
154  * @since 11
155  * @version 1.0
156  */
157 const OH_Drawing_RunBuffer* OH_Drawing_TextBlobBuilderAllocRunPos(OH_Drawing_TextBlobBuilder*, const OH_Drawing_Font*,
158     int32_t count, const OH_Drawing_Rect*);
159 
160 /**
161  * @brief Make an <b>OH_Drawing_TextBlob</b> from <b>OH_Drawing_TextBlobBuilder</b>.
162  *
163  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
164  * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object.
165  * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object.
166  * @since 11
167  * @version 1.0
168  */
169 OH_Drawing_TextBlob* OH_Drawing_TextBlobBuilderMake(OH_Drawing_TextBlobBuilder*);
170 
171 /**
172  * @brief Destroys an <b>OH_Drawing_TextBlob</b> object and reclaims the memory occupied by the object.
173  *
174  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
175  * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
176  * @since 11
177  * @version 1.0
178  */
179 void OH_Drawing_TextBlobDestroy(OH_Drawing_TextBlob*);
180 
181 /**
182  * @brief Destroys an <b>OH_Drawing_TextBlobBuilder</b> object and reclaims the memory occupied by the object.
183  *
184  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
185  * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object.
186  * @since 11
187  * @version 1.0
188  */
189 void OH_Drawing_TextBlobBuilderDestroy(OH_Drawing_TextBlobBuilder*);
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 /** @} */
195 #endif
196