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 * @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 Creates an <b>OH_Drawing_TextBlobBuilder</b> object. 48 * 49 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 50 * @return Returns the pointer to the <b>OH_Drawing_TextBlobBuilder</b> object created. 51 * @since 11 52 * @version 1.0 53 */ 54 OH_Drawing_TextBlobBuilder* OH_Drawing_TextBlobBuilderCreate(void); 55 56 /** 57 * @brief Creates an <b>OH_Drawing_TextBlob</b> object from text. 58 * 59 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 60 * @param text Indicates the the pointer to text. 61 * @param byteLength Indicates the text length. 62 * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 63 * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object. 64 * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created. 65 * @since 12 66 * @version 1.0 67 */ 68 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromText(const void* text, size_t byteLength, 69 const OH_Drawing_Font*, OH_Drawing_TextEncoding); 70 71 /** 72 * @brief Creates an <b>OH_Drawing_TextBlob</b> object from pos text. 73 * 74 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 75 * @param text Indicates the the pointer to text. 76 * @param byteLength Indicates the text length. 77 * @param OH_Drawing_Point2D Indicates the pointer to an <b>OH_Drawing_Point2D</b> array object. 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_TextBlobCreateFromPosText(const void* text, size_t byteLength, 85 OH_Drawing_Point2D*, 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 str Indicates the the pointer to text. 92 * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 93 * @param OH_Drawing_TextEncoding Indicates the pointer to an <b>OH_Drawing_TextEncoding</b> object. 94 * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object created. 95 * @since 12 96 * @version 1.0 97 */ 98 OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromString(const char* str, 99 const OH_Drawing_Font*, OH_Drawing_TextEncoding); 100 101 /** 102 * @brief Gets the bounds of textblob, assigned to the pointer to an <b>OH_Drawing_Rect</b> object. 103 * 104 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 105 * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object. 106 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 107 * @since 12 108 * @version 1.0 109 */ 110 void OH_Drawing_TextBlobGetBounds(OH_Drawing_TextBlob*, OH_Drawing_Rect*); 111 112 /** 113 * @brief Gets a non-zero value unique among all <b>OH_Drawing_TextBlob</b> objects. 114 * 115 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 116 * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object. 117 * @return Returns identifier for the <b>OH_Drawing_TextBlob</b> object. 118 * @since 12 119 * @version 1.0 120 */ 121 uint32_t OH_Drawing_TextBlobUniqueID(const OH_Drawing_TextBlob*); 122 123 /** 124 * @brief Defines a run, supplies storage for glyphs and positions. 125 * 126 * @since 11 127 * @version 1.0 128 */ 129 typedef struct { 130 /** storage for glyph indexes in run */ 131 uint16_t* glyphs; 132 /** storage for glyph positions in run */ 133 float* pos; 134 /** storage for text UTF-8 code units in run */ 135 char* utf8text; 136 /** storage for glyph clusters (index of UTF-8 code unit) */ 137 uint32_t* clusters; 138 } OH_Drawing_RunBuffer; 139 140 /** 141 * @brief Alloc run with storage for glyphs and positions. The returned pointer does not need to be managed 142 * by the caller and is forbidden to be used after OH_Drawing_TextBlobBuilderMake is called. 143 * 144 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 145 * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object. 146 * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 147 * @param count Indicates the number of glyphs. 148 * @param OH_Drawing_Rect Indicates the optional run bounding box. 149 * @since 11 150 * @version 1.0 151 */ 152 const OH_Drawing_RunBuffer* OH_Drawing_TextBlobBuilderAllocRunPos(OH_Drawing_TextBlobBuilder*, const OH_Drawing_Font*, 153 int32_t count, const OH_Drawing_Rect*); 154 155 /** 156 * @brief Make an <b>OH_Drawing_TextBlob</b> from <b>OH_Drawing_TextBlobBuilder</b>. 157 * 158 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 159 * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object. 160 * @return Returns the pointer to the <b>OH_Drawing_TextBlob</b> object. 161 * @since 11 162 * @version 1.0 163 */ 164 OH_Drawing_TextBlob* OH_Drawing_TextBlobBuilderMake(OH_Drawing_TextBlobBuilder*); 165 166 /** 167 * @brief Destroys an <b>OH_Drawing_TextBlob</b> object and reclaims the memory occupied by the object. 168 * 169 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 170 * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object. 171 * @since 11 172 * @version 1.0 173 */ 174 void OH_Drawing_TextBlobDestroy(OH_Drawing_TextBlob*); 175 176 /** 177 * @brief Destroys an <b>OH_Drawing_TextBlobBuilder</b> object and reclaims the memory occupied by the object. 178 * 179 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 180 * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an <b>OH_Drawing_TextBlobBuilder</b> object. 181 * @since 11 182 * @version 1.0 183 */ 184 void OH_Drawing_TextBlobBuilderDestroy(OH_Drawing_TextBlobBuilder*); 185 186 #ifdef __cplusplus 187 } 188 #endif 189 /** @} */ 190 #endif 191