diff --git a/graphic/graphic_2d/native_drawing/BUILD.gn b/graphic/graphic_2d/native_drawing/BUILD.gn index 499a374c24d51cc02d688deceb9547af85cc701c..8f112ad0d58ea5d1326029cf816e57889bdec55a 100644 --- a/graphic/graphic_2d/native_drawing/BUILD.gn +++ b/graphic/graphic_2d/native_drawing/BUILD.gn @@ -21,11 +21,22 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_brush.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_canvas.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_color.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_color_filter.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_filter.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_font.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_font_collection.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_mask_filter.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_matrix.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_path.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_pen.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_point.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_rect.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_round_rect.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_shader_effect.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_blob.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_declaration.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_typography.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_typeface.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_types.h", ] } @@ -40,11 +51,22 @@ ohos_ndk_library("libnative_drawing_ndk") { "native_drawing/drawing_brush.h", "native_drawing/drawing_canvas.h", "native_drawing/drawing_color.h", + "native_drawing/drawing_color_filter.h", + "native_drawing/drawing_filter.h", + "native_drawing/drawing_font.h", "native_drawing/drawing_font_collection.h", + "native_drawing/drawing_mask_filter.h", + "native_drawing/drawing_matrix.h", "native_drawing/drawing_path.h", "native_drawing/drawing_pen.h", + "native_drawing/drawing_point.h", + "native_drawing/drawing_rect.h", + "native_drawing/drawing_round_rect.h", + "native_drawing/drawing_shader_effect.h", + "native_drawing/drawing_text_blob.h", "native_drawing/drawing_text_declaration.h", "native_drawing/drawing_text_typography.h", + "native_drawing/drawing_typeface.h", "native_drawing/drawing_types.h", ] } diff --git a/graphic/graphic_2d/native_drawing/drawing_brush.h b/graphic/graphic_2d/native_drawing/drawing_brush.h index bee8f403fb952a94f9240074f68e1e437d04be9d..215a3ee3966e91b31b21204c161577cf408682de 100644 --- a/graphic/graphic_2d/native_drawing/drawing_brush.h +++ b/graphic/graphic_2d/native_drawing/drawing_brush.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -110,6 +110,50 @@ uint32_t OH_Drawing_BrushGetColor(const OH_Drawing_Brush*); */ void OH_Drawing_BrushSetColor(OH_Drawing_Brush*, uint32_t color); +/** + * @brief Obtains the alpha of a brush. The alpha is used by the brush to fill in a shape. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Brush Indicates the pointer to an OH_Drawing_Brush object. + * @return Returns a 8-bit variable that describes the alpha. + * @since 11 + * @version 1.0 + */ +uint8_t OH_Drawing_BrushGetAlpha(const OH_Drawing_Brush*); + +/** + * @brief Sets the alpha for a brush. The alpha will be used by the brush to fill in a shape. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Brush Indicates the pointer to an OH_Drawing_Brush object. + * @param alpha Indicates the alpha to set, which is a 8-bit variable. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_BrushSetAlpha(OH_Drawing_Brush*, uint8_t alpha); + +/** + * @brief Sets the shaderEffect for a brush. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Brush Indicates the pointer to an OH_Drawing_Brush object. + * @param OH_Drawing_ShaderEffect Indicates the pointer to an OH_Drawing_ShaderEffect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_BrushSetShaderEffect(OH_Drawing_Brush*, OH_Drawing_ShaderEffect*); + +/** + * @brief Sets the filter for a brush. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Brush Indicates the pointer to an OH_Drawing_Brush object. + * @param OH_Drawing_Filter Indicates the pointer to an OH_Drawing_Filter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_BrushSetFilter(OH_Drawing_Brush*, OH_Drawing_Filter*); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_canvas.h b/graphic/graphic_2d/native_drawing/drawing_canvas.h index baebc08e998517c2174a7c20b73ada0a38a87872..cc37815899750dae0d247397f59ebc3db6e23256 100644 --- a/graphic/graphic_2d/native_drawing/drawing_canvas.h +++ b/graphic/graphic_2d/native_drawing/drawing_canvas.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -139,6 +139,28 @@ void OH_Drawing_CanvasSave(OH_Drawing_Canvas*); */ void OH_Drawing_CanvasRestore(OH_Drawing_Canvas*); +/** + * @brief Gets the number of the canvas status (canvas matrix) saved in the stack. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @return Returns a 32-bit variable that describes the number of canvas status. + * @since 11 + * @version 1.0 + */ +uint32_t OH_Drawing_CanvasGetSaveCount(OH_Drawing_Canvas*); + +/** + * @brief Restores the specific number of the canvas status (canvas matrix) saved in the stack. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param saveCount Indicates the specific number of canvas status. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasRestoreToCount(OH_Drawing_Canvas*, uint32_t saveCount); + /** * @brief Draws a line segment. * @@ -177,6 +199,77 @@ void OH_Drawing_CanvasDrawPath(OH_Drawing_Canvas*, const OH_Drawing_Path*); */ void OH_Drawing_CanvasDrawBitmap(OH_Drawing_Canvas*, const OH_Drawing_Bitmap*, float left, float top); +/** + * @brief Draws a rect. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*); + +/** + * @brief Draws a circle. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Point Indicates the pointer to an OH_Drawing_Point object. + * @param radius Indicates the radius of the circle. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawCircle(OH_Drawing_Canvas*, const OH_Drawing_Point*, float radius); + +/** + * @brief Draws an oval. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawOval(OH_Drawing_Canvas*, const OH_Drawing_Rect*); + +/** + * @brief Draws an arc. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object. + * @param startAngle Indicates the startAngle of the arc. + * @param sweepAngle Indicates the sweepAngle of the arc. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawArc(OH_Drawing_Canvas*, const OH_Drawing_Rect*, float startAngle, float sweepAngle); + +/** + * @brief Draws a roundrect. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_RoundRect Indicates the pointer to an OH_Drawing_RoundRect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas*, const OH_Drawing_RoundRect*); + +/** + * @brief Draws a textblob. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_TextBlob Indicates the pointer to an OH_Drawing_TextBlob object. + * @param x Indicates the horizontal offset applied to blob. + * @param y Indicates the vertical offset applied to blob. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas*, const OH_Drawing_TextBlob*, float x, float y); + /** * @brief Enumerates clip op. * @@ -199,18 +292,42 @@ typedef enum { * * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. - * @param left Indicates the left position of the rect. - * @param top Indicates the top position of the rect. - * @param right Indicates the right position of the rect. - * @param bottom Indicates the bottom position of the rect. + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object. * @param clipOp Indicates the operation to apply to clip. * @param doAntiAlias Indicates whether clip operation requires anti-aliased. * @since 11 * @version 1.0 */ -void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas*, float left, float top, float right, float bottom, +void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*, OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias); +/** + * @brief Clip a path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Path Indicates the pointer to an OH_Drawing_Path object. + * @param clipOp Indicates the operation to apply to clip. + * @param doAntiAlias Indicates whether clip operation requires anti-aliased. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas*, const OH_Drawing_Path*, + OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias); + +/** + * @brief Rotates by degrees. Positive degrees rotates clockwise. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param degrees Indicates the amount to rotate, in degrees. + * @param px Indicates the x-axis value of the point to rotate about. + * @param py Indicates the y-axis value of the point to rotate about. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_CanvasRotate(OH_Drawing_Canvas*, float degrees, float px, float py); + /** * @brief Translates by dx along the x-axis and dy along the y-axis. * diff --git a/graphic/graphic_2d/native_drawing/drawing_color_filter.h b/graphic/graphic_2d/native_drawing/drawing_color_filter.h new file mode 100644 index 0000000000000000000000000000000000000000..67eefc7e520510af4f8a85f53c48598c3a44173a --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_color_filter.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_COLOR_FILTER_H +#define C_INCLUDE_DRAWING_COLOR_FILTER_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_color_filter.h + * + * @brief Declares functions related to the colorFilter object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_ColorFilter with a blend mode. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param color Indicates the color, which is a 32-bit (ARGB) variable. + * @param OH_Drawing_BlendMode Indicates the blend mode. + * @return Returns the pointer to the OH_Drawing_ColorFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateBlendMode(uint32_t color, OH_Drawing_BlendMode); + +/** + * @brief Creates an OH_Drawing_ColorFilter applies the colorFilter1 and then applies colorFilter2. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_ColorFilter Indicates the pointer to an OH_Drawing_ColorFilter object. + * @param OH_Drawing_ColorFilter Indicates the pointer to an OH_Drawing_ColorFilter object. + * @return Returns the pointer to the OH_Drawing_ColorFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateCompose(OH_Drawing_ColorFilter* colorFilter1, + OH_Drawing_ColorFilter* colorFilter2); + +/** + * @brief Creates an OH_Drawing_ColorFilter with a 5x4 color matrix. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param matrix Indicates the matrix, which is represented as a float array of length 20. + * @return Returns the pointer to the OH_Drawing_ColorFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateMatrix(const float matrix[20]); + +/** + * @brief Creates an OH_Drawing_ColorFilter applies the gamma curve of SRGB to the RGB color channel. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_ColorFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateLinearToSrgbGamma(void); + +/** + * @brief Creates an OH_Drawing_ColorFilter applies the RGB color channel to the gamma curve of SRGB. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_ColorFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateSrgbGammaToLinear(void); + +/** + * @brief Creates an OH_Drawing_ColorFilter multiplies the luma of its input into the alpha channel, + * and sets the red, green, and blue channels to zero. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_ColorFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateLuma(void); + +/** + * @brief Destroys an OH_Drawing_ColorFilter object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_ColorFilter Indicates the pointer to an OH_Drawing_ColorFilter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_ColorFilterDestroy(OH_Drawing_ColorFilter*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_filter.h b/graphic/graphic_2d/native_drawing/drawing_filter.h new file mode 100644 index 0000000000000000000000000000000000000000..3a031b95fb94ed9cd4187eaf03d71c115193960b --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_filter.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_FILTER_H +#define C_INCLUDE_DRAWING_FILTER_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_filter.h + * + * @brief Declares functions related to the filter object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_Filter object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_Filter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_Filter* OH_Drawing_FilterCreate(void); + +/** + * @brief Sets an OH_Drawing_MaskFilter object for an OH_Drawing_Filter object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Filter Indicates the pointer to an OH_Drawing_Filter object. + * @param OH_Drawing_MaskFilter Indicates the pointer to an OH_Drawing_MaskFilter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FilterSetMaskFilter(OH_Drawing_Filter*, OH_Drawing_MaskFilter*); + +/** + * @brief Sets an OH_Drawing_ColorFilter object for an OH_Drawing_Filter object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Filter Indicates the pointer to an OH_Drawing_Filter object. + * @param OH_Drawing_ColorFilter Indicates the pointer to an OH_Drawing_ColorFilter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FilterSetColorFilter(OH_Drawing_Filter*, OH_Drawing_ColorFilter*); + +/** + * @brief Destroys an OH_Drawing_Filter object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Filter Indicates the pointer to an OH_Drawing_Filter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FilterDestroy(OH_Drawing_Filter*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_font.h b/graphic/graphic_2d/native_drawing/drawing_font.h new file mode 100644 index 0000000000000000000000000000000000000000..5c02a704d0b24f8fc6aaa4051878280e0643edea --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_font.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_FONT_H +#define C_INCLUDE_DRAWING_FONT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_font.h + * + * @brief Declares functions related to the font object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_Font object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_Font* OH_Drawing_FontCreate(void); + +/** + * @brief Sets an OH_Drawing_Typeface object for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param OH_Drawing_Typeface Indicates the pointer to an OH_Drawing_Typeface object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FontSetTypeface(OH_Drawing_Font*, OH_Drawing_Typeface*); + +/** + * @brief Sets text size for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param textSize Indicates the text size. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FontSetTextSize(OH_Drawing_Font*, float textSize); + +/** + * @brief Enables or disables linearly scalable font for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param isLinearText Indicates whether to enable linearly scalable font. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FontSetLinearText(OH_Drawing_Font*, bool isLinearText); + +/** + * @brief Sets text skew on x-axis for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param skewX Indicates the additional shear on x-axis relative to y-axis. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FontSetTextSkewX(OH_Drawing_Font*, float skewX); + +/** + * @brief Enables or disables to increase stroke width to approximate bold fonts for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param isFakeBoldText Indicates whether to enable to increase stroke width. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FontSetFakeBoldText(OH_Drawing_Font*, bool isFakeBoldText); + +/** + * @brief Destroys an OH_Drawing_Font object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_FontDestroy(OH_Drawing_Font*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_mask_filter.h b/graphic/graphic_2d/native_drawing/drawing_mask_filter.h new file mode 100644 index 0000000000000000000000000000000000000000..8c60501b11cb361f3bfc7b686a10ffcdb2e56507 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_mask_filter.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_MASK_FILTER_H +#define C_INCLUDE_DRAWING_MASK_FILTER_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_mask_filter.h + * + * @brief Declares functions related to the maskFilter object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates blur type. + * + * @since 11 + * @version 1.0 + */ +typedef enum { + /** + * Fuzzy inside and outside. + */ + NORMAL, + /** + * Solid inside, fuzzy outside. + */ + SOLID, + /** + * Nothing inside, fuzzy outside. + */ + OUTER, + /** + * Fuzzy inside, nothing outside. + */ + INNER, +} OH_Drawing_BlurType; + +/** + * @brief Creates an OH_Drawing_MaskFilter with a blur effect. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param blurType Indicates the blur type. + * @param sigma Indicates the standard deviation of the Gaussian blur to apply. Must be > 0. + * @param respectCTM Indicates the blur's sigma is modified by the CTM, default is true. + * @return Returns the pointer to the OH_Drawing_MaskFilter object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_MaskFilter* OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType blurType, float sigma, bool respectCTM); + +/** + * @brief Destroys an OH_Drawing_MaskFilter object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_MaskFilter Indicates the pointer to an OH_Drawing_MaskFilter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_MaskFilterDestroy(OH_Drawing_MaskFilter*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_matrix.h b/graphic/graphic_2d/native_drawing/drawing_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..8ae3da4c2e141737926d18b59c7ca4e3c851e741 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_matrix.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_MATRIX_H +#define C_INCLUDE_DRAWING_MATRIX_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_matrix.h + * + * @brief Declares functions related to the matrix object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_Matrix object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_Matrix object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_Matrix* OH_Drawing_MatrixCreate(void); + +/** + * @brief Sets the params for a matrix. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Matrix Indicates the pointer to an OH_Drawing_Matrix object. + * @param scaleX horizontal scale factor to store + * @param skewX horizontal skew factor to store + * @param transX horizontal translation to store + * @param skewY vertical skew factor to store + * @param scaleY vertical scale factor to store + * @param transY vertical translation to store + * @param persp0 input x-axis values perspective factor to store + * @param persp1 input y-axis values perspective factor to store + * @param persp2 perspective scale factor to store + * @since 11 + * @version 1.0 + */ +void OH_Drawing_MatrixSetMatrix(OH_Drawing_Matrix*, float scaleX, float skewX, float transX, + float skewY, float scaleY, float transY, float persp0, float persp1, float persp2); + +/** + * @brief Destroys an OH_Drawing_Matrix object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Matrix Indicates the pointer to an OH_Drawing_Matrix object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_MatrixDestroy(OH_Drawing_Matrix*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_pen.h b/graphic/graphic_2d/native_drawing/drawing_pen.h index 70deb6d09c37a50c4bcf6325c1619665fa539676..220e5723d12d8ede702f020b1c2dd9c2efd2ecea 100644 --- a/graphic/graphic_2d/native_drawing/drawing_pen.h +++ b/graphic/graphic_2d/native_drawing/drawing_pen.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -110,6 +110,28 @@ uint32_t OH_Drawing_PenGetColor(const OH_Drawing_Pen*); */ void OH_Drawing_PenSetColor(OH_Drawing_Pen*, uint32_t color); +/** + * @brief Obtains the alpha of a pen. The alpha is used by the pen to outline a shape. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object. + * @return Returns a 8-bit variable that describes the alpha. + * @since 11 + * @version 1.0 + */ +uint8_t OH_Drawing_PenGetAlpha(const OH_Drawing_Pen*); + +/** + * @brief Sets the alpha for a pen. The alpha is used by the pen to outline a shape. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object. + * @param alpha Indicates the alpha to set, which is a 8-bit variable. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_PenSetAlpha(OH_Drawing_Pen*, uint8_t alpha); + /** * @brief Obtains the thickness of a pen. This thickness determines the width of the outline of a shape. * @@ -247,6 +269,28 @@ OH_Drawing_PenLineJoinStyle OH_Drawing_PenGetJoin(const OH_Drawing_Pen*); */ void OH_Drawing_PenSetJoin(OH_Drawing_Pen*, OH_Drawing_PenLineJoinStyle); +/** + * @brief Sets the shaderEffect for a pen. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object. + * @param OH_Drawing_ShaderEffect Indicates the pointer to an OH_Drawing_ShaderEffect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_PenSetShaderEffect(OH_Drawing_Pen*, OH_Drawing_ShaderEffect*); + +/** + * @brief Sets the filter for a pen. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object. + * @param OH_Drawing_Filter Indicates the pointer to an OH_Drawing_Filter object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_PenSetFilter(OH_Drawing_Pen*, OH_Drawing_Filter*); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_point.h b/graphic/graphic_2d/native_drawing/drawing_point.h new file mode 100644 index 0000000000000000000000000000000000000000..f63faf78d885ee6a432dfb677b524e3f1934fdb1 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_point.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_POINT_H +#define C_INCLUDE_DRAWING_POINT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_point.h + * + * @brief Declares functions related to the point object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_Point object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param x Indicates the x-axis coordinates of the point. + * @param y Indicates the y-axis coordinates of the point. + * @return Returns the pointer to the OH_Drawing_Point object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_Point* OH_Drawing_PointCreate(float x, float y); + +/** + * @brief Destroys an OH_Drawing_Point object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Point Indicates the pointer to an OH_Drawing_Point object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_PointDestroy(OH_Drawing_Point*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_rect.h b/graphic/graphic_2d/native_drawing/drawing_rect.h new file mode 100644 index 0000000000000000000000000000000000000000..3f1a1bc0e03a5b1afaf333df5e19b871b3d3fa5d --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_rect.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_RECT_H +#define C_INCLUDE_DRAWING_RECT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_rect.h + * + * @brief Declares functions related to the rect object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_Rect object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param left Indicates the left position of the rect. + * @param top Indicates the top position of the rect. + * @param right Indicates the right position of the rect. + * @param bottom Indicates the bottom position of the rect. + * @return Returns the pointer to the OH_Drawing_Rect object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_Rect* OH_Drawing_RectCreate(float left, float top, float right, float bottom); + +/** + * @brief Destroys an OH_Drawing_Rect object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_RectDestroy(OH_Drawing_Rect*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_round_rect.h b/graphic/graphic_2d/native_drawing/drawing_round_rect.h new file mode 100644 index 0000000000000000000000000000000000000000..d17025de1e942b68ed937e34bc93f702081bc100 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_round_rect.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_ROUND_RECT_H +#define C_INCLUDE_DRAWING_ROUND_RECT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_round_rect.h + * + * @brief Declares functions related to the roundRect object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_RoundRect object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object. + * @param xRad Indicates the corner radii on x-axis. + * @param yRad Indicates the corner radii on y-axis. + * @return Returns the pointer to the OH_Drawing_RoundRect object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_RoundRect* OH_Drawing_RoundRectCreate(const OH_Drawing_Rect*, float xRad, float yRad); + +/** + * @brief Destroys an OH_Drawing_RoundRect object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_RoundRect Indicates the pointer to an OH_Drawing_RoundRect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_RoundRectDestroy(OH_Drawing_RoundRect*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_shader_effect.h b/graphic/graphic_2d/native_drawing/drawing_shader_effect.h new file mode 100644 index 0000000000000000000000000000000000000000..6eac17aaa560ee6431cdf6d25af275cd55239be9 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_shader_effect.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_SHADER_EFFECT_H +#define C_INCLUDE_DRAWING_SHADER_EFFECT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_shader_effect.h + * + * @brief Declares functions related to the shaderEffect object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates tile mode. + * + * @since 11 + * @version 1.0 + */ +typedef enum { + /** + * Replicate the edge color if the shader effect draws outside of its original bounds. + */ + CLAMP, + /** + * Repeat the shader effect image horizontally and vertically. + */ + REPEAT, + /** + * Repeat the shader effect image horizontally and vertically, alternating mirror images + * so that adjacent images always seam. + */ + MIRROR, + /** + * Only draw within the original domain, return transparent-black everywhere else. + */ + DECAL, +} OH_Drawing_TileMode; + +/** + * @brief Creates an OH_Drawing_ShaderEffect that generates a linear gradient between the two specified points. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param startPt Indicates the start point for the gradient. + * @param endPt Indicates the end point for the gradient. + * @param colors Indicates the colors to be distributed between the two points. + * @param pos Indicates the relative position of each corresponding color in the colors array. + * @param size Indicates the number of colors and pos. + * @param OH_Drawing_TileMode Indicates the tile mode. + * @return Returns the pointer to the OH_Drawing_ShaderEffect object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradient(const OH_Drawing_Point* startPt, + const OH_Drawing_Point* endPt, const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); + +/** + * @brief Creates an OH_Drawing_ShaderEffect that generates a radial gradient given the center and radius. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param centerPt Indicates the center of the circle for the gradient. + * @param radius Indicates the radius of the circle for this gradient. + * @param colors Indicates the colors to be distributed between the two points. + * @param pos Indicates the relative position of each corresponding color in the colors array. + * @param size Indicates the number of colors and pos. + * @param OH_Drawing_TileMode Indicates the tile mode. + * @return Returns the pointer to the OH_Drawing_ShaderEffect object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradient(const OH_Drawing_Point* centerPt, float radius, + const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); + +/** + * @brief Creates an OH_Drawing_ShaderEffect that generates a sweep gradient given a center. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param centerPt Indicates the center of the circle for the gradient. + * @param colors Indicates the colors to be distributed between the two points. + * @param pos Indicates the relative position of each corresponding color in the colors array. + * @param size Indicates the number of colors and pos. + * @param OH_Drawing_TileMode Indicates the tile mode. + * @return Returns the pointer to the OH_Drawing_ShaderEffect object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateSweepGradient(const OH_Drawing_Point* centerPt, + const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); + +/** + * @brief Destroys an OH_Drawing_ShaderEffect object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_ShaderEffect Indicates the pointer to an OH_Drawing_ShaderEffect object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_ShaderEffectDestroy(OH_Drawing_ShaderEffect*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_text_blob.h b/graphic/graphic_2d/native_drawing/drawing_text_blob.h new file mode 100644 index 0000000000000000000000000000000000000000..73325b032013affd46f05212499dcf3f6d30f9c0 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_text_blob.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_TEXT_BLOB_H +#define C_INCLUDE_DRAWING_TEXT_BLOB_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_text_blob.h + * + * @brief Declares functions related to the textBlob object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_TextBlobBuilder object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_TextBlobBuilder object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_TextBlobBuilder* OH_Drawing_TextBlobBuilderCreate(void); + +/** + * @brief Defines a run, supplies storage for glyphs and positions. + * + * @since 11 + * @version 1.0 + */ +typedef struct { + /** storage for glyph indexes in run */ + uint16_t* glyphs; + /** storage for glyph positions in run */ + float* pos; + /** storage for text UTF-8 code units in run */ + char* utf8text; + /** storage for glyph clusters (index of UTF-8 code unit) */ + uint32_t* clusters; +} OH_Drawing_RunBuffer; + +/** + * @brief Alloc run with storage for glyphs and positions. The returned pointer does not need to be managed + * by the caller and is forbidden to be used after OH_Drawing_TextBlobBuilderMake is called. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an OH_Drawing_TextBlobBuilder object. + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param count Indicates the number of glyphs. + * @param OH_Drawing_Rect Indicates the optional run bounding box. + * @since 11 + * @version 1.0 + */ +const OH_Drawing_RunBuffer* OH_Drawing_TextBlobBuilderAllocRunPos(OH_Drawing_TextBlobBuilder*, const OH_Drawing_Font*, + int32_t count, const OH_Drawing_Rect*); + +/** + * @brief Make an OH_Drawing_TextBlob from OH_Drawing_TextBlobBuilder. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an OH_Drawing_TextBlobBuilder object. + * @return Returns the pointer to the OH_Drawing_TextBlob object. + * @since 11 + * @version 1.0 + */ +OH_Drawing_TextBlob* OH_Drawing_TextBlobBuilderMake(OH_Drawing_TextBlobBuilder*); + +/** + * @brief Destroys an OH_Drawing_TextBlob object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextBlob Indicates the pointer to an OH_Drawing_TextBlob object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_TextBlobDestroy(OH_Drawing_TextBlob*); + +/** + * @brief Destroys an OH_Drawing_TextBlobBuilder object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextBlobBuilder Indicates the pointer to an OH_Drawing_TextBlobBuilder object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_TextBlobBuilderDestroy(OH_Drawing_TextBlobBuilder*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_typeface.h b/graphic/graphic_2d/native_drawing/drawing_typeface.h new file mode 100644 index 0000000000000000000000000000000000000000..a484d70f2d560d9865122a46c2fd1d68a32be856 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_typeface.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_TYPEFACE_H +#define C_INCLUDE_DRAWING_TYPEFACE_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 11 + * @version 1.0 + */ + +/** + * @file drawing_typeface.h + * + * @brief Declares functions related to the typeface object in the drawing module. + * + * @since 11 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates a default OH_Drawing_Typeface object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_Typeface object created. + * @since 11 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_TypefaceCreateDefault(void); + +/** + * @brief Destroys an OH_Drawing_Typeface object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Typeface Indicates the pointer to an OH_Drawing_Typeface object. + * @since 11 + * @version 1.0 + */ +void OH_Drawing_TypefaceDestroy(OH_Drawing_Typeface*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index ee945b72e7581c0e88c091fcfe5ed1d7de6b569b..cdf7f35cc7738dc86e91aa114147e4e10c70f3ef 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -46,7 +46,7 @@ extern "C" { /** * @brief Defines a rectangular canvas on which various shapes, images, * and texts can be drawn by using the brush and pen. - * + * * @since 8 * @version 1.0 */ @@ -54,7 +54,7 @@ typedef struct OH_Drawing_Canvas OH_Drawing_Canvas; /** * @brief Defines a pen, which is used to describe the style and color to outline a shape. - * + * * @since 8 * @version 1.0 */ @@ -62,7 +62,7 @@ typedef struct OH_Drawing_Pen OH_Drawing_Pen; /** * @brief Defines as a brush, which is used to describe the style and color to fill in a shape. - * + * * @since 8 * @version 1.0 */ @@ -70,7 +70,7 @@ typedef struct OH_Drawing_Brush OH_Drawing_Brush; /** * @brief Defines a path, which is used to customize various shapes. - * + * * @since 8 * @version 1.0 */ @@ -78,15 +78,112 @@ typedef struct OH_Drawing_Path OH_Drawing_Path; /** * @brief Defines a bitmap, which is a memory that contains the pixel data of a shape. - * + * * @since 8 * @version 1.0 */ typedef struct OH_Drawing_Bitmap OH_Drawing_Bitmap; +/** + * @brief Defines a point, which is used to describe the coordinate point. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_Point OH_Drawing_Point; + +/** + * @brief Defines a rect, which is used to describe the rectangle. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_Rect OH_Drawing_Rect; + +/** + * @brief Defines a roundRect, which is used to describe the round rectangle. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_RoundRect OH_Drawing_RoundRect; + +/** + * @brief Defines a matrix, which is used to describe the transforming coordinates. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_Matrix OH_Drawing_Matrix; + +/** + * @brief Defines a shaderEffect, which is used to describe the source color(s) for what is being drawn. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_ShaderEffect OH_Drawing_ShaderEffect; + +/** + * @brief Defines a filter, which is used to store maskFilter and colorFilter. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_Filter OH_Drawing_Filter; + +/** + * @brief Defines a maskFilter, which is used to perform transformations on the mask before drawing it. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_MaskFilter OH_Drawing_MaskFilter; + +/** + * @brief Defines a colorFilter, which is called a color and returns a new color. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_ColorFilter OH_Drawing_ColorFilter; + +/** + * @brief Defines a font, which is used to describe the font. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_Font OH_Drawing_Font; + +/** + * @brief Defines a typeface, which is used to describe the typeface. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_Typeface OH_Drawing_Typeface; + +/** + * @brief Defines a textBlob, which combines multiple text runs into an immutable container. + * Each text run consists of glyphs and positions. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_TextBlob OH_Drawing_TextBlob; + +/** + * @brief Defines a textBlobBuilder, which is used to build the textBlob. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_Drawing_TextBlobBuilder OH_Drawing_TextBlobBuilder; + /** * @brief Enumerates storage formats of bitmap pixels. - * + * * @since 8 * @version 1.0 */ @@ -119,7 +216,7 @@ typedef enum { /** * @brief Enumerates alpha formats of bitmap pixels. - * + * * @since 8 * @version 1.0 */ @@ -134,6 +231,86 @@ typedef enum { ALPHA_FORMAT_UNPREMUL } OH_Drawing_AlphaFormat; +/** + * @brief The blending operation generates a new color for the two colors (source, target). + * These operations are the same on the 4 color channels: red, green, blue, alpha. + * For these, we use alpha channel as an example, rather than naming each channel individually. + * + * For brevity, we use the following abbreviations. + * s : source + * d : destination + * sa : source alpha + * da : destination alpha + * + * Results are abbreviated + * r : if all 4 channels are computed in the same manner + * ra : result alpha channel + * rc : result "color": red, green, blue channels + * + * @since 11 + * @version 1.0 + */ +typedef enum { + /** r = 0. */ + BLEND_MODE_CLEAR, + /** r = s. */ + BLEND_MODE_SRC, + /** r = d. */ + BLEND_MODE_DST, + /** r = s + (1-sa)*d. */ + BLEND_MODE_SRC_OVER, + /** r = d + (1-da)*s. */ + BLEND_MODE_DST_OVER, + /** r = s * da. */ + BLEND_MODE_SRC_IN, + /** r = d * sa. */ + BLEND_MODE_DST_IN, + /** r = s * (1-da). */ + BLEND_MODE_SRC_OUT, + /** r = d * (1-sa). */ + BLEND_MODE_DST_OUT, + /** r = s*da + d*(1-sa). */ + BLEND_MODE_SRC_ATOP, + /** r = d*sa + s*(1-da). */ + BLEND_MODE_DST_ATOP, + /** r = s*(1-da) + d*(1-sa). */ + BLEND_MODE_XOR, + /** r = min(s + d, 1). */ + BLEND_MODE_PLUS, + /** r = s*d. */ + BLEND_MODE_MODULATE, + /** r = s + d - s*d. */ + BLEND_MODE_SCREEN, + /** multiply or screen, depending on destination. */ + BLEND_MODE_OVERLAY, + /** rc = s + d - max(s*da, d*sa), ra = s + (1-sa)*d. */ + BLEND_MODE_DARKEN, + /** rc = s + d - min(s*da, d*sa), ra = s + (1-sa)*d. */ + BLEND_MODE_LIGHTEN, + /** brighten destination to reflect source. */ + BLEND_MODE_COLOR_DODGE, + /** darken destination to reflect source. */ + BLEND_MODE_COLOR_BURN, + /** multiply or screen, depending on source. */ + BLEND_MODE_HARD_LIGHT, + /** lighten or darken, depending on source. */ + BLEND_MODE_SOFT_LIGHT, + /** rc = s + d - 2*(min(s*da, d*sa)), ra = s + (1-sa)*d. */ + BLEND_MODE_DIFFERENCE, + /** rc = s + d - two(s*d), ra = s + (1-sa)*d. */ + BLEND_MODE_EXCLUSION, + /** r = s*(1-da) + d*(1-sa) + s*d. */ + BLEND_MODE_MULTIPLY, + /** hue of source with saturation and luminosity of destination. */ + BLEND_MODE_HUE, + /** saturation of source with hue and luminosity of destination. */ + BLEND_MODE_SATURATION, + /** hue and saturation of source with luminosity of destination. */ + BLEND_MODE_COLOR, + /** luminosity of source with hue and saturation of destination. */ + BLEND_MODE_LUMINOSITY, +} OH_Drawing_BlendMode; + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index 4763442825d8000235cbdb1c36c611c649f1216a..222d418be16567e72e35fb82dc438ced52aadeea 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -7,10 +7,14 @@ { "name": "OH_Drawing_BitmapGetPixels" }, { "name": "OH_Drawing_BrushCreate" }, { "name": "OH_Drawing_BrushDestroy" }, + { "name": "OH_Drawing_BrushGetAlpha" }, + { "name": "OH_Drawing_BrushSetAlpha" }, { "name": "OH_Drawing_BrushIsAntiAlias" }, { "name": "OH_Drawing_BrushSetAntiAlias" }, { "name": "OH_Drawing_BrushGetColor" }, { "name": "OH_Drawing_BrushSetColor" }, + { "name": "OH_Drawing_BrushSetFilter" }, + { "name": "OH_Drawing_BrushSetShaderEffect" }, { "name": "OH_Drawing_CanvasCreate" }, { "name": "OH_Drawing_CanvasDestroy" }, { "name": "OH_Drawing_CanvasBind" }, @@ -20,13 +24,46 @@ { "name": "OH_Drawing_CanvasDetachBrush" }, { "name": "OH_Drawing_CanvasSave" }, { "name": "OH_Drawing_CanvasRestore" }, + { "name": "OH_Drawing_CanvasGetSaveCount" }, + { "name": "OH_Drawing_CanvasRestoreToCount" }, + { "name": "OH_Drawing_CanvasDrawArc" }, + { "name": "OH_Drawing_CanvasDrawBitmap" }, + { "name": "OH_Drawing_CanvasDrawCircle" }, { "name": "OH_Drawing_CanvasDrawLine" }, + { "name": "OH_Drawing_CanvasDrawOval" }, { "name": "OH_Drawing_CanvasDrawPath" }, - { "name": "OH_Drawing_CanvasDrawBitmap" }, + { "name": "OH_Drawing_CanvasDrawRect" }, + { "name": "OH_Drawing_CanvasDrawRoundRect" }, + { "name": "OH_Drawing_CanvasDrawTextBlob" }, { "name": "OH_Drawing_CanvasClipRect" }, + { "name": "OH_Drawing_CanvasClipPath" }, + { "name": "OH_Drawing_CanvasRotate" }, { "name": "OH_Drawing_CanvasTranslate" }, { "name": "OH_Drawing_CanvasScale" }, { "name": "OH_Drawing_CanvasClear" }, + { "name": "OH_Drawing_ColorFilterCreateBlendMode" }, + { "name": "OH_Drawing_ColorFilterCreateCompose" }, + { "name": "OH_Drawing_ColorFilterCreateLinearToSrgbGamma" }, + { "name": "OH_Drawing_ColorFilterCreateLuma" }, + { "name": "OH_Drawing_ColorFilterCreateMatrix" }, + { "name": "OH_Drawing_ColorFilterCreateSrgbGammaToLinear" }, + { "name": "OH_Drawing_ColorFilterDestroy" }, + { "name": "OH_Drawing_FilterCreate" }, + { "name": "OH_Drawing_FilterSetColorFilter" }, + { "name": "OH_Drawing_FilterSetMaskFilter" }, + { "name": "OH_Drawing_FilterDestroy" }, + { "name": "OH_Drawing_FontCreate" }, + { "name": "OH_Drawing_FontDestroy" }, + { "name": "OH_Drawing_FontSetFakeBoldText" }, + { "name": "OH_Drawing_FontSetLinearText" }, + { "name": "OH_Drawing_FontSetTextSize" }, + { "name": "OH_Drawing_FontSetTextSkewX" }, + { "name": "OH_Drawing_FontSetTypeface" }, + { "name": "OH_Drawing_MaskFilterCreateBlur" }, + { "name": "OH_Drawing_MaskFilterDestroy" }, + { "name": "OH_Drawing_MatrixCreate" }, + { "name": "OH_Drawing_MatrixSetMatrix" }, + { "name": "OH_Drawing_MatrixDestroy" }, { "name": "OH_Drawing_PathCreate" }, { "name": "OH_Drawing_PathDestroy" }, { "name": "OH_Drawing_PathMoveTo" }, @@ -38,6 +75,8 @@ { "name": "OH_Drawing_PathReset" }, { "name": "OH_Drawing_PenCreate" }, { "name": "OH_Drawing_PenDestroy" }, + { "name": "OH_Drawing_PenGetAlpha" }, + { "name": "OH_Drawing_PenSetAlpha" }, { "name": "OH_Drawing_PenIsAntiAlias" }, { "name": "OH_Drawing_PenSetAntiAlias" }, { "name": "OH_Drawing_PenGetColor" }, @@ -50,6 +89,10 @@ { "name": "OH_Drawing_PenSetCap" }, { "name": "OH_Drawing_PenGetJoin" }, { "name": "OH_Drawing_PenSetJoin" }, + { "name": "OH_Drawing_PenSetFilter" }, + { "name": "OH_Drawing_PenSetShaderEffect" }, + { "name": "OH_Drawing_PointCreate" }, + { "name": "OH_Drawing_PointDestroy" }, { "name": "OH_Drawing_ColorSetArgb" }, { "name": "OH_Drawing_CreateFontCollection" }, { "name": "OH_Drawing_DestroyFontCollection" }, @@ -60,6 +103,10 @@ { "name": "OH_Drawing_SetTypographyTextMaxLines" }, { "name": "OH_Drawing_CreateTextStyle" }, { "name": "OH_Drawing_DestroyTextStyle" }, + { "name": "OH_Drawing_RectCreate" }, + { "name": "OH_Drawing_RectDestroy" }, + { "name": "OH_Drawing_RoundRectCreate" }, + { "name": "OH_Drawing_RoundRectDestroy" }, { "name": "OH_Drawing_SetTextStyleColor" }, { "name": "OH_Drawing_SetTextStyleFontSize" }, { "name": "OH_Drawing_SetTextStyleFontWeight" }, @@ -70,6 +117,17 @@ { "name": "OH_Drawing_SetTextStyleFontFamilies" }, { "name": "OH_Drawing_SetTextStyleFontStyle" }, { "name": "OH_Drawing_SetTextStyleLocale" }, + { "name": "OH_Drawing_ShaderEffectCreateLinearGradient" }, + { "name": "OH_Drawing_ShaderEffectCreateRadialGradient" }, + { "name": "OH_Drawing_ShaderEffectCreateSweepGradient" }, + { "name": "OH_Drawing_ShaderEffectDestroy" }, + { "name": "OH_Drawing_TextBlobBuilderAllocRunPos" }, + { "name": "OH_Drawing_TextBlobBuilderCreate" }, + { "name": "OH_Drawing_TextBlobBuilderDestroy" }, + { "name": "OH_Drawing_TextBlobBuilderMake" }, + { "name": "OH_Drawing_TextBlobDestroy" }, + { "name": "OH_Drawing_TypefaceCreateDefault" }, + { "name": "OH_Drawing_TypefaceDestroy" }, { "name": "OH_Drawing_CreateTypographyHandler" }, { "name": "OH_Drawing_DestroyTypographyHandler" }, { "name": "OH_Drawing_TypographyHandlerPushTextStyle" },