1 /* 2 * Copyright (c) 2021-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_PEN_H 17 #define C_INCLUDE_DRAWING_PEN_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 8 28 * @version 1.0 29 */ 30 31 /** 32 * @file drawing_pen.h 33 * 34 * @brief Declares functions related to the <b>pen</b> object in the drawing module. 35 * 36 * @kit ArkGraphics2D 37 * @library libnative_drawing.so 38 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 39 * @since 8 40 * @version 1.0 41 */ 42 43 #include "drawing_types.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 * @brief Creates an <b>OH_Drawing_Pen</b> object. 51 * 52 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 53 * @return Returns the pointer to the <b>OH_Drawing_Pen</b> object created. 54 * @since 8 55 * @version 1.0 56 */ 57 OH_Drawing_Pen* OH_Drawing_PenCreate(void); 58 59 /** 60 * @brief Creates an <b>OH_Drawing_Pen</b> copy object. 61 * 62 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 63 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 64 * @return Returns the pointer to the <b>OH_Drawing_Pen</b> object created. 65 * If nullptr is returned, the creation fails. 66 * The possible cause of the failure is that the available memory is empty or a nullptr is passed. 67 * @since 12 68 * @version 1.0 69 */ 70 OH_Drawing_Pen* OH_Drawing_PenCopy(OH_Drawing_Pen*); 71 72 /** 73 * @brief Destroys an <b>OH_Drawing_Pen</b> object and reclaims the memory occupied by the object. 74 * 75 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 76 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 77 * @since 8 78 * @version 1.0 79 */ 80 void OH_Drawing_PenDestroy(OH_Drawing_Pen*); 81 82 /** 83 * @brief Checks whether anti-aliasing is enabled for a pen. If anti-aliasing is enabled, 84 * edges will be drawn with partial transparency. 85 * 86 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 87 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 88 * @return Returns <b>true</b> if anti-aliasing is enabled; returns <b>false</b> otherwise. 89 * @since 8 90 * @version 1.0 91 */ 92 bool OH_Drawing_PenIsAntiAlias(const OH_Drawing_Pen*); 93 94 /** 95 * @brief Enables or disables anti-aliasing for a pen. If anti-aliasing is enabled, 96 * edges will be drawn with partial transparency. 97 * 98 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 99 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 100 * @param bool Specifies whether to enable anti-aliasing. The value <b>true</b> means 101 * to enable anti-aliasing, and <b>false</b> means the opposite. 102 * @since 8 103 * @version 1.0 104 */ 105 void OH_Drawing_PenSetAntiAlias(OH_Drawing_Pen*, bool); 106 107 /** 108 * @brief Obtains the color of a pen. The color is used by the pen to outline a shape. 109 * 110 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 111 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 112 * @return Returns a 32-bit (ARGB) variable that describes the color. 113 * @since 8 114 * @version 1.0 115 */ 116 uint32_t OH_Drawing_PenGetColor(const OH_Drawing_Pen*); 117 118 /** 119 * @brief Sets the color for a pen. The color is used by the pen to outline a shape. 120 * 121 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 122 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 123 * @param color Indicates the color to set, which is a 32-bit (ARGB) variable. 124 * @since 8 125 * @version 1.0 126 */ 127 void OH_Drawing_PenSetColor(OH_Drawing_Pen*, uint32_t color); 128 129 /** 130 * @brief Obtains the alpha of a pen. The alpha is used by the pen to outline a shape. 131 * 132 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 133 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 134 * @return Returns a 8-bit variable that describes the alpha. 135 * @since 11 136 * @version 1.0 137 */ 138 uint8_t OH_Drawing_PenGetAlpha(const OH_Drawing_Pen*); 139 140 /** 141 * @brief Sets the alpha for a pen. The alpha is used by the pen to outline a shape. 142 * 143 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 144 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 145 * @param alpha Indicates the alpha to set, which is a 8-bit variable. 146 * @since 11 147 * @version 1.0 148 */ 149 void OH_Drawing_PenSetAlpha(OH_Drawing_Pen*, uint8_t alpha); 150 151 /** 152 * @brief Obtains the thickness of a pen. This thickness determines the width of the outline of a shape. 153 * 154 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 155 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 156 * @return Returns the thickness. 157 * @since 8 158 * @version 1.0 159 */ 160 float OH_Drawing_PenGetWidth(const OH_Drawing_Pen*); 161 162 /** 163 * @brief Sets the thickness for a pen. This thickness determines the width of the outline of a shape. 164 * 165 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 166 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 167 * @param width Indicates the thickness to set, which is a variable. 168 * @since 8 169 * @version 1.0 170 */ 171 void OH_Drawing_PenSetWidth(OH_Drawing_Pen*, float width); 172 173 /** 174 * @brief Obtains the stroke miter limit of a polyline drawn by a pen. 175 * 176 * When the corner type is bevel, a beveled corner is displayed if the miter limit is exceeded, 177 * and a mitered corner is displayed if the miter limit is not exceeded. 178 * 179 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 180 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 181 * @return Returns the miter limit. 182 * @since 8 183 * @version 1.0 184 */ 185 float OH_Drawing_PenGetMiterLimit(const OH_Drawing_Pen*); 186 187 /** 188 * @brief Sets the stroke miter limit for a polyline drawn by a pen. 189 * 190 * When the corner type is bevel, a beveled corner is displayed if the miter limit is exceeded, 191 * and a mitered corner is displayed if the miter limit is not exceeded. 192 * 193 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 194 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 195 * @param miter Indicates a variable that describes the miter limit. 196 * @since 8 197 * @version 1.0 198 */ 199 void OH_Drawing_PenSetMiterLimit(OH_Drawing_Pen*, float miter); 200 201 /** 202 * @brief Enumerates line cap styles of a pen. The line cap style defines 203 * the style of both ends of a line segment drawn by the pen. 204 * 205 * @since 8 206 * @version 1.0 207 */ 208 typedef enum { 209 /** 210 * There is no cap style. Both ends of the line segment are cut off square. 211 */ 212 LINE_FLAT_CAP, 213 /** 214 * Square cap style. Both ends have a square, the height of which 215 * is half of the width of the line segment, with the same width. 216 */ 217 LINE_SQUARE_CAP, 218 /** 219 * Round cap style. Both ends have a semicircle centered, the diameter of which 220 * is the same as the width of the line segment. 221 */ 222 LINE_ROUND_CAP 223 } OH_Drawing_PenLineCapStyle; 224 225 /** 226 * @brief Obtains the line cap style of a pen. 227 * 228 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 229 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 230 * @return Returns the line cap style. 231 * @since 8 232 * @version 1.0 233 */ 234 OH_Drawing_PenLineCapStyle OH_Drawing_PenGetCap(const OH_Drawing_Pen*); 235 236 /** 237 * @brief Sets the line cap style for a pen. 238 * 239 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 240 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 241 * @param OH_Drawing_PenLineCapStyle Indicates a variable that describes the line cap style. 242 * @since 8 243 * @version 1.0 244 */ 245 void OH_Drawing_PenSetCap(OH_Drawing_Pen*, OH_Drawing_PenLineCapStyle); 246 247 /** 248 * @brief Enumerates pen line join styles. The line join style defines 249 * the shape of the joints of a polyline segment drawn by the pen. 250 * 251 * @since 8 252 * @version 1.0 253 */ 254 typedef enum { 255 /** 256 * Mitered corner. If the angle of a polyline is small, its miter length may be inappropriate. 257 * In this case, you need to use the miter limit to limit the miter length. 258 */ 259 LINE_MITER_JOIN, 260 /** Round corner. */ 261 LINE_ROUND_JOIN, 262 /** Beveled corner. */ 263 LINE_BEVEL_JOIN 264 } OH_Drawing_PenLineJoinStyle; 265 266 /** 267 * @brief Obtains the line join style of a pen. 268 * 269 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 270 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 271 * @return Returns the line join style. 272 * @since 8 273 * @version 1.0 274 */ 275 OH_Drawing_PenLineJoinStyle OH_Drawing_PenGetJoin(const OH_Drawing_Pen*); 276 277 /** 278 * @brief Sets the line join style for a pen. 279 * 280 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 281 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 282 * @param OH_Drawing_PenLineJoinStyle Indicates a variable that describes the line join style. 283 * @since 8 284 * @version 1.0 285 */ 286 void OH_Drawing_PenSetJoin(OH_Drawing_Pen*, OH_Drawing_PenLineJoinStyle); 287 288 /** 289 * @brief Sets the shaderEffect for a pen. 290 * 291 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 292 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 293 * @param OH_Drawing_ShaderEffect Indicates the pointer to an <b>OH_Drawing_ShaderEffect</b> object. 294 * @since 11 295 * @version 1.0 296 */ 297 void OH_Drawing_PenSetShaderEffect(OH_Drawing_Pen*, OH_Drawing_ShaderEffect*); 298 299 /** 300 * @brief Sets the shadowLayer for a pen. 301 * 302 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 303 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 304 * @param OH_Drawing_ShadowLayer Indicates the pointer to an <b>OH_Drawing_ShadowLayer</b> object. 305 * @since 12 306 * @version 1.0 307 */ 308 void OH_Drawing_PenSetShadowLayer(OH_Drawing_Pen*, OH_Drawing_ShadowLayer*); 309 310 /** 311 * @brief Sets the pathEffect for a pen. 312 * 313 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 314 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 315 * @param OH_Drawing_PathEffect Indicates the pointer to an <b>OH_Drawing_PathEffect</b> object. 316 * @since 12 317 * @version 1.0 318 */ 319 void OH_Drawing_PenSetPathEffect(OH_Drawing_Pen*, OH_Drawing_PathEffect*); 320 321 /** 322 * @brief Sets the filter for a pen. 323 * 324 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 325 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 326 * @param OH_Drawing_Filter Indicates the pointer to an <b>OH_Drawing_Filter</b> object. 327 * @since 11 328 * @version 1.0 329 */ 330 void OH_Drawing_PenSetFilter(OH_Drawing_Pen*, OH_Drawing_Filter*); 331 332 /** 333 * @brief Gets the filter from a pen. 334 * 335 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 336 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 337 * @param OH_Drawing_Filter Indicates the pointer to an <b>OH_Drawing_Filter</b> object. 338 * @since 12 339 * @version 1.0 340 */ 341 void OH_Drawing_PenGetFilter(OH_Drawing_Pen*, OH_Drawing_Filter*); 342 343 /** 344 * @brief Sets a blender that implements the specified blendmode enum for a pen. 345 * 346 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 347 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 348 * @param OH_Drawing_BlendMode Indicates the blend mode. 349 * @since 12 350 * @version 1.0 351 */ 352 void OH_Drawing_PenSetBlendMode(OH_Drawing_Pen*, OH_Drawing_BlendMode); 353 354 /** 355 * @brief Gets the filled equivalent of the src path. 356 * 357 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 358 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 359 * @param src Indicates the Path read to create a filled version. 360 * @param dst Indicates the resulting Path. 361 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object that limits the PathEffect area if 362 Pen has PathEffect. 363 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object that tranfomation applied to 364 PathEffect if Pen has PathEffect. 365 * @return Returns true if get successes; false if get fails. 366 * @since 12 367 * @version 1.0 368 */ 369 bool OH_Drawing_PenGetFillPath(OH_Drawing_Pen*, const OH_Drawing_Path* src, OH_Drawing_Path* dst, 370 const OH_Drawing_Rect*, const OH_Drawing_Matrix*); 371 372 /** 373 * @brief Resets all pen contents to their initial values. 374 * 375 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 376 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 377 * @since 12 378 * @version 1.0 379 */ 380 void OH_Drawing_PenReset(OH_Drawing_Pen*); 381 382 #ifdef __cplusplus 383 } 384 #endif 385 /** @} */ 386 #endif 387