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