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 #ifndef C_INCLUDE_DRAWING_TEXT_LINE_H 17 #define C_INCLUDE_DRAWING_TEXT_LINE_H 18 19 /** 20 * @addtogroup Drawing 21 * @{ 22 * 23 * @brief Provides the 2D drawing capability. 24 * 25 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 26 * 27 * @since 14 28 * @version 1.0 29 */ 30 31 /** 32 * @file drawing_text_line.h 33 * 34 * @brief Declares functions related to <b>textLine</b> in the drawing module. 35 * 36 * @since 14 37 * @version 1.0 38 */ 39 40 #include "drawing_text_declaration.h" 41 #include "drawing_types.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Get text line information. 49 * 50 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 51 * @param typography Indicates the pointer to a typography object <b>OH_Drawing_Typography</b>. 52 * @return Indicates the pointer to a text line array object <b>OH_Drawing_Array</b>. 53 * @since 14 54 * @version 1.0 55 */ 56 OH_Drawing_Array* OH_Drawing_TypographyGetTextLines(OH_Drawing_Typography* typography); 57 58 /** 59 * @brief Releases the memory occupied by the text line array object <b>OH_Drawing_Array</b>. 60 * 61 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 62 * @param lines Indicates the pointer to the text line array object <b>OH_Drawing_Array</b>. 63 * @since 14 64 * @version 1.0 65 */ 66 void OH_Drawing_DestroyTextLines(OH_Drawing_Array* lines); 67 68 /** 69 * @brief Releases the memory occupied by the text line object <b>OH_Drawing_TextLine</b>. 70 * 71 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 72 * @param line Indicates the pointer to the text line object <b>OH_Drawing_TextLine</b>. 73 * @since 14 74 * @version 1.0 75 */ 76 void OH_Drawing_DestroyTextLine(OH_Drawing_TextLine* line); 77 78 /** 79 * @brief Get the text line object by index. 80 * 81 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 82 * @param lines Indicates the pointer to the text line array object <b>OH_Drawing_Array</b>. 83 * @param index The text line object index. 84 * @return Indicates the pointer to a text line object <b>OH_Drawing_TextLine</b>. 85 * @since 14 86 * @version 1.0 87 */ 88 OH_Drawing_TextLine* OH_Drawing_GetTextLineByIndex(OH_Drawing_Array* lines, size_t index); 89 90 /** 91 * @brief Get the count of glyphs. 92 * 93 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 94 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 95 * @return Returns the count of glyphs. 96 * @since 14 97 * @version 1.0 98 */ 99 double OH_Drawing_TextLineGetGlyphCount(OH_Drawing_TextLine* line); 100 101 /** 102 * @brief Get the range of text line. 103 * 104 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 105 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 106 * @param start Indicates the pointer to text line start position. 107 * @param end Indicates the pointer to text line end position. 108 * @since 14 109 * @version 1.0 110 */ 111 void OH_Drawing_TextLineGetTextRange(OH_Drawing_TextLine* line, size_t* start, size_t* end); 112 113 /** 114 * @brief Get the glyph runs array of text line. 115 * 116 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 117 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 118 * @return Indicates the pointer to a glyph runs array object of text line <b>OH_Drawing_Array</b>. 119 * @since 14 120 * @version 1.0 121 */ 122 OH_Drawing_Array* OH_Drawing_TextLineGetGlyphRuns(OH_Drawing_TextLine* line); 123 124 /** 125 * @brief Releases the memory occupied by the run array object <b>OH_Drawing_Array</b>. 126 * 127 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 128 * @param runs Indicates the pointer to the run array object <b>OH_Drawing_Array</b>. 129 * @since 14 130 * @version 1.0 131 */ 132 void OH_Drawing_DestroyRuns(OH_Drawing_Array* runs); 133 134 /** 135 * @brief Get the run object by index. 136 * 137 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 138 * @param runs Indicates the pointer to the run array object <b>OH_Drawing_Array</b>. 139 * @param index The run object index. 140 * @return Indicates the pointer to a run object <b>OH_Drawing_Run</b>. 141 * @since 14 142 * @version 1.0 143 */ 144 OH_Drawing_Run* OH_Drawing_GetRunByIndex(OH_Drawing_Array* runs, size_t index); 145 146 /** 147 * @brief Paint the range of text line. 148 * 149 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 150 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 151 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 152 * @param x Represents the X-axis position on the canvas. 153 * @param y Represents the Y-axis position on the canvas. 154 * @since 14 155 * @version 1.0 156 */ 157 void OH_Drawing_TextLinePaint(OH_Drawing_TextLine* line, OH_Drawing_Canvas* canvas, double x, double y); 158 159 /** 160 * @brief Creates a truncated text line object. 161 * 162 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 163 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 164 * @param width Indicates the text line width to set. 165 * @param mode Indicates the ellipsis model to set, EllipsisMode:MIDDLE is not supported. 166 * For details, see the enum <b>OH_Drawing_EllipsisModal</b>. 167 * @param ellipsis Indicates the ellipsis string to set. 168 * @return Returns the pointer to the <b>OH_Drawing_TextLine</b> object created. 169 * @since 14 170 * @version 1.0 171 */ 172 OH_Drawing_TextLine* OH_Drawing_TextLineCreateTruncatedLine(OH_Drawing_TextLine* line, double width, int mode, 173 const char* ellipsis); 174 175 /** 176 * @brief Gets the text line typographic bounds. 177 * 178 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 179 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 180 * @param ascent Indicates the distance that the pointer points to remain above the baseline. 181 * @param descent Indicates the pointer to the distance that remains below the baseline. 182 * @param leading Indicates the pointer to the line Spacing. 183 * @return Returns The total width of the typesetting border. 184 * @since 14 185 * @version 1.0 186 */ 187 double OH_Drawing_TextLineGetTypographicBounds(OH_Drawing_TextLine* line, double* ascent, double* descent, 188 double* leading); 189 190 /** 191 * @brief Gets the text line image bounds. 192 * 193 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 194 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 195 * @return Returns the pointer to the <b>OH_Drawing_Rect</b> struct created. 196 * @since 14 197 * @version 1.0 198 */ 199 OH_Drawing_Rect* OH_Drawing_TextLineGetImageBounds(OH_Drawing_TextLine* line); 200 201 /** 202 * @brief Gets the tail space width. 203 * 204 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 205 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 206 * @return Returns the tail space width. 207 * @since 14 208 * @version 1.0 209 */ 210 double OH_Drawing_TextLineGetTrailingSpaceWidth(OH_Drawing_TextLine* line); 211 212 /** 213 * @brief Gets the string index of the given position. 214 * 215 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 216 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 217 * @param point Indicates the pointer to an <b>OH_Drawing_Point</b> object. 218 * @return Returns the string index for a given position. 219 * @since 14 220 * @version 1.0 221 */ 222 int32_t OH_Drawing_TextLineGetStringIndexForPosition(OH_Drawing_TextLine* line, OH_Drawing_Point* point); 223 224 /** 225 * @brief Gets the offset of the given string index. 226 * 227 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 228 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 229 * @param index The given string index. 230 * @return Returns the offset for a given string index. 231 * @since 14 232 * @version 1.0 233 */ 234 double OH_Drawing_TextLineGetOffsetForStringIndex(OH_Drawing_TextLine* line, int32_t index); 235 236 /** 237 * @brief User-defined callback functions for using offsets and indexes. 238 * 239 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 240 * @param offset Character offset is traversed as an argument to the callback function. 241 * @param index Character index is traversed as an argument to the callback function. 242 * @param leadingEdge Whether the current offset is at the character front, as an argument to the callback function. 243 * @return The return value of the user-defined callback function. 244 * If false is returned, the traversal continues. 245 * If true is returned, the traversal stops. 246 * @since 14 247 * @version 1.0 248 */ 249 typedef bool (*Drawing_CaretOffsetsCallback)(double offset, int32_t index, bool leadingEdge); 250 251 /** 252 * @brief Enumerate caret offset and index in text lines. 253 * 254 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 255 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 256 * @param callback User-defined callback functions, see <b>Drawing_CaretOffsetsCallback</b>. 257 * @since 14 258 */ 259 void OH_Drawing_TextLineEnumerateCaretOffsets(OH_Drawing_TextLine* line, Drawing_CaretOffsetsCallback callback); 260 261 /** 262 * @brief Gets the text offset based on the given alignment factor and alignment width. 263 * 264 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 265 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 266 * @param alignmentFactor The coefficients that text needs to be aligned. 267 * Less than or equal to 0 is left justified, 0.5 is center justified, 268 * and greater than or equal to 1 is right justified. 269 * @param alignmentWidth The width of the text to be aligned. 270 * Returns 0 if it is less than the actual width of the text. 271 * @return Returns the offset of the aligned text. 272 * @since 14 273 * @version 1.0 274 */ 275 double OH_Drawing_TextLineGetAlignmentOffset(OH_Drawing_TextLine* line, double alignmentFactor, double alignmentWidth); 276 277 #ifdef __cplusplus 278 } 279 #endif 280 /** @} */ 281 #endif // C_INCLUDE_DRAWING_TEXT_LINE_H