diff --git a/graphic/graphic_2d/native_drawing/drawing_error_code.h b/graphic/graphic_2d/native_drawing/drawing_error_code.h index 0c6e6e0c8769442fa067a5aa242eee703eabfc9e..239f948173bbc8e79ec0c11be2b43bbe056b8747 100644 --- a/graphic/graphic_2d/native_drawing/drawing_error_code.h +++ b/graphic/graphic_2d/native_drawing/drawing_error_code.h @@ -70,6 +70,11 @@ typedef enum { * @since 13 */ OH_DRAWING_ERROR_ALLOCATION_FAILED = 26200002, + /** + * @error The attribute id is not recognized or supported. + * @since 21 + */ + OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH = 26200003, } OH_Drawing_ErrorCode; /** diff --git a/graphic/graphic_2d/native_drawing/drawing_text_typography.h b/graphic/graphic_2d/native_drawing/drawing_text_typography.h index 9bdf581f61da05374d9028e623b2e958a73126aa..633d974825bc2a08d652d30db03cb2e8235120d4 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_typography.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_typography.h @@ -48,6 +48,7 @@ #include #endif #include "drawing_canvas.h" +#include "drawing_error_code.h" #include "drawing_color.h" #include "drawing_font.h" #include "drawing_text_declaration.h" @@ -582,6 +583,180 @@ typedef enum OH_Drawing_FontWidth { FONT_WIDTH_ULTRA_EXPANDED = 9, } OH_Drawing_FontWidth; +/** + * @brief Enumerates text style attribute. + * + * @since 21 + */ +typedef enum OH_Drawing_TextStyleAttributeId { + /** Line height maximum */ + TEXT_STYLE_ATTR_D_LINE_HEIGHT_MAXIMUM = 0, + /** Line height minimum */ + TEXT_STYLE_ATTR_D_LINE_HEIGHT_MINIMUM = 1, + /** Line height style */ + TEXT_STYLE_ATTR_I_LINE_HEIGHT_STYLE = 2, + /** Font width */ + TEXT_STYLE_ATTR_I_FONT_WIDTH = 3, +} OH_Drawing_TextStyleAttributeId; + +/** + * @brief Enumerates line height's scaling type. + * + * @since 21 + */ +typedef enum OH_Drawing_LineHeightStyle { + /** Use the font size as the scale factor for line height scaling */ + TEXT_LINE_HEIGHT_BY_FONT_SIZE = 0, + /** Use the text height after shaping as the scale factor for line height scaling */ + TEXT_LINE_HEIGHT_BY_FONT_HEIGHT = 1, +} OH_Drawing_LineHeightStyle; + +/** + * @brief Enumerates typography style attribute. + * + * @since 21 + */ +typedef enum OH_Drawing_TypographyStyleAttributeId { + /** Line height maximum */ + TYPOGRAPHY_STYLE_ATTR_D_LINE_HEIGHT_MAXIMUM = 0, + /** Line height minimum */ + TYPOGRAPHY_STYLE_ATTR_D_LINE_HEIGHT_MINIMUM = 1, + /** Line spacing */ + TYPOGRAPHY_STYLE_ATTR_D_LINE_SPACING = 2, + /** Line height style */ + TYPOGRAPHY_STYLE_ATTR_I_LINE_HEIGHT_STYLE = 3, + /** Font width */ + TYPOGRAPHY_STYLE_ATTR_I_FONT_WIDTH = 4, +} OH_Drawing_TypographyStyleAttributeId; + +/** + * @brief Sets double value to the text style attribute. + * + * @param style Indicates the pointer to an OH_Drawing_TextStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the value to set. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * Returns {@link OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE} if the value corresponding to the attribute id + * exceeds the allowable range. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_SetTextStyleAttributeDouble(OH_Drawing_TextStyle* style, + OH_Drawing_TextStyleAttributeId id, double value); + +/** + * @brief Gets the double type property's value from the text style. + * + * @param style Indicates the pointer to an OH_Drawing_TextStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the return value of the interface. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_GetTextStyleAttributeDouble(OH_Drawing_TextStyle* style, + OH_Drawing_TextStyleAttributeId id, double* value); + +/** + * @brief Sets int value to the text style attribute. + * + * @param style Indicates the pointer to an OH_Drawing_TextStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the value to set. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * Returns {@link OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE} if the value corresponding to the attribute id + * exceeds the allowable range. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_SetTextStyleAttributeInt(OH_Drawing_TextStyle* style, + OH_Drawing_TextStyleAttributeId id, int value); + +/** + * @brief Gets the int type property's value from the text style. + * + * @param style Indicates the pointer to an OH_Drawing_TextStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the return value of the interface. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_GetTextStyleAttributeInt(OH_Drawing_TextStyle* style, + OH_Drawing_TextStyleAttributeId id, int* value); + +/** + * @brief Sets double value to the typography style attribute. + * + * @param style Indicates the pointer to an OH_Drawing_TypographyStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the value to set. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * Returns {@link OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE} if the value corresponding to the attribute id + * exceeds the allowable range. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeDouble(OH_Drawing_TypographyStyle* style, + OH_Drawing_TypographyStyleAttributeId id, double value); + +/** + * @brief Gets the double type property's value from the typography style. + * + * @param style Indicates the pointer to an OH_Drawing_TypographyStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the return value of the interface. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeDouble(OH_Drawing_TypographyStyle* style, + OH_Drawing_TypographyStyleAttributeId id, double* value); + +/** + * @brief Sets int value to the typography style attribute. + * + * @param style Indicates the pointer to an OH_Drawing_TypographyStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the value to set. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * Returns {@link OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE} if the value corresponding to the attribute id + * exceeds the allowable range. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeInt(OH_Drawing_TypographyStyle* style, + OH_Drawing_TypographyStyleAttributeId id, int value); + +/** + * @brief Gets the int type property's value from the typography style. + * + * @param style Indicates the pointer to an OH_Drawing_TypographyStyle object. + * @param id Indicates the attribute id. + * @param value Indicates the return value of the interface. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if the style is nullptr. + * Returns {@link OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH} if the attribute id is not recognized or supported. + * @since 21 + */ +OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeInt(OH_Drawing_TypographyStyle* style, + OH_Drawing_TypographyStyleAttributeId id, int* value); + /** * @brief Type of badge. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index 7472ebb07985bc1347f7f672324792cae5f576ec..dd7a437602384c555040754aab51efeed2b8a736 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -2037,5 +2037,37 @@ { "first_introduced": "20", "name": "OH_Drawing_FontFeaturesDestroy" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_SetTextStyleAttributeDouble" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_GetTextStyleAttributeDouble" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_SetTextStyleAttributeInt" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_GetTextStyleAttributeInt" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_SetTypographyStyleAttributeDouble" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_GetTypographyStyleAttributeDouble" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_SetTypographyStyleAttributeInt" + }, + { + "first_introduced": "21", + "name": "OH_Drawing_GetTypographyStyleAttributeInt" } ] \ No newline at end of file