diff --git a/graphic/graphic_2d/native_drawing/drawing_canvas.h b/graphic/graphic_2d/native_drawing/drawing_canvas.h index 8f515031b2516c872b14e812a500cd1920a451ce..c9d709db00855bf3ef26695bfd7f06e6c47627c8 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 69fb717ce7e1a9dd83bc71c2b81b36a0547c2274..9d995c696d74e0cd22e9656c7bced839e54327b2 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. *