From b2fae9f44494815c36cb22fca7ab4e78ebcc0210 Mon Sep 17 00:00:00 2001 From: ustc-tianyu Date: Wed, 4 Sep 2024 10:10:38 +0800 Subject: [PATCH] cherry pick 167668f from https://gitee.com/ustc-tianyu/interface_sdk_c/pulls/1398 add fontVariation C API Signed-off-by: ustc-tianyu --- .../native_drawing/drawing_typeface.h | 84 ++++++++++++++++++- .../graphic_2d/native_drawing/drawing_types.h | 8 ++ .../native_drawing/libnative_drawing.ndk.json | 20 +++++ 3 files changed, 110 insertions(+), 2 deletions(-) diff --git a/graphic/graphic_2d/native_drawing/drawing_typeface.h b/graphic/graphic_2d/native_drawing/drawing_typeface.h index 0208f5ff9..fa3d016e9 100644 --- a/graphic/graphic_2d/native_drawing/drawing_typeface.h +++ b/graphic/graphic_2d/native_drawing/drawing_typeface.h @@ -40,6 +40,7 @@ * @version 1.0 */ +#include "drawing_error_code.h" #include "drawing_types.h" #ifdef __cplusplus @@ -57,7 +58,7 @@ extern "C" { OH_Drawing_Typeface* OH_Drawing_TypefaceCreateDefault(void); /** - * @brief Creates a OH_Drawing_Typeface object by file. + * @brief Creates an OH_Drawing_Typeface object by file. * * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing * @param path file path. @@ -69,7 +70,44 @@ OH_Drawing_Typeface* OH_Drawing_TypefaceCreateDefault(void); OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFile(const char* path, int index); /** - * @brief Creates a OH_Drawing_Typeface object by given a stream. If the stream is not a valid + * @brief Creates an OH_Drawing_Typeface object with the specified font arguments from a file. + * If the OH_Drawing_Typeface object does not support the variations described in fontArguments, + * this function creates an OH_Drawing_Typeface object without font arguments. + * In this case, this function provides the same capability as {@link OH_Drawing_TypefaceCreateFromFile}. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the file path. + * @param fontArguments Indicates the pointer to an OH_Drawing_FontArguments object. + * @return Returns the pointer to the OH_Drawing_Typeface object created. + * If nullptr is returned, the creation fails. + * The possible cause of the failure is that the available memory is empty, + * or either path or fontArguments is nullptr, or the path is invalid. + * @since 13 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFileWithArguments(const char* path, + const OH_Drawing_FontArguments* fontArguments); + +/** + * @brief Creates an OH_Drawing_Typeface object with the specified font arguments from + * an existing OH_Drawing_Typeface object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param current Indicates the existing OH_Drawing_Typeface object. + * @param fontArguments Indicates the pointer to an OH_Drawing_FontArguments object. + * @return Returns the pointer to the OH_Drawing_Typeface object created. + * If nullptr is returned, the creation fails. + * The possible cause of the failure is that the available memory is empty, + * or either current or fontArguments is nullptr, + * or current does not support the variations described in fontArguments. + * @since 13 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromCurrent(const OH_Drawing_Typeface* current, + const OH_Drawing_FontArguments* fontArguments); + +/** + * @brief Creates an OH_Drawing_Typeface object by given a stream. If the stream is not a valid * font file, returns nullptr. Ownership of the stream is transferred, so the caller must not reference * it or free it again. * @@ -92,6 +130,48 @@ OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromStream(OH_Drawing_MemoryStream */ void OH_Drawing_TypefaceDestroy(OH_Drawing_Typeface*); +/** + * @brief Creates an OH_Drawing_FontArguments object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_FontArguments object created. + * If nullptr is returned, the creation fails. + * The possible cause of the failure is that the available memory is empty. + * @since 13 + * @version 1.0 + */ +OH_Drawing_FontArguments* OH_Drawing_FontArgumentsCreate(void); + +/** + * @brief Adds a font variation axis for an OH_Drawing_FontArguments object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param fontArguments Indicates the pointer to an OH_Drawing_FontArguments object. + * @param axis Indicates the axis tag, which must contain four ASCII characters. + * @param value Indicates the value of the axis field. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if either fontArguments or axis is nullptr, + * or the length of axis is not 4. + * @since 13 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_FontArgumentsAddVariation(OH_Drawing_FontArguments* fontArguments, + const char* axis, float value); + +/** + * @brief Destroys an OH_Drawing_FontArguments object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param fontArguments Indicates the pointer to an OH_Drawing_FontArguments object. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if fontArguments is nullptr. + * @since 13 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_FontArgumentsDestroy(OH_Drawing_FontArguments* fontArguments); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index 71697e908..f10b9f8bf 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -239,6 +239,14 @@ typedef struct OH_Drawing_Font OH_Drawing_Font; */ typedef struct OH_Drawing_MemoryStream OH_Drawing_MemoryStream; +/** + * @brief Defines fontArguments, which is used to describe the arguments for a font. + * + * @since 13 + * @version 1.0 + */ +typedef struct OH_Drawing_FontArguments OH_Drawing_FontArguments; + /** * @brief Defines a typeface, which is used to describe the typeface. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index 5f0503977..c4dcab005 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -176,6 +176,18 @@ }, { "name": "OH_Drawing_FilterSetMaskFilter" }, { "name": "OH_Drawing_FilterDestroy" }, + { + "first_introduced": "13", + "name": "OH_Drawing_FontArgumentsAddVariation" + }, + { + "first_introduced": "13", + "name": "OH_Drawing_FontArgumentsCreate" + }, + { + "first_introduced": "13", + "name": "OH_Drawing_FontArgumentsDestroy" + }, { "name": "OH_Drawing_FontCreate" }, { "name": "OH_Drawing_FontDestroy" }, { @@ -680,7 +692,15 @@ { "name": "OH_Drawing_MemoryStreamCreate" }, { "name": "OH_Drawing_MemoryStreamDestroy" }, { "name": "OH_Drawing_TypefaceCreateDefault" }, + { + "first_introduced": "13", + "name": "OH_Drawing_TypefaceCreateFromCurrent" + }, { "name": "OH_Drawing_TypefaceCreateFromFile" }, + { + "first_introduced": "13", + "name": "OH_Drawing_TypefaceCreateFromFileWithArguments" + }, { "name": "OH_Drawing_TypefaceCreateFromStream" }, { "name": "OH_Drawing_TypefaceDestroy" }, { "name": "OH_Drawing_CreateTypographyHandler" }, -- Gitee