From a6b7bea1e5f02729f1fab70f99dd5b0a7cc4e4d7 Mon Sep 17 00:00:00 2001 From: qsftw Date: Fri, 20 Jun 2025 02:49:55 +0000 Subject: [PATCH] add draw font feature interfaces Signed-off-by: qsftw Change-Id: I96f6aa81b08214f5e7780af150a432e7bb36ff0a --- .../native_drawing/drawing_canvas.h | 20 +++++++ .../graphic_2d/native_drawing/drawing_font.h | 59 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/graphic/graphic_2d/native_drawing/drawing_canvas.h b/graphic/graphic_2d/native_drawing/drawing_canvas.h index 8f515031b..c9d709db0 100644 --- a/graphic/graphic_2d/native_drawing/drawing_canvas.h +++ b/graphic/graphic_2d/native_drawing/drawing_canvas.h @@ -501,6 +501,26 @@ OH_Drawing_ErrorCode OH_Drawing_CanvasDrawNestedRoundRect(OH_Drawing_Canvas* can OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacter(OH_Drawing_Canvas* canvas, const char* str, const OH_Drawing_Font* font, float x, float y); +/** + * @brief Draws a single character with font feature. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param str Indicates the single character encoded in UTF-8. + * @param font Indicates the pointer to an OH_Drawing_Font object. + * @param x Indicates the horizontal offset applied to the single character. + * @param y Indicates the vertical offset applied to the single character. + * @param fontFeatures Indicates the pointer to an OH_Drawing_FontFeatures object. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of canvas, str, font + * or fontFeatures is nullptr, or if strlen(str) is 0. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacterWithFeatures(OH_Drawing_Canvas* canvas, const char* str, + const OH_Drawing_Font* font, float x, float y, OH_Drawing_FontFeatures* fontFeatures); + /** * @brief Draws a textblob. * diff --git a/graphic/graphic_2d/native_drawing/drawing_font.h b/graphic/graphic_2d/native_drawing/drawing_font.h index 69fb717ce..9d995c696 100644 --- a/graphic/graphic_2d/native_drawing/drawing_font.h +++ b/graphic/graphic_2d/native_drawing/drawing_font.h @@ -260,6 +260,24 @@ void OH_Drawing_FontGetWidths(const OH_Drawing_Font* font, const uint16_t* glyph OH_Drawing_ErrorCode OH_Drawing_FontMeasureSingleCharacter(const OH_Drawing_Font* font, const char* str, float* textWidth); +/** + * @brief Measures the width of a single character. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param font Indicates the pointer to an OH_Drawing_Font object. + * @param str Indicates the single character encoded in UTF-8. + * @param fontFeatures Indicates the pointer to an OH_Drawing_FontFeatures object. + * @param textWidth Indicates the width of the single character. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, str + * fontFeatures or textWidth is nullptr, or if strlen(str) is 0. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_FontMeasureSingleCharacterWithFeatures(const OH_Drawing_Font* font, const char* str, + const OH_Drawing_FontFeatures* fontFeatures, float* textWidth); + /** * @brief Measures the width of text. * @@ -629,6 +647,47 @@ OH_Drawing_ErrorCode OH_Drawing_FontGetPathForGlyph(const OH_Drawing_Font* font, OH_Drawing_ErrorCode OH_Drawing_FontGetTextPath(const OH_Drawing_Font* font, const void* text, size_t byteLength, OH_Drawing_TextEncoding encoding, float x, float y, OH_Drawing_Path* path); +/** + * @brief Creates an OH_Drawing_FontFeatures object + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * Returns the pointer to the OH_Drawing_FontFeatures object created. + * If nullptr is returned, the creation fails. + * The possible cause of the failure is that the available memory is empty. + * @since 20 + * @version 1.0 + */ +OH_Drawing_FontFeatures* OH_Drawing_FontFeaturesCreate(void); + +/** + * @brief Add a font feature for an OH_Drawing_FontFeatures object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param fontFeatures Indicates the pointer to an OH_Drawing_FontFeatures object. + * @param name Indicates the feature name. + * @param value Indicates the value of the feature. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if either fontFeatures or name is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_FontFeaturesAddFeature(OH_Drawing_FontFeatures* fontFeatures, + const char* name, float value); + +/** + * @brief Destroys an OH_Drawing_FontFeatures object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param fontFeatures Indicates the pointer to an OH_Drawing_FontFeatures object. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if fontFeatures is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_FontFeaturesDestroy(OH_Drawing_FontFeatures* fontFeatures); + /** * @brief Sets whether to follow the theme font. If the value is true, the theme font is used when typeface is not set. * -- Gitee