• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 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* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
93  * @param 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* canvas, OH_Drawing_Bitmap* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
104  * @param 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* canvas, const OH_Drawing_Pen* 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 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* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
126  * @param 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* canvas, const OH_Drawing_Brush* 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 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* 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 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* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
159  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
160  * @param 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* canvas, const OH_Drawing_Rect* rect, const OH_Drawing_Brush* 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 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* 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 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* 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 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* canvas, uint32_t saveCount);
197 
198 /**
199  * @brief Draws a line segment.
200  *
201  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
202  * @param 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* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
217  * @param 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* canvas, const OH_Drawing_Path* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
228  * @param pixelMap Indicates the pointer to an <b>OH_Drawing_PixelMap</b> object.
229  * @param src the area of source pixelmap.
230  * @param dst the area of destination canvas.
231  * @param samplingOptions the sampling mode.
232  * @since 12
233  * @version 1.0
234  */
235 void OH_Drawing_CanvasDrawPixelMapRect(OH_Drawing_Canvas* canvas, OH_Drawing_PixelMap* pixelMap,
236     const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions);
237 
238 /**
239  * @brief Fills clipped canvas area with brush.
240  *
241  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
242  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
243  * @param 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* canvas, const OH_Drawing_Brush* brush);
248 
249 /**
250  * @brief Draws region using clip, matrix and paint.
251  *
252  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
253  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
254  * @param 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* canvas, const OH_Drawing_Region* 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 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 point2D Point struct array.
304  * @since 12
305  * @version 1.0
306  */
307 void OH_Drawing_CanvasDrawPoints(OH_Drawing_Canvas* canvas, OH_Drawing_PointMode mode,
308     uint32_t count, const OH_Drawing_Point2D* point2D);
309 
310 /**
311  * @brief Draws a bitmap.
312  *
313  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
314  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
315  * @param 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* canvas, const OH_Drawing_Bitmap* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
328  * @param 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 samplingOptions the sampling mode.
332  * @since 12
333  * @version 1.0
334  */
335 void OH_Drawing_CanvasDrawBitmapRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Bitmap* bitmap,
336     const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions);
337 
338 /**
339  * @brief Draws a rect.
340  *
341  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
342  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
343  * @param 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* canvas, const OH_Drawing_Rect* rect);
348 
349 /**
350  * @brief Draws a circle.
351  *
352  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
353  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
354  * @param 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* canvas, const OH_Drawing_Point* 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 canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
382  * @param 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* canvas, const OH_Drawing_Rect* rect);
387 
388 /**
389  * @brief Draws an arc.
390  *
391  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
392  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
393  * @param 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* canvas,
400     const OH_Drawing_Rect* rect, float startAngle, float sweepAngle);
401 
402 /**
403  * @brief Draws a roundrect.
404  *
405  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
406  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
407  * @param roundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object.
408  * @since 11
409  * @version 1.0
410  */
411 void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* roundRect);
412 
413 /**
414  * @brief Draws a single character.
415  *
416  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
417  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
418  * @param str Indicates the single character encoded in UTF-8.
419  * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object.
420  * @param x Indicates the horizontal offset applied to the single character.
421  * @param y Indicates the vertical offset applied to the single character.
422  * @return Returns the error code.
423  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
424  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of canvas, str
425  *                 and font is nullptr or strlen(str) is 0.
426  * @since 12
427  * @version 1.0
428  */
429 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacter(OH_Drawing_Canvas* canvas, const char* str,
430     const OH_Drawing_Font* font, float x, float y);
431 
432 /**
433  * @brief Draws a textblob.
434  *
435  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
436  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
437  * @param textBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
438  * @param x Indicates the horizontal offset applied to blob.
439  * @param y Indicates the vertical offset applied to blob.
440  * @since 11
441  * @version 1.0
442  */
443 void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas* canvas, const OH_Drawing_TextBlob* textBlob, float x, float y);
444 
445 /**
446  * @brief Enumerates clip op.
447  *
448  * @since 11
449  * @version 1.0
450  */
451 typedef enum {
452     /**
453      * Clip with difference.
454      */
455     DIFFERENCE,
456     /**
457      * Clip with intersection.
458      */
459     INTERSECT,
460 } OH_Drawing_CanvasClipOp;
461 
462 /**
463  * @brief Clip a rect.
464  *
465  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
466  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
467  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
468  * @param clipOp Indicates the operation to apply to clip.
469  * @param doAntiAlias Indicates whether clip operation requires anti-aliased.
470  * @since 11
471  * @version 1.0
472  */
473 void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,
474     OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
475 
476 /**
477  * @brief Clip a round rect.
478  *
479  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
480  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
481  * @param roundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object.
482  * @param clipOp Indicates the operation to apply to clip.
483  * @param doAntiAlias Indicates whether clip operation requires anti-aliased.
484  * @since 12
485  * @version 1.0
486  */
487 void OH_Drawing_CanvasClipRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* roundRect,
488     OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
489 
490 /**
491  * @brief Clip a path.
492  *
493  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
494  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
495  * @param path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
496  * @param clipOp Indicates the operation to apply to clip.
497  * @param doAntiAlias Indicates whether clip operation requires anti-aliased.
498  * @since 11
499  * @version 1.0
500  */
501 void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path,
502     OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
503 
504 /**
505  * @brief Clips a region.
506  *
507  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
508  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
509  * @param region Indicates the pointer to an <b>OH_Drawing_Region</b> object.
510  * @param clipOp To apply to clip.
511  * @return Returns the error code.
512  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
513  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or region is nullptr.
514  * @since 12
515  * @version 1.0
516  */
517 OH_Drawing_ErrorCode OH_Drawing_CanvasClipRegion(OH_Drawing_Canvas* canvas, const OH_Drawing_Region* region,
518     OH_Drawing_CanvasClipOp clipOp);
519 
520 /**
521  * @brief Rotates by degrees. Positive degrees rotates clockwise.
522  *
523  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
524  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
525  * @param degrees Indicates the amount to rotate, in degrees.
526  * @param px Indicates the x-axis value of the point to rotate about.
527  * @param py Indicates the y-axis value of the point to rotate about.
528  * @since 11
529  * @version 1.0
530  */
531 void OH_Drawing_CanvasRotate(OH_Drawing_Canvas* canvas, float degrees, float px, float py);
532 
533 /**
534  * @brief Translates by dx along the x-axis and dy along the y-axis.
535  *
536  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
537  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
538  * @param dx Indicates the distance to translate on x-axis.
539  * @param dy Indicates the distance to translate on y-axis.
540  * @since 11
541  * @version 1.0
542  */
543 void OH_Drawing_CanvasTranslate(OH_Drawing_Canvas* canvas, float dx, float dy);
544 
545 /**
546  * @brief Scales by sx on the x-axis and sy on the y-axis.
547  *
548  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
549  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
550  * @param sx Indicates the amount to scale on x-axis.
551  * @param sy Indicates the amount to scale on y-axis.
552  * @since 11
553  * @version 1.0
554  */
555 void OH_Drawing_CanvasScale(OH_Drawing_Canvas* canvas, float sx, float sy);
556 
557 /**
558  * @brief Skew by sx on the x-axis and sy on the y-axis.
559  *
560  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
561  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
562  * @param sx Indicates the amount to skew on x-axis.
563  * @param sy Indicates the amount to skew on y-axis.
564  * @since 12
565  * @version 1.0
566  */
567 void OH_Drawing_CanvasSkew(OH_Drawing_Canvas* canvas, float sx, float sy);
568 
569 /**
570  * @brief Get the width of a canvas.
571  *
572  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
573  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
574  * @since 12
575  * @version 1.0
576  */
577 int32_t OH_Drawing_CanvasGetWidth(OH_Drawing_Canvas* canvas);
578 
579 /**
580  * @brief Get the height of a canvas.
581  *
582  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
583  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
584  * @since 12
585  * @version 1.0
586  */
587 int32_t OH_Drawing_CanvasGetHeight(OH_Drawing_Canvas* canvas);
588 
589 /**
590  * @brief Get the bounds of clip of a canvas.
591  *
592  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
593  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
594  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
595  * @since 12
596  * @version 1.0
597  */
598 void OH_Drawing_CanvasGetLocalClipBounds(OH_Drawing_Canvas* canvas, OH_Drawing_Rect* rect);
599 
600 /**
601  * @brief Get a 3x3 matrix of the transform from local coordinates to 'device'.
602  *
603  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
604  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
605  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object.
606  * @since 12
607  * @version 1.0
608  */
609 void OH_Drawing_CanvasGetTotalMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix);
610 
611 /**
612  * @brief Use the passed matrix to transforming the geometry, then use existing matrix.
613  *
614  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
615  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
616  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object,
617  * represents the matrix which is passed.
618  * @since 12
619  * @version 1.0
620  */
621 void OH_Drawing_CanvasConcatMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix);
622 
623 /**
624  * @brief Enumerates of shadow flags.
625  *
626  * @since 12
627  * @version 1.0
628  */
629 typedef enum {
630     /**
631      * Use no shadow flags.
632      */
633     SHADOW_FLAGS_NONE,
634     /**
635      * The occluding object is transparent.
636      */
637     SHADOW_FLAGS_TRANSPARENT_OCCLUDER,
638     /**
639      * No need to analyze shadows.
640      */
641     SHADOW_FLAGS_GEOMETRIC_ONLY,
642     /**
643      * Use all shadow flags.
644      */
645     SHADOW_FLAGS_ALL,
646 } OH_Drawing_CanvasShadowFlags;
647 
648 /**
649  * @brief Use circular light to draw an offset spot shadow and outlining ambient shadow for the given path.
650  *
651  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
652  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
653  * @param path Indicates the pointer to an <b>OH_Drawing_Path</b> object, use to generate shadows.
654  * @param planeParams Represents the value of the function which returns Z offset of the occluder from the
655  * canvas based on x and y.
656  * @param devLightPos Represents the position of the light relative to the canvas.
657  * @param lightRadius The radius of the circular light.
658  * @param ambientColor Ambient shadow's color.
659  * @param spotColor Spot shadow's color.
660  * @param flag Indicates the flag to control opaque occluder, shadow, and light position.
661  * @since 12
662  * @version 1.0
663  */
664 void OH_Drawing_CanvasDrawShadow(OH_Drawing_Canvas* canvas, OH_Drawing_Path* path, OH_Drawing_Point3D planeParams,
665     OH_Drawing_Point3D devLightPos, float lightRadius, uint32_t ambientColor, uint32_t spotColor,
666     OH_Drawing_CanvasShadowFlags flag);
667 
668 /**
669  * @brief Clears a canvas by using a specified color.
670  *
671  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
672  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
673  * @param color Indicates the color, which is a 32-bit (ARGB) variable.
674  * @since 8
675  * @version 1.0
676  */
677 void OH_Drawing_CanvasClear(OH_Drawing_Canvas* canvas, uint32_t color);
678 
679 /**
680  * @brief Sets matrix of canvas.
681  *
682  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
683  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
684  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object.
685  * @since 12
686  * @version 1.0
687  */
688 void OH_Drawing_CanvasSetMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix);
689 
690 /**
691  * @brief Reset matrix to the idenmtity matrix, any prior matrix state is overwritten.
692  *
693  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
694  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
695  * @since 12
696  * @version 1.0
697  */
698 void OH_Drawing_CanvasResetMatrix(OH_Drawing_Canvas* canvas);
699 
700 /**
701  * @brief Draws the specified source rectangle of the image onto the canvas,
702  * scaled and translated to the destination rectangle.
703  *
704  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
705  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
706  * @param image Indicates the pointer to an <b>OH_Drawing_Image</b> object.
707  * @param src The area of source image.
708  * @param dst The area of destination canvas.
709  * @param samplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object.
710  * @param srcRectConstraint Constraint type.
711  * @since 12
712  * @version 1.0
713  */
714 void OH_Drawing_CanvasDrawImageRectWithSrc(OH_Drawing_Canvas* canvas, const OH_Drawing_Image* image,
715     const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions,
716     OH_Drawing_SrcRectConstraint srcRectConstraint);
717 
718 /**
719  * @brief Draws the specified source rectangle of the image onto the canvas,
720  * scaled and translated to the destination rectangle.
721  *
722  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
723  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
724  * @param image Indicates the pointer to an <b>OH_Drawing_Image</b> object.
725  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
726  * @param samplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object.
727  * @since 12
728  * @version 1.0
729  */
730 void OH_Drawing_CanvasDrawImageRect(OH_Drawing_Canvas* canvas, OH_Drawing_Image* image,
731     OH_Drawing_Rect* rect, OH_Drawing_SamplingOptions* samplingOptions);
732 
733 /**
734  * @brief Enumerates of vertices flags.
735  *
736  * @since 12
737  * @version 1.0
738  */
739 typedef enum {
740     /**
741      * The vertices are a triangle list.
742      */
743     VERTEX_MODE_TRIANGLES,
744     /**
745      * The vertices are a triangle strip.
746      */
747     VERTEX_MODE_TRIANGLES_STRIP,
748     /**
749      * The vertices are a triangle fan.
750      */
751     VERTEX_MODE_TRIANGLE_FAN,
752 } OH_Drawing_VertexMode;
753 
754 /**
755  * @brief Draw a triangular mesh with vertex descriptions.
756  *
757  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
758  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
759  * @param vertexMmode Draw a set of vertices.
760  * @param vertexCount Vertex count.
761  * @param positions Positions data pointer.
762  * @param texs Texture coordinate data pointer.
763  * @param colors Color data pointer.
764  * @param indexCount Index count.
765  * @param indices Index data pointer.
766  * @param mode Blend mode used for drawing.
767  * @since 12
768  * @version 1.0
769  */
770 void OH_Drawing_CanvasDrawVertices(OH_Drawing_Canvas* canvas, OH_Drawing_VertexMode vertexMmode,
771     int32_t vertexCount, const OH_Drawing_Point2D* positions, const OH_Drawing_Point2D* texs,
772     const uint32_t* colors, int32_t indexCount, const uint16_t* indices, OH_Drawing_BlendMode mode);
773 
774 /**
775  * @brief Read pixels data from canvas.
776  *
777  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
778  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
779  * @param imageInfo width, height, colorType, and alphaType of dstPixels.
780  * @param dstPixels destination pixel storage.
781  * @param dstRowBytes size of one row of pixels.
782  * @param srcX offset into canvas writable pixels on x-axis.
783  * @param srcY offset into canvas writable pixels on y-axis.
784  * @return true if pixels are copied to dstPixels.
785  * @since 12
786  * @version 1.0
787  */
788 bool OH_Drawing_CanvasReadPixels(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo,
789     void* dstPixels, uint32_t dstRowBytes, int32_t srcX, int32_t srcY);
790 
791 /**
792  * @brief Read pixels data to a bitmap from canvas.
793  *
794  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
795  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
796  * @param bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object.
797  * @param srcX offset into canvas writable pixels on x-axis.
798  * @param srcY offset into canvas writable pixels on y-axis.
799  * @return true if pixels are copied to dstBitmap.
800  * @since 12
801  * @version 1.0
802  */
803 bool OH_Drawing_CanvasReadPixelsToBitmap(OH_Drawing_Canvas* canvas,
804     OH_Drawing_Bitmap* bitmap, int32_t srcX, int32_t srcY);
805 
806 /**
807  * @brief Checks whether the drawable area is empty.
808  *
809  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
810  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
811  * @param isClipEmpty Indicates if drawable area is empty.
812  * @return Returns the error code.
813  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
814  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or isClipEmpty is nullptr.
815  * @since 12
816  * @version 1.0
817  */
818 OH_Drawing_ErrorCode OH_Drawing_CanvasIsClipEmpty(OH_Drawing_Canvas* canvas, bool* isClipEmpty);
819 
820 /**
821  * @brief Gets image info of canvas.
822  *
823  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
824  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
825  * @param imageInfo Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object.
826  * @return Returns the error code.
827  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
828  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or imageInfo is nullptr.
829  * @since 12
830  * @version 1.0
831  */
832 OH_Drawing_ErrorCode OH_Drawing_CanvasGetImageInfo(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo);
833 
834 /**
835  * @brief Replay drawing command.
836  *
837  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
838  * @param canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
839  * @param recordCmd Indicates the pointer to an <b>OH_Drawing_RecordCmd</b> object.
840  * @return Returns the error code.
841  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
842  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if canvas or recordCmd is nullptr.
843  * @since 13
844  * @version 1.0
845  */
846 OH_Drawing_ErrorCode OH_Drawing_CanvasDrawRecordCmd(OH_Drawing_Canvas* canvas, OH_Drawing_RecordCmd* recordCmd);
847 #ifdef __cplusplus
848 }
849 #endif
850 /** @} */
851 #endif
852