diff --git a/frameworks/core/components_ng/pattern/text/text_model_ng.cpp b/frameworks/core/components_ng/pattern/text/text_model_ng.cpp index 369acfcbbc99c1e5ec3a63ea1a9a320b02b6cbf9..ad236b3327478f4dece905b136aa36590142d105 100644 --- a/frameworks/core/components_ng/pattern/text/text_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/text/text_model_ng.cpp @@ -1028,4 +1028,11 @@ void TextModelNG::SetHalfLeading(FrameNode* frameNode, bool halfLeading) { ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, HalfLeading, halfLeading, frameNode); } + +bool TextModelNG::GetHalfLeading(FrameNode* frameNode) +{ + bool value = false; + ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextLayoutProperty, HalfLeading, value, frameNode, value); + return value; +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/text/text_model_ng.h b/frameworks/core/components_ng/pattern/text/text_model_ng.h index 9154f2b635464eb162da3e2b2f0b528df9db4005..d07243cd9f307e19ed6e8bc21a6a1b3be0040819 100644 --- a/frameworks/core/components_ng/pattern/text/text_model_ng.h +++ b/frameworks/core/components_ng/pattern/text/text_model_ng.h @@ -166,6 +166,7 @@ public: static void SetSelectionMenuOptions(FrameNode* frameNode, const NG::OnCreateMenuCallback&& onCreateMenuCallback, const NG::OnMenuItemClickCallback&& onMenuItemClick); static void SetHalfLeading(FrameNode* frameNode, bool halfLeading); + static bool GetHalfLeading(FrameNode* frameNode); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 4c67c0b363c2f370b23a2fc0441b273f6edb500b..d48f2aaa524320822dffb9748d010f977cc6f639 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -26,10 +26,10 @@ extern "C" { #endif -#define ARKUI_FULL_API_VERSION 120 +#define ARKUI_FULL_API_VERSION 121 // When changing ARKUI_BASIC_API_VERSION, ARKUI_FULL_API_VERSION must be // increased as well. -#define ARKUI_NODE_API_VERSION 120 +#define ARKUI_NODE_API_VERSION 121 #define ARKUI_BASIC_API_VERSION 8 #define ARKUI_EXTENDED_API_VERSION 8 @@ -1996,6 +1996,7 @@ struct ArkUITextModifier { void (*resetTextSelectionMenuOptions)(ArkUINodeHandle node); void (*setTextHalfLeading)(ArkUINodeHandle node, ArkUI_Bool value); void (*resetTextHalfLeading)(ArkUINodeHandle node); + ArkUI_Int32 (*getTextHalfLeading)(ArkUINodeHandle node); }; struct ArkUIButtonModifier { diff --git a/frameworks/core/interfaces/native/node/node_text_modifier.cpp b/frameworks/core/interfaces/native/node/node_text_modifier.cpp index d1239e62d616dc1cb75e04ec75c3f0f808a9281c..4294549fbc3517a1eb173dde501f3f5ef5bb10b8 100644 --- a/frameworks/core/interfaces/native/node/node_text_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_text_modifier.cpp @@ -1075,6 +1075,13 @@ void ResetTextHalfLeading(ArkUINodeHandle node) CHECK_NULL_VOID(frameNode); TextModelNG::SetHalfLeading(frameNode, false); } + +ArkUI_Int32 GetTextHalfLeading(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_RETURN(frameNode, false); + return static_cast(TextModelNG::GetHalfLeading(frameNode)); +} } // namespace namespace NodeModifier { @@ -1194,7 +1201,8 @@ const ArkUITextModifier* GetTextModifier() SetTextSelectionMenuOptions, ResetTextSelectionMenuOptions, SetTextHalfLeading, - ResetTextHalfLeading + ResetTextHalfLeading, + GetTextHalfLeading }; return &modifier; diff --git a/interfaces/native/native_node.h b/interfaces/native/native_node.h index a80b9e03c7b67aa4520fd44c4c811c6cdce64c8e..b0c6b974e0863c9d1a714159a6ad3942ea9054cd 100644 --- a/interfaces/native/native_node.h +++ b/interfaces/native/native_node.h @@ -2022,6 +2022,18 @@ typedef enum { */ NODE_TEXT_CONTENT_WITH_STYLED_STRING, + /** + * @brief 设置文本居中显示。 + * + * 属性设置方法参数{@link ArkUI_AttributeItem}格式:\n + * .value[0].i32:文本是否居中,默认值false。\n + * \n + * 属性获取方法返回值{@link ArkUI_AttributeItem}格式:\n + * .value[0].i32:文本是否居中。\n + * + */ + NODE_TEXT_HALF_LEADING = 1029, + /** * @brief Defines the text content attribute, which can be set, reset, and obtained as required through APIs. * diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index fe4f14ab2c9647789bdd51af28978f4bb4a62ac2..3b4eba82f1ab6f21758c99fa5521920d45f8cf1f 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -9430,6 +9430,33 @@ void ResetTextContentWithStyledString(ArkUI_NodeHandle node) fullImpl->getNodeModifiers()->getTextModifier()->resetTextContentWithStyledString(node->uiNodeHandle); } +int32_t SetHalfLeading(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) +{ + auto actualSize = CheckAttributeItemArray(item, REQUIRED_ONE_PARAM); + if (actualSize < 0 || !InRegion(NUM_0, NUM_1, item->value[NUM_0].i32)) { + return ERROR_CODE_PARAM_INVALID; + } + // already check in entry point. + auto* fullImpl = GetFullImpl(); + fullImpl->getNodeModifiers()->getTextModifier()->setTextHalfLeading( + node->uiNodeHandle, item->value[NUM_0].i32); + return ERROR_CODE_NO_ERROR; +} + +const ArkUI_AttributeItem* GetHalfLeading(ArkUI_NodeHandle node) +{ + auto fullImpl = GetFullImpl(); + g_numberValues[0].i32 = fullImpl->getNodeModifiers()->getTextModifier()->getTextHalfLeading(node->uiNodeHandle); + g_attributeItem.size = REQUIRED_ONE_PARAM; + return &g_attributeItem; +} + +void ResetHalfLeading(ArkUI_NodeHandle node) +{ + auto* fullImpl = GetFullImpl(); + fullImpl->getNodeModifiers()->getTextModifier()->resetTextHalfLeading(node->uiNodeHandle); +} + const ArkUI_AttributeItem* GetTextEllipsisMode(ArkUI_NodeHandle node) { auto fullImpl = GetFullImpl(); @@ -12841,7 +12868,7 @@ int32_t SetTextAttribute(ArkUI_NodeHandle node, int32_t subTypeId, const ArkUI_A SetTextCopyOption, SetBaseLineOffset, SetTextShadow, SetTextMinFontSize, SetTextMaxFontSize, SetTextFont, SetTextHeightAdaptivePolicy, SetTextIndent, SetTextWordBreak, SetTextEllipsisMode, SetLineSpacing, SetFontFeature, SetTextEnableDateDetector, SetTextDataDetectorConfig, SetTextSelectedBackgroundColor, - SetTextContentWithStyledString }; + SetTextContentWithStyledString, SetHalfLeading }; if (static_cast(subTypeId) >= sizeof(setters) / sizeof(Setter*)) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "text node attribute: %{public}d NOT IMPLEMENT", subTypeId); return ERROR_CODE_NATIVE_IMPL_TYPE_NOT_SUPPORTED; @@ -12855,8 +12882,9 @@ const ArkUI_AttributeItem* GetTextAttribute(ArkUI_NodeHandle node, int32_t subTy GetDecoration, GetTextCase, GetLetterSpacing, GetMaxLines, GetTextAlign, GetTextOverflow, GetTextFontFamily, GetTextCopyOption, GetBaseLineOffset, GetTextShadow, GetTextMinFontSize, GetTextMaxFontSize, GetTextFont, GetTextHeightAdaptivePolicy, GetTextIndent, GetTextWordBreak, GetTextEllipsisMode, GetLineSpacing, - GetFontFeature, GetTextEnableDateDetector, GetTextDataDetectorConfig, GetTextSelectedBackgroundColor }; - if (static_cast(subTypeId) >= sizeof(getters) / sizeof(Getter*)) { + GetFontFeature, GetTextEnableDateDetector, GetTextDataDetectorConfig, GetTextSelectedBackgroundColor, nullptr, + GetHalfLeading }; + if (static_cast(subTypeId) >= sizeof(getters) / sizeof(Getter*) || !getters[subTypeId]) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "text node attribute: %{public}d NOT IMPLEMENT", subTypeId); return nullptr; } @@ -12871,7 +12899,7 @@ void ResetTextAttribute(ArkUI_NodeHandle node, int32_t subTypeId) ResetTextOverflow, ResetTextFontFamily, ResetTextCopyOption, ResetBaselineOffset, ResetTextShadow, ResetTextMinFontSize, ResetTextMaxFontSize, ResetTextFont, ResetTextHeightAdaptivePolicy, ResetTextIndent, ResetTextWordBreak, ResetTextEllipsisMode, ResetLineSpacing, ResetFontFeature, ResetTextEnableDateDetector, - ResetTextDataDetectorConfig, ResetTextSelectedBackgroundColor, ResetTextContentWithStyledString }; + ResetTextDataDetectorConfig, ResetTextSelectedBackgroundColor, ResetTextContentWithStyledString, ResetHalfLeading }; if (static_cast(subTypeId) >= sizeof(resetters) / sizeof(Resetter*)) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "text node attribute: %{public}d NOT IMPLEMENT", subTypeId); return;