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 2D drawing capability. 21 * 22 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 23 * 24 * @since 18 25 * @version 1.0 26 */ 27 28 /** 29 * @file drawing_text_line.h 30 * 31 * @brief Declares functions related to <b>textLine</b> in the drawing module. 32 * 33 * @kit ArkGraphics2D 34 * @library libnative_drawing.so 35 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 36 * @since 18 37 * @version 1.0 38 */ 39 40 #ifndef C_INCLUDE_DRAWING_TEXT_LINE_H 41 #define C_INCLUDE_DRAWING_TEXT_LINE_H 42 43 #include "drawing_text_declaration.h" 44 #include "drawing_types.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Get text line information. 52 * 53 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 54 * @param typography Indicates the pointer to a typography object <b>OH_Drawing_Typography</b>. 55 * @return Indicates the pointer to a text line array object <b>OH_Drawing_Array</b>. 56 * @since 18 57 */ 58 OH_Drawing_Array* OH_Drawing_TypographyGetTextLines(OH_Drawing_Typography* typography); 59 60 /** 61 * @brief Releases the memory occupied by the text line array object <b>OH_Drawing_Array</b>. 62 * 63 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 64 * @param lines Indicates the pointer to the text line array object <b>OH_Drawing_Array</b>. 65 * @since 18 66 * @version 1.0 67 */ 68 void OH_Drawing_DestroyTextLines(OH_Drawing_Array* lines); 69 70 /** 71 * @brief Releases the memory occupied by the text line object <b>OH_Drawing_TextLine</b>. 72 * 73 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 74 * @param line Indicates the pointer to the text line object <b>OH_Drawing_TextLine</b>. 75 * @since 18 76 * @version 1.0 77 */ 78 void OH_Drawing_DestroyTextLine(OH_Drawing_TextLine* line); 79 80 /** 81 * @brief Get the text line object by index. 82 * 83 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 84 * @param lines Indicates the pointer to the text line array object <b>OH_Drawing_Array</b>. 85 * @param index The text line object index. 86 * @return Indicates the pointer to a text line object <b>OH_Drawing_TextLine</b>. 87 * @since 18 88 */ 89 OH_Drawing_TextLine* OH_Drawing_GetTextLineByIndex(OH_Drawing_Array* lines, size_t index); 90 91 /** 92 * @brief Get the count of glyphs. 93 * 94 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 95 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 96 * @return Returns the count of glyphs. 97 * @since 18 98 * @version 1.0 99 */ 100 double OH_Drawing_TextLineGetGlyphCount(OH_Drawing_TextLine* line); 101 102 /** 103 * @brief Get the range of text line. 104 * 105 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 106 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 107 * @param start Indicates the pointer to text line start position. 108 * @param end Indicates the pointer to text line end position. 109 * @since 18 110 * @version 1.0 111 */ 112 void OH_Drawing_TextLineGetTextRange(OH_Drawing_TextLine* line, size_t* start, size_t* end); 113 114 /** 115 * @brief Get the glyph runs array of text line. 116 * 117 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 118 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 119 * @return Indicates the pointer to a glyph runs array object of text line <b>OH_Drawing_Array</b>. 120 * @since 18 121 * @version 1.0 122 */ 123 OH_Drawing_Array* OH_Drawing_TextLineGetGlyphRuns(OH_Drawing_TextLine* line); 124 125 /** 126 * @brief Releases the memory occupied by the run array object <b>OH_Drawing_Array</b>. 127 * 128 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 129 * @param runs Indicates the pointer to the run array object <b>OH_Drawing_Array</b>. 130 * @since 18 131 * @version 1.0 132 */ 133 void OH_Drawing_DestroyRuns(OH_Drawing_Array* runs); 134 135 /** 136 * @brief Get the run object by index. 137 * 138 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 139 * @param runs Indicates the pointer to the run array object <b>OH_Drawing_Array</b>. 140 * @param index The run object index. 141 * @return Indicates the pointer to a run object <b>OH_Drawing_Run</b>. 142 * @since 18 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 18 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 18 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 18 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 18 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 18 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 18 220 */ 221 int32_t OH_Drawing_TextLineGetStringIndexForPosition(OH_Drawing_TextLine* line, OH_Drawing_Point* point); 222 223 /** 224 * @brief Gets the offset of the given string index. 225 * 226 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 227 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 228 * @param index The given string index. 229 * @return Returns the offset for a given string index. 230 * @since 18 231 */ 232 double OH_Drawing_TextLineGetOffsetForStringIndex(OH_Drawing_TextLine* line, int32_t index); 233 234 /** 235 * @brief User-defined callback functions for using offsets and indexes. 236 * 237 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 238 * @param offset Character offset is traversed as an argument to the callback function. 239 * @param index Character index is traversed as an argument to the callback function. 240 * @param leadingEdge Whether the current offset is at the character front, as an argument to the callback function. 241 * @return The return value of the user-defined callback function. 242 * If false is returned, the traversal continues. 243 * If true is returned, the traversal stops. 244 * @since 18 245 * @version 1.0 246 */ 247 typedef bool (*Drawing_CaretOffsetsCallback)(double offset, int32_t index, bool leadingEdge); 248 249 /** 250 * @brief Enumerate caret offset and index in text lines. 251 * 252 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 253 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 254 * @param callback User-defined callback functions, see <b>Drawing_CaretOffsetsCallback</b>. 255 * @since 18 256 */ 257 void OH_Drawing_TextLineEnumerateCaretOffsets(OH_Drawing_TextLine* line, Drawing_CaretOffsetsCallback callback); 258 259 /** 260 * @brief Gets the text offset based on the given alignment factor and alignment width. 261 * 262 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 263 * @param line Indicates the pointer to an <b>OH_Drawing_TextLine</b> object. 264 * @param alignmentFactor The coefficients that text needs to be aligned. 265 * Less than or equal to 0 is left justified, 0.5 is center justified, 266 * and greater than or equal to 1 is right justified. 267 * @param alignmentWidth The width of the text to be aligned. 268 * Returns 0 if it is less than the actual width of the text. 269 * @return Returns the offset of the aligned text. 270 * @since 18 271 * @version 1.0 272 */ 273 double OH_Drawing_TextLineGetAlignmentOffset(OH_Drawing_TextLine* line, double alignmentFactor, double alignmentWidth); 274 275 #ifdef __cplusplus 276 } 277 #endif 278 /** @} */ 279 #endif // C_INCLUDE_DRAWING_TEXT_LINE_H