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 Drawing
18  * @{
19  *
20  * @brief Provides the text run capability.
21  *
22  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
23  *
24  * @since 14
25  * @version 1.0
26  */
27 
28 /**
29  * @file drawing_text_run.h
30  *
31  * @brief Declares functions related to <b>run</b> in the drawing module.
32  *
33  * @since 14
34  * @version 1.0
35  */
36 
37 #ifndef C_INCLUDE_DRAWING_TEXT_RUN_H
38 #define C_INCLUDE_DRAWING_TEXT_RUN_H
39 
40 #include "drawing_text_declaration.h"
41 #include "drawing_types.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 /**
47  * @brief Gets the run glyph indices ,the offset of the index relative to the entire paragraph.
48  *
49  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
50  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
51  * @param start The run of start index.
52  * @param length The run of length, if start and length are set to 0, then get all of the current run.
53  * @return Run of glyph indices array object <b>OH_Drawing_Array</b>.
54  * @since 14
55  */
56 OH_Drawing_Array* OH_Drawing_GetRunStringIndices(OH_Drawing_Run* run, int64_t start, int64_t length);
57 
58 /**
59  * @brief Gets the run glyph indices by index.
60  *
61  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
62  * @param stringIndices the run glyph indices array object <b>OH_Drawing_Array</b>.
63  * @param index The run of glyph index.
64  * @return Run of glyph indices element.
65  * @since 14
66  */
67 uint64_t OH_Drawing_GetRunStringIndicesByIndex(OH_Drawing_Array* stringIndices, size_t index);
68 
69 /**
70  * @brief Releases the memory run glyph indices array.
71  *
72  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
73  * @param stringIndices glyph indices array object <b>OH_Drawing_Array</b>.
74  * @since 14
75  */
76 void OH_Drawing_DestroyRunStringIndices(OH_Drawing_Array* stringIndices);
77 
78 /**
79  * @brief Gets the range run glyph location and length.
80  *
81  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
82  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
83  * @param location The run of glyph location.
84  * @param length The run of glyph length.
85  * @since 14
86  */
87 void OH_Drawing_GetRunStringRange(OH_Drawing_Run* run, uint64_t* location, uint64_t* length);
88 
89 /**
90  * @brief Gets the run typographic bound.
91  *
92  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
93  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
94  * @param ascent The run of ascent.
95  * @param descent The run of descent.
96  * @param leading The run of leading.
97  * @return run typographic width.
98  * @since 14
99  */
100 float OH_Drawing_GetRunTypographicBounds(OH_Drawing_Run* run, float* ascent, float* descent, float* leading);
101 
102 /**
103  * @brief Paints text on the canvas.
104  *
105  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
106  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
107  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
108  * @param x Indicates the x coordinate.
109  * @param y Indicates the y coordinate.
110  * @since 14
111  */
112 void OH_Drawing_RunPaint(OH_Drawing_Canvas* canvas, OH_Drawing_Run* run, double x, double y);
113 
114 /**
115  * @brief Gets the run image bound.
116  *
117  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
118  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
119  * @return The run image bounds to an <b>OH_Drawing_Rect</b> object.
120  * @since 14
121  */
122 OH_Drawing_Rect* OH_Drawing_GetRunImageBounds(OH_Drawing_Run* run);
123 
124  /**
125  * @brief Releases the memory run image bounds pointer.
126  *
127  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
128  * @param rect Run image bounds to an <b>OH_Drawing_Rect</b> object.
129  * @since 14
130  */
131 void OH_Drawing_DestroyRunImageBounds(OH_Drawing_Rect* rect);
132 
133 /**
134  * @brief Gets the range glyph identifier for each character.
135  *
136  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
137  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
138  * @param start The run of start index.
139  * @param length The run of length, if start and length are set to 0, then get all of the current run.
140  * @return Run of glyph array object <b>OH_Drawing_Array</b.
141  * @since 14
142  */
143 OH_Drawing_Array* OH_Drawing_GetRunGlyphs(OH_Drawing_Run* run, int64_t start, int64_t length);
144 
145 /**
146  * @brief Gets the glyph identifier by index.
147  *
148  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
149  * @param glyphs The run of glyph array object <b>OH_Drawing_Array</b>.
150  * @param index The run of glyph index.
151  * @return Run of glyph element.
152  * @since 14
153  * @version 1.0
154  */
155 uint16_t OH_Drawing_GetRunGlyphsByIndex(OH_Drawing_Array* glyphs, size_t index);
156 
157 /**
158  * @brief Releases the memory run glyph array.
159  *
160  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
161  * @param glyphs The run of glyph array object <b>OH_Drawing_Array</b>.
162  * @since 14
163  */
164 void OH_Drawing_DestroyRunGlyphs(OH_Drawing_Array* glyphs);
165 
166 /**
167  * @brief Gets the range glyph position array.
168  *
169  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
170  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
171  * @param start The run of start index.
172  * @param length The run of length, if start and length are set to 0, then get all of the current run.
173  * @return Run of position array object <b>OH_Drawing_Array</b>.
174  * @since 14
175  */
176 OH_Drawing_Array* OH_Drawing_GetRunPositions(OH_Drawing_Run* run, int64_t start, int64_t length);
177 
178 /**
179  * @brief Gets the glyph position by index.
180  *
181  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
182  * @param positions The run of position array object <b>OH_Drawing_Array</b>.
183  * @param index The run of glyph index.
184  * @return Run of glyph position pointer to an <b>OH_Drawing_Point</b> object.
185  * @since 14
186  * @version 1.0
187  */
188 OH_Drawing_Point* OH_Drawing_GetRunPositionsByIndex(OH_Drawing_Array* positions, size_t index);
189 
190 /**
191  * @brief Releases the memory run of position array.
192  *
193  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
194  * @param positions The run of position array object <b>OH_Drawing_Array</b>.
195  * @since 14
196  */
197 void OH_Drawing_DestroyRunPositions(OH_Drawing_Array* positions);
198 
199 /**
200  * @brief Gets the number of glyph.
201  *
202  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
203  * @param run Indicates the pointer to an <b>OH_Drawing_Run</b> object.
204  * @return The number of glyph.
205  * @since 14
206  */
207 uint32_t OH_Drawing_GetRunGlyphCount(OH_Drawing_Run* run);
208 #ifdef __cplusplus
209 }
210 #endif
211 /** @} */
212 #endif // C_INCLUDE_DRAWING_TEXT_RUN_H
213