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