From 794292000919ee18ba53245c3cd8df521cf6bbfc Mon Sep 17 00:00:00 2001 From: changleipeng Date: Sat, 3 Aug 2024 11:34:13 +0800 Subject: [PATCH] add ndk interface for path and bound obtain for font glyph Signed-off-by: changleipeng --- .../graphic_2d/native_drawing/drawing_font.h | 32 +++++++++++++ .../graphic_2d/native_drawing/drawing_rect.h | 48 +++++++++++++++++++ .../graphic_2d/native_drawing/drawing_types.h | 9 ++++ .../native_drawing/libnative_drawing.ndk.json | 24 ++++++++++ 4 files changed, 113 insertions(+) diff --git a/graphic/graphic_2d/native_drawing/drawing_font.h b/graphic/graphic_2d/native_drawing/drawing_font.h index 38ea644f3..f056846fd 100644 --- a/graphic/graphic_2d/native_drawing/drawing_font.h +++ b/graphic/graphic_2d/native_drawing/drawing_font.h @@ -497,6 +497,38 @@ typedef struct OH_Drawing_Font_Metrics { */ float OH_Drawing_FontGetMetrics(OH_Drawing_Font*, OH_Drawing_Font_Metrics*); +/** + * @brief Retrieves the bound rect for each glyph in glyph array. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param glyphs Indicates the array of glyph indices to be measured. + * @param count Indicates the number of glyphs. + * @param OH_Drawing_Array The bound rect array for each glyph, returned to the caller. + * @since 14 + * @version 1.0 + * @note OH_Drawing_Array object must be allocated by OH_Drawing_RectCreateArray function. + * @note Size of OH_Drawing_Array must be bigger than glyph counts. + * @note OH_Drawing_Rect use y-axis-goes-down system, y axis is inverted to the y-axis-goes-up system. + * @note OH_Drawing_Rect use two points(left-bottom & right-top) to describe the bound. + * @note The bound rect will be snap to integral boundaries. + */ +void OH_Drawing_FontGetBounds(const OH_Drawing_Font*, const uint16_t* glyphs, int count, OH_Drawing_Array*); + +/** + * @brief Create a path object for specified Glyph. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param glyph glyph index to be obtained. + * @return Returns an OH_Drawing_Path object of specified glyph index, return nullptr if error happened. + * @since 14 + * @version 1.0 + * @note OH_Drawing_Path use y-axis-goes-down system, y axis is inverted to the y-axis-goes-up system. + * @note Return value must be released by OH_Drawing_PathDestroy function. + */ +OH_Drawing_Path* OH_Drawing_FontCreatePathForGlyph(OH_Drawing_Font*, uint16_t glyph); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_rect.h b/graphic/graphic_2d/native_drawing/drawing_rect.h index e07abff68..68d240f93 100644 --- a/graphic/graphic_2d/native_drawing/drawing_rect.h +++ b/graphic/graphic_2d/native_drawing/drawing_rect.h @@ -214,6 +214,54 @@ void OH_Drawing_RectCopy(OH_Drawing_Rect* src, OH_Drawing_Rect* dst); */ void OH_Drawing_RectDestroy(OH_Drawing_Rect*); +/** + * @brief Creates an OH_Drawing_Array object, which is used to store multiple OH_Drawing_Rect object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param size Indicates the size of the array object + * @return Returns the pointer to the OH_Drawing_Array object created. + * @since 14 + * @version 1.0 + * @note OH_Drawing_Array must be release by OH_Drawing_RectDestroyArray function. + * @note Return nullptr if size invalid. + */ +OH_Drawing_Array* OH_Drawing_RectCreateArray(size_t size); + +/** + * @brief Return the size of an OH_Drawing_Array object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Array Indicates the array object + * @return The size of the array object + * @since 14 + * @version 1.0 + * @note Return zero if OH_Drawing_Array invalid. + */ +size_t OH_Drawing_RectGetArraySize(OH_Drawing_Array*); + +/** + * @brief return the specified OH_Drawing_Rect object from OH_Drawing_Array object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param rectArr Indicates the array object + * @param index Indicates the index of array, caller must make sure the index is valid. + * @return Returns the pointer to the OH_Drawing_Rect object. + * @since 14 + * @version 1.0 + * @note Return nullptr if OH_Drawing_Array or index invalid. + */ +OH_Drawing_Rect* OH_Drawing_RectGetArrayElement(OH_Drawing_Array* rectArr, size_t index); + +/** + * @brief Destroys an array OH_Drawing_Rect object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Array Indicates the pointer to an OH_Drawing_Array object. + * @since 14 + * @version 1.0 + */ +void OH_Drawing_RectDestroyArray(OH_Drawing_Array*); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index edcc71cb8..3debd6c96 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -167,6 +167,15 @@ typedef struct OH_Drawing_PathEffect OH_Drawing_PathEffect; */ typedef struct OH_Drawing_Rect OH_Drawing_Rect; +/** + * @brief Defines an array object, which is used to store multiple NDK object. + * + * @since 13 + * @version 1.0 + */ + +typedef struct OH_Drawing_Array OH_Drawing_Array; + /** * @brief Defines a roundRect, which is used to describe the round rectangle. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index f0d6835c1..99d76e616 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -1441,5 +1441,29 @@ { "first_introduced": "12", "name":"OH_Drawing_SetTextShadow" + }, + { + "first_introduced": "13", + "name":"OH_Drawing_FontGetBounds" + }, + { + "first_introduced": "13", + "name":"OH_Drawing_FontCreatePathForGlyph" + }, + { + "first_introduced": "13", + "name":"OH_Drawing_RectCreateArray" + }, + { + "first_introduced": "13", + "name":"OH_Drawing_RectGetArraySize" + }, + { + "first_introduced": "13", + "name":"OH_Drawing_RectGetArrayElement" + }, + { + "first_introduced": "13", + "name":"OH_Drawing_RectDestroyArray" } ] \ No newline at end of file -- Gitee