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_H 17 #define C_INCLUDE_DRAWING_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_canvas.h 33 * 34 * @brief Declares functions related to the <b>canvas</b> object in the drawing module. 35 * 36 * @since 8 37 * @version 1.0 38 */ 39 40 #include "drawing_error_code.h" 41 #include "drawing_sampling_options.h" 42 #include "drawing_types.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /** 49 * @brief Enumeration defines the constraint type. 50 * 51 * @since 12 52 * @version 1.0 53 */ 54 typedef enum { 55 /** 56 * Using sampling only inside bounds in a slower manner. 57 */ 58 STRICT_SRC_RECT_CONSTRAINT, 59 /** 60 * Using sampling outside bounds in a faster manner. 61 */ 62 FAST_SRC_RECT_CONSTRAINT, 63 } OH_Drawing_SrcRectConstraint; 64 65 /** 66 * @brief Creates an <b>OH_Drawing_Canvas</b> object. 67 * 68 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 69 * @return Returns the pointer to the <b>OH_Drawing_Canvas</b> object created. 70 * @since 8 71 * @version 1.0 72 */ 73 OH_Drawing_Canvas* OH_Drawing_CanvasCreate(void); 74 75 /** 76 * @brief Destroys an <b>OH_Drawing_Canvas</b> object and reclaims the memory occupied by the object. 77 * 78 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 79 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 80 * @since 8 81 * @version 1.0 82 */ 83 void OH_Drawing_CanvasDestroy(OH_Drawing_Canvas*); 84 85 /** 86 * @brief Binds a bitmap to a canvas so that the content drawn on the canvas 87 * is output to the bitmap (this process is called CPU rendering). 88 * 89 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 90 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 91 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 92 * @since 8 93 * @version 1.0 94 */ 95 void OH_Drawing_CanvasBind(OH_Drawing_Canvas*, OH_Drawing_Bitmap*); 96 97 /** 98 * @brief Attaches a pen to a canvas so that the canvas will use the style and color of the pen to outline a shape. 99 * 100 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 101 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 102 * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 103 * @since 8 104 * @version 1.0 105 */ 106 void OH_Drawing_CanvasAttachPen(OH_Drawing_Canvas*, const OH_Drawing_Pen*); 107 108 /** 109 * @brief Detaches the pen from a canvas so that the canvas will not use the style 110 * and color of the pen to outline a shape. 111 * 112 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 113 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 114 * @since 8 115 * @version 1.0 116 */ 117 void OH_Drawing_CanvasDetachPen(OH_Drawing_Canvas*); 118 119 /** 120 * @brief Attaches a brush to a canvas so that the canvas will use the style and color of the brush to fill in a shape. 121 * 122 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 123 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 124 * @param OH_Drawing_Brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 125 * @since 8 126 * @version 1.0 127 */ 128 void OH_Drawing_CanvasAttachBrush(OH_Drawing_Canvas*, const OH_Drawing_Brush*); 129 130 /** 131 * @brief Detaches the brush from a canvas so that the canvas will not use the style 132 * and color of the brush to fill in a shape. 133 * 134 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 135 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 136 * @since 8 137 * @version 1.0 138 */ 139 void OH_Drawing_CanvasDetachBrush(OH_Drawing_Canvas*); 140 141 /** 142 * @brief Saves the current canvas status (canvas matrix) to the top of the stack. 143 * 144 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 145 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 146 * @since 8 147 * @version 1.0 148 */ 149 void OH_Drawing_CanvasSave(OH_Drawing_Canvas*); 150 151 /** 152 * @brief Saves matrix and clip, and allocates a bitmap for subsequent drawing. 153 * Calling restore discards changes to matrix and clip, and draws the bitmap. 154 * 155 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 156 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 157 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 158 * @param OH_Drawing_Brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 159 * @since 12 160 * @version 1.0 161 */ 162 void OH_Drawing_CanvasSaveLayer(OH_Drawing_Canvas*, const OH_Drawing_Rect*, const OH_Drawing_Brush*); 163 164 /** 165 * @brief Restores the canvas status (canvas matrix) saved on the top of the stack. 166 * 167 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 168 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 169 * @since 8 170 * @version 1.0 171 */ 172 void OH_Drawing_CanvasRestore(OH_Drawing_Canvas*); 173 174 /** 175 * @brief Gets the number of the canvas status (canvas matrix) saved in the stack. 176 * 177 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 178 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 179 * @return Returns a 32-bit variable that describes the number of canvas status. 180 * @since 11 181 * @version 1.0 182 */ 183 uint32_t OH_Drawing_CanvasGetSaveCount(OH_Drawing_Canvas*); 184 185 /** 186 * @brief Restores the specific number of the canvas status (canvas matrix) saved in the stack. 187 * 188 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 189 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 190 * @param saveCount Indicates the specific number of canvas status. 191 * @since 11 192 * @version 1.0 193 */ 194 void OH_Drawing_CanvasRestoreToCount(OH_Drawing_Canvas*, uint32_t saveCount); 195 196 /** 197 * @brief Draws a line segment. 198 * 199 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 200 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 201 * @param x1 Indicates the x coordinate of the start point of the line segment. 202 * @param y1 Indicates the y coordinate of the start point of the line segment. 203 * @param x2 Indicates the x coordinate of the end point of the line segment. 204 * @param y2 Indicates the y coordinate of the end point of the line segment. 205 * @since 8 206 * @version 1.0 207 */ 208 void OH_Drawing_CanvasDrawLine(OH_Drawing_Canvas*, float x1, float y1, float x2, float y2); 209 210 /** 211 * @brief Draws a path. 212 * 213 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 214 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 215 * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object. 216 * @since 8 217 * @version 1.0 218 */ 219 void OH_Drawing_CanvasDrawPath(OH_Drawing_Canvas*, const OH_Drawing_Path*); 220 221 /** 222 * @brief Divides the pixelmap into a grid with nine sections: four sides, four corners, and the center. 223 * Draws the specified section of the pixelmap onto the canvas, corners are unmodified or scaled down if they exceed 224 * the destination rectangle, center and four sides are scaled to fit remaining space. 225 * 226 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 227 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 228 * @param pixelMap Indicates the pointer to an <b>OH_Drawing_PixelMap</b> object. 229 * @param center Divides the pixelmap into nine sections: four sides, four corners, and the center. 230 * @param dst The area of destination canvas. 231 * @param mode Filter mode. 232 * @return Returns the error code. 233 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 234 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of canvas, pixelMap 235 * and dst is nullptr. 236 * @since 16 237 * @version 1.0 238 */ 239 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapNine(OH_Drawing_Canvas* canvas, OH_Drawing_PixelMap* pixelMap, 240 const OH_Drawing_Rect* center, const OH_Drawing_Rect* dst, OH_Drawing_FilterMode mode); 241 242 /** 243 * @brief Draw the specified area of the Media::PixelMap to the specified area of the canvas. 244 * 245 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 246 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 247 * @param OH_Drawing_PixelMap Indicates the pointer to an <b>OH_Drawing_PixelMap</b> object. 248 * @param src the area of source pixelmap. 249 * @param dst the area of destination canvas. 250 * @param OH_Drawing_SamplingOptions the sampling mode. 251 * @since 12 252 * @version 1.0 253 */ 254 void OH_Drawing_CanvasDrawPixelMapRect(OH_Drawing_Canvas*, OH_Drawing_PixelMap*, const OH_Drawing_Rect* src, 255 const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions*); 256 257 /** 258 * @brief Fills clipped canvas area with brush. 259 * 260 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 261 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 262 * @param OH_Drawing_Brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 263 * @since 12 264 * @version 1.0 265 */ 266 void OH_Drawing_CanvasDrawBackground(OH_Drawing_Canvas*, const OH_Drawing_Brush*); 267 268 /** 269 * @brief Draws region using clip, matrix and paint. 270 * 271 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 272 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 273 * @param OH_Drawing_Region Indicates the pointer to an <b>OH_Drawing_Region</b> object. 274 * @since 12 275 * @version 1.0 276 */ 277 void OH_Drawing_CanvasDrawRegion(OH_Drawing_Canvas*, const OH_Drawing_Region*); 278 279 /** 280 * @brief Enumerates of scale to fit flags, selects if an array of points are drawn as discrete points, as lines, 281 * or as an open polygon. 282 * 283 * @since 12 284 * @version 1.0 285 */ 286 typedef enum { 287 /** 288 * Draw each point separately. 289 */ 290 POINT_MODE_POINTS, 291 /** 292 * Draw each pair of points as a line segment. 293 */ 294 POINT_MODE_LINES, 295 /** 296 * Draw the array of points as a open polygon. 297 */ 298 POINT_MODE_POLYGON, 299 } OH_Drawing_PointMode; 300 301 /** 302 * @brief Draws a point. 303 * 304 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 305 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 306 * @param point Indicates the pointer to an <b>OH_Drawing_Point</b> object. 307 * @return Returns the error code. 308 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 309 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or point is nullptr. 310 * @since 12 311 * @version 1.0 312 */ 313 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPoint(OH_Drawing_Canvas* canvas, const OH_Drawing_Point2D* point); 314 315 /** 316 * @brief Draws point array as separate point, line segment or open polygon according to given point mode. 317 * 318 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 319 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 320 * @param mode Draw points enum. 321 * @param count The point count. 322 * @param OH_Drawing_Point2D Point struct array. 323 * @since 12 324 * @version 1.0 325 */ 326 void OH_Drawing_CanvasDrawPoints(OH_Drawing_Canvas*, OH_Drawing_PointMode mode, 327 uint32_t count, const OH_Drawing_Point2D*); 328 329 /** 330 * @brief Draws a bitmap. 331 * 332 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 333 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 334 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 335 * @param left Indicates the left position of the <b>OH_Drawing_Bitmap</b>. 336 * @param top Indicates the top position of the <b>OH_Drawing_Bitmap</b>. 337 * @since 11 338 * @version 1.0 339 */ 340 void OH_Drawing_CanvasDrawBitmap(OH_Drawing_Canvas*, const OH_Drawing_Bitmap*, float left, float top); 341 342 /** 343 * @brief Draw the specified area of the bitmap to the specified area of the canvas. 344 * 345 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 346 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 347 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 348 * @param src the area of source bitmap, can be nullptr. 349 * @param dst the area of destination canvas. 350 * @param OH_Drawing_SamplingOptions the sampling mode. 351 * @since 12 352 * @version 1.0 353 */ 354 void OH_Drawing_CanvasDrawBitmapRect(OH_Drawing_Canvas*, const OH_Drawing_Bitmap*, const OH_Drawing_Rect* src, 355 const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions*); 356 357 /** 358 * @brief Draws a rect. 359 * 360 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 361 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 362 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 363 * @since 11 364 * @version 1.0 365 */ 366 void OH_Drawing_CanvasDrawRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*); 367 368 /** 369 * @brief Draws a circle. 370 * 371 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 372 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 373 * @param OH_Drawing_Point Indicates the pointer to an <b>OH_Drawing_Point</b> object. 374 * @param radius Indicates the radius of the circle. 375 * @since 11 376 * @version 1.0 377 */ 378 void OH_Drawing_CanvasDrawCircle(OH_Drawing_Canvas*, const OH_Drawing_Point*, float radius); 379 380 /** 381 * @brief Fills the entire canvas with the specified color and blend mode. 382 * 383 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 384 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 385 * @param color Indicates the color, which is a 32-bit variable. 386 * @param blendMode Indicates the blend mode. 387 * @return Returns the error code. 388 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 389 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas is nullptr. 390 * @since 12 391 * @version 1.0 392 */ 393 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawColor(OH_Drawing_Canvas* canvas, uint32_t color, 394 OH_Drawing_BlendMode blendMode); 395 396 /** 397 * @brief Draws an oval. 398 * 399 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 400 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 401 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 402 * @since 11 403 * @version 1.0 404 */ 405 void OH_Drawing_CanvasDrawOval(OH_Drawing_Canvas*, const OH_Drawing_Rect*); 406 407 /** 408 * @brief Draws an arc. 409 * 410 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 411 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 412 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 413 * @param startAngle Indicates the startAngle of the arc. 414 * @param sweepAngle Indicates the sweepAngle of the arc. 415 * @since 11 416 * @version 1.0 417 */ 418 void OH_Drawing_CanvasDrawArc(OH_Drawing_Canvas*, const OH_Drawing_Rect*, float startAngle, float sweepAngle); 419 420 /** 421 * @brief Draws an arc with use center. 422 * 423 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 424 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 425 * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 426 * @param startAngle Indicates the startAngle of the arc. 427 * @param sweepAngle Indicates the sweepAngle of the arc. 428 * @param useCenter If true, include the center of the oval in the arc, and close it if it is being stroked. 429 * @return Returns the error code. 430 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 431 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or rect is nullptr. 432 * @since 16 433 * @version 1.0 434 */ 435 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawArcWithCenter(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect, 436 float startAngle, float sweepAngle, bool useCenter); 437 438 439 /** 440 * @brief Draws a roundrect. 441 * 442 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 443 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 444 * @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object. 445 * @since 11 446 * @version 1.0 447 */ 448 void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas*, const OH_Drawing_RoundRect*); 449 450 /** 451 * @brief Draw two nested rounded rectangles. 452 * 453 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 454 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 455 * @param outer Rounded rectangle object, representing the outer rounded rectangle boundary. 456 * @param inner Rounded rectangle object, representing the internal rounded rectangle boundary. 457 * @return Returns the error code. 458 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 459 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of canvas, outer 460 * and inner is nullptr. 461 * @since 16 462 * @version 1.0 463 */ 464 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawNestedRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* outer, 465 const OH_Drawing_RoundRect* inner); 466 467 /** 468 * @brief Draws a single character. 469 * 470 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 471 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 472 * @param str Indicates the single character encoded in UTF-8. 473 * @param OH_Drawing_Font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 474 * @param x Indicates the horizontal offset applied to the single character. 475 * @param y Indicates the vertical offset applied to the single character. 476 * @return Returns the error code. 477 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 478 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of canvas, str 479 * and font is nullptr or strlen(str) is 0. 480 * @since 12 481 * @version 1.0 482 */ 483 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacter(OH_Drawing_Canvas* canvas, const char* str, 484 const OH_Drawing_Font* font, float x, float y); 485 486 /** 487 * @brief Draws a textblob. 488 * 489 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 490 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 491 * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object. 492 * @param x Indicates the horizontal offset applied to blob. 493 * @param y Indicates the vertical offset applied to blob. 494 * @since 11 495 * @version 1.0 496 */ 497 void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas*, const OH_Drawing_TextBlob*, float x, float y); 498 499 /** 500 * @brief Enumerates clip op. 501 * 502 * @since 11 503 * @version 1.0 504 */ 505 typedef enum { 506 /** 507 * Clip with difference. 508 */ 509 DIFFERENCE, 510 /** 511 * Clip with intersection. 512 */ 513 INTERSECT, 514 } OH_Drawing_CanvasClipOp; 515 516 /** 517 * @brief Clip a rect. 518 * 519 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 520 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 521 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 522 * @param clipOp Indicates the operation to apply to clip. 523 * @param doAntiAlias Indicates whether clip operation requires anti-aliased. 524 * @since 11 525 * @version 1.0 526 */ 527 void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*, 528 OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias); 529 530 /** 531 * @brief Clip a round rect. 532 * 533 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 534 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 535 * @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object. 536 * @param clipOp Indicates the operation to apply to clip. 537 * @param doAntiAlias Indicates whether clip operation requires anti-aliased. 538 * @since 12 539 * @version 1.0 540 */ 541 void OH_Drawing_CanvasClipRoundRect(OH_Drawing_Canvas*, const OH_Drawing_RoundRect*, 542 OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias); 543 544 /** 545 * @brief Clip a path. 546 * 547 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 548 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 549 * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object. 550 * @param clipOp Indicates the operation to apply to clip. 551 * @param doAntiAlias Indicates whether clip operation requires anti-aliased. 552 * @since 11 553 * @version 1.0 554 */ 555 void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas*, const OH_Drawing_Path*, 556 OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias); 557 558 /** 559 * @brief Clips a region. 560 * 561 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 562 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 563 * @param region Indicates the pointer to an <b>OH_Drawing_Region</b> object. 564 * @param clipOp To apply to clip. 565 * @return Returns the error code. 566 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 567 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or region is nullptr. 568 * @since 12 569 * @version 1.0 570 */ 571 OH_Drawing_ErrorCode OH_Drawing_CanvasClipRegion(OH_Drawing_Canvas* canvas, const OH_Drawing_Region* region, 572 OH_Drawing_CanvasClipOp clipOp); 573 574 /** 575 * @brief Rotates by degrees. Positive degrees rotates clockwise. 576 * 577 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 578 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 579 * @param degrees Indicates the amount to rotate, in degrees. 580 * @param px Indicates the x-axis value of the point to rotate about. 581 * @param py Indicates the y-axis value of the point to rotate about. 582 * @since 11 583 * @version 1.0 584 */ 585 void OH_Drawing_CanvasRotate(OH_Drawing_Canvas*, float degrees, float px, float py); 586 587 /** 588 * @brief Translates by dx along the x-axis and dy along the y-axis. 589 * 590 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 591 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 592 * @param dx Indicates the distance to translate on x-axis. 593 * @param dy Indicates the distance to translate on y-axis. 594 * @since 11 595 * @version 1.0 596 */ 597 void OH_Drawing_CanvasTranslate(OH_Drawing_Canvas*, float dx, float dy); 598 599 /** 600 * @brief Scales by sx on the x-axis and sy on the y-axis. 601 * 602 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 603 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 604 * @param sx Indicates the amount to scale on x-axis. 605 * @param sy Indicates the amount to scale on y-axis. 606 * @since 11 607 * @version 1.0 608 */ 609 void OH_Drawing_CanvasScale(OH_Drawing_Canvas*, float sx, float sy); 610 611 /** 612 * @brief Skew by sx on the x-axis and sy on the y-axis. 613 * 614 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 615 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 616 * @param sx Indicates the amount to skew on x-axis. 617 * @param sy Indicates the amount to skew on y-axis. 618 * @since 12 619 * @version 1.0 620 */ 621 void OH_Drawing_CanvasSkew(OH_Drawing_Canvas*, float sx, float sy); 622 623 /** 624 * @brief Get the width of a canvas. 625 * 626 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 627 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 628 * @since 12 629 * @version 1.0 630 */ 631 int32_t OH_Drawing_CanvasGetWidth(OH_Drawing_Canvas*); 632 633 /** 634 * @brief Get the height of a canvas. 635 * 636 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 637 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 638 * @since 12 639 * @version 1.0 640 */ 641 int32_t OH_Drawing_CanvasGetHeight(OH_Drawing_Canvas*); 642 643 /** 644 * @brief Get the bounds of clip of a canvas. 645 * 646 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 647 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 648 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 649 * @since 12 650 * @version 1.0 651 */ 652 void OH_Drawing_CanvasGetLocalClipBounds(OH_Drawing_Canvas*, OH_Drawing_Rect*); 653 654 /** 655 * @brief Get a 3x3 matrix of the transform from local coordinates to 'device'. 656 * 657 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 658 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 659 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 660 * @since 12 661 * @version 1.0 662 */ 663 void OH_Drawing_CanvasGetTotalMatrix(OH_Drawing_Canvas*, OH_Drawing_Matrix*); 664 665 /** 666 * @brief Use the passed matrix to transforming the geometry, then use existing matrix. 667 * 668 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 669 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 670 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 671 * represents the matrix which is passed. 672 * @since 12 673 * @version 1.0 674 */ 675 void OH_Drawing_CanvasConcatMatrix(OH_Drawing_Canvas*, OH_Drawing_Matrix*); 676 677 /** 678 * @brief Enumerates of shadow flags. 679 * 680 * @since 12 681 * @version 1.0 682 */ 683 typedef enum { 684 /** 685 * Use no shadow flags. 686 */ 687 SHADOW_FLAGS_NONE, 688 /** 689 * The occluding object is transparent. 690 */ 691 SHADOW_FLAGS_TRANSPARENT_OCCLUDER, 692 /** 693 * No need to analyze shadows. 694 */ 695 SHADOW_FLAGS_GEOMETRIC_ONLY, 696 /** 697 * Use all shadow flags. 698 */ 699 SHADOW_FLAGS_ALL, 700 } OH_Drawing_CanvasShadowFlags; 701 702 /** 703 * @brief Use circular light to draw an offset spot shadow and outlining ambient shadow for the given path. 704 * 705 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 706 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 707 * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object, use to generate shadows. 708 * @param planeParams Represents the value of the function which returns Z offset of the occluder from the 709 * canvas based on x and y. 710 * @param devLightPos Represents the position of the light relative to the canvas. 711 * @param lightRadius The radius of the circular light. 712 * @param ambientColor Ambient shadow's color. 713 * @param spotColor Spot shadow's color. 714 * @param flag Indicates the flag to control opaque occluder, shadow, and light position. 715 * @since 12 716 * @version 1.0 717 */ 718 void OH_Drawing_CanvasDrawShadow(OH_Drawing_Canvas*, OH_Drawing_Path*, OH_Drawing_Point3D planeParams, 719 OH_Drawing_Point3D devLightPos, float lightRadius, uint32_t ambientColor, uint32_t spotColor, 720 OH_Drawing_CanvasShadowFlags flag); 721 722 /** 723 * @brief Clears a canvas by using a specified color. 724 * 725 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 726 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 727 * @param color Indicates the color, which is a 32-bit (ARGB) variable. 728 * @since 8 729 * @version 1.0 730 */ 731 void OH_Drawing_CanvasClear(OH_Drawing_Canvas*, uint32_t color); 732 733 /** 734 * @brief Sets matrix of canvas. 735 * 736 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 737 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 738 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 739 * @since 12 740 * @version 1.0 741 */ 742 void OH_Drawing_CanvasSetMatrix(OH_Drawing_Canvas*, OH_Drawing_Matrix*); 743 744 /** 745 * @brief Reset matrix to the idenmtity matrix, any prior matrix state is overwritten. 746 * 747 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 748 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 749 * @since 12 750 * @version 1.0 751 */ 752 void OH_Drawing_CanvasResetMatrix(OH_Drawing_Canvas*); 753 754 /** 755 * @brief Draws the specified source rectangle of the image onto the canvas, 756 * scaled and translated to the destination rectangle. 757 * 758 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 759 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 760 * @param OH_Drawing_Image Indicates the pointer to an <b>OH_Drawing_Image</b> object. 761 * @param src The area of source image. 762 * @param dst The area of destination canvas. 763 * @param OH_Drawing_SamplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object. 764 * @param OH_Drawing_SrcRectConstraint Constraint type. 765 * @since 12 766 * @version 1.0 767 */ 768 void OH_Drawing_CanvasDrawImageRectWithSrc(OH_Drawing_Canvas*, const OH_Drawing_Image*, 769 const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions*, 770 OH_Drawing_SrcRectConstraint); 771 772 /** 773 * @brief Draws the specified source rectangle of the image onto the canvas, 774 * scaled and translated to the destination rectangle. 775 * 776 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 777 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 778 * @param OH_Drawing_Image Indicates the pointer to an <b>OH_Drawing_Image</b> object. 779 * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 780 * @param OH_Drawing_SamplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object. 781 * @since 12 782 * @version 1.0 783 */ 784 void OH_Drawing_CanvasDrawImageRect(OH_Drawing_Canvas*, OH_Drawing_Image*, 785 OH_Drawing_Rect* dst, OH_Drawing_SamplingOptions*); 786 787 /** 788 * @brief Enumerates of vertices flags. 789 * 790 * @since 12 791 * @version 1.0 792 */ 793 typedef enum { 794 /** 795 * The vertices are a triangle list. 796 */ 797 VERTEX_MODE_TRIANGLES, 798 /** 799 * The vertices are a triangle strip. 800 */ 801 VERTEX_MODE_TRIANGLES_STRIP, 802 /** 803 * The vertices are a triangle fan. 804 */ 805 VERTEX_MODE_TRIANGLE_FAN, 806 } OH_Drawing_VertexMode; 807 808 /** 809 * @brief Draw a triangular mesh with vertex descriptions. 810 * 811 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 812 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 813 * @param vertexMmode Draw a set of vertices. 814 * @param vertexCount Vertex count. 815 * @param positions Positions data pointer. 816 * @param texs Texture coordinate data pointer. 817 * @param colors Color data pointer. 818 * @param indexCount Index count. 819 * @param indices Index data pointer. 820 * @since 12 821 * @version 1.0 822 */ 823 void OH_Drawing_CanvasDrawVertices(OH_Drawing_Canvas*, OH_Drawing_VertexMode vertexMmode, 824 int32_t vertexCount, const OH_Drawing_Point2D* positions, const OH_Drawing_Point2D* texs, 825 const uint32_t* colors, int32_t indexCount, const uint16_t* indices, OH_Drawing_BlendMode mode); 826 827 /** 828 * @brief Read pixels data from canvas. 829 * 830 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 831 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 832 * @param OH_Drawing_Image_Info width, height, colorType, and alphaType of dstPixels. 833 * @param dstPixels destination pixel storage. 834 * @param dstRowBytes size of one row of pixels. 835 * @param srcX offset into canvas writable pixels on x-axis. 836 * @param srcY offset into canvas writable pixels on y-axis. 837 * @return true if pixels are copied to dstPixels. 838 * @since 12 839 * @version 1.0 840 */ 841 bool OH_Drawing_CanvasReadPixels(OH_Drawing_Canvas*, OH_Drawing_Image_Info*, 842 void* dstPixels, uint32_t dstRowBytes, int32_t srcX, int32_t srcY); 843 844 /** 845 * @brief Read pixels data to a bitmap from canvas. 846 * 847 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 848 * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 849 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 850 * @param srcX offset into canvas writable pixels on x-axis. 851 * @param srcY offset into canvas writable pixels on y-axis. 852 * @return true if pixels are copied to dstBitmap. 853 * @since 12 854 * @version 1.0 855 */ 856 bool OH_Drawing_CanvasReadPixelsToBitmap(OH_Drawing_Canvas*, OH_Drawing_Bitmap*, int32_t srcX, int32_t srcY); 857 858 /** 859 * @brief Checks whether the drawable area is empty. 860 * 861 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 862 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 863 * @param isClipEmpty Indicates if drawable area is empty. 864 * @return Returns the error code. 865 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 866 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or isClipEmpty is nullptr. 867 * @since 12 868 * @version 1.0 869 */ 870 OH_Drawing_ErrorCode OH_Drawing_CanvasIsClipEmpty(OH_Drawing_Canvas* canvas, bool* isClipEmpty); 871 872 /** 873 * @brief Gets image info of canvas. 874 * 875 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 876 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 877 * @param imageInfo Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 878 * @return Returns the error code. 879 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 880 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or imageInfo is nullptr. 881 * @since 12 882 * @version 1.0 883 */ 884 OH_Drawing_ErrorCode OH_Drawing_CanvasGetImageInfo(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo); 885 886 /** 887 * @brief Replay drawing command. 888 * 889 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 890 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 891 * @param recordCmd Indicates the pointer to an <b>OH_Drawing_RecordCmd</b> object. 892 * @return Returns the error code. 893 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 894 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or recordCmd is nullptr. 895 * @since 13 896 * @version 1.0 897 */ 898 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawRecordCmd(OH_Drawing_Canvas* canvas, OH_Drawing_RecordCmd* recordCmd); 899 900 /** 901 * @brief Checks if the path has been cut off. 902 * 903 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 904 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 905 * @param path Indicates the pointer to an <b>OH_Drawing_Paht</b> object. 906 * @param quickReject Indicates if the path has been cut off. 907 * @return Returns the error code. 908 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 909 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or path is nullptr, 910 * or quickReject is nullptr. 911 * @since 16 912 * @version 1.0 913 */ 914 OH_Drawing_ErrorCode OH_Drawing_CanvasQuickRejectPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path, 915 bool* quickReject); 916 917 /** 918 * @brief Checks if the rect has been cut off. 919 * 920 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 921 * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object. 922 * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object. 923 * @param quickReject Indicates if the rect has been cut off. 924 * @return Returns the error code. 925 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 926 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or rect is nullptr, 927 * or quickReject is nullptr. 928 * @since 16 929 * @version 1.0 930 */ 931 OH_Drawing_ErrorCode OH_Drawing_CanvasQuickRejectRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect, 932 bool* quickReject); 933 #ifdef __cplusplus 934 } 935 #endif 936 /** @} */ 937 #endif 938