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