From 80e3453fc52cf0db888719867127175cfa6100cd Mon Sep 17 00:00:00 2001 From: firminly Date: Thu, 8 Aug 2024 19:10:07 +0800 Subject: [PATCH] NDK C-API fix TDD Signed-off-by: liyi0309 Change-Id: I76b62ab3f88dbbc160c93c783821c14eeb7daab3 --- .../pattern/text/span_model_ng.cpp | 8 +++++++ .../pattern/text/span_model_ng.h | 1 + .../core/interfaces/arkoala/arkoala_api.h | 1 + .../native/node/node_span_modifier.cpp | 21 ++++++++++++++++++- interfaces/native/node/style_modifier.cpp | 9 ++++++-- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/frameworks/core/components_ng/pattern/text/span_model_ng.cpp b/frameworks/core/components_ng/pattern/text/span_model_ng.cpp index 85159a9cb3e..dbdf332f515 100644 --- a/frameworks/core/components_ng/pattern/text/span_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/text/span_model_ng.cpp @@ -429,4 +429,12 @@ std::vector SpanModelNG::GetTextShadow(UINode* uiNode) CHECK_NULL_RETURN(uiNode, defaultShadow); return spanNode->GetTextShadow().value_or(defaultShadow); } + +std::vector SpanModelNG::GetSpanFontFamily(UINode* uiNode) +{ + auto spanNode = AceType::DynamicCast(uiNode); + std::vector value; + CHECK_NULL_RETURN(spanNode, value); + return spanNode->GetFontFamily().value_or(value); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text/span_model_ng.h b/frameworks/core/components_ng/pattern/text/span_model_ng.h index bf91660f586..3c3aa7489cd 100644 --- a/frameworks/core/components_ng/pattern/text/span_model_ng.h +++ b/frameworks/core/components_ng/pattern/text/span_model_ng.h @@ -82,6 +82,7 @@ public: static std::vector GetTextShadow(UINode* uiNode); static void SetOnClick(UINode* uiNode, GestureEventFunc&& click); static void ClearOnClick(UINode* uiNode); + static std::vector GetSpanFontFamily(UINode* uiNode); #ifdef USE_GRAPHIC_TEXT_GINE // impl in render/adapter/span_model_adapter.cpp static RefPtr CreateSpanItem(ArkUI_SpanItem* item); diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 4c67c0b363c..5b16c1d007d 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -3983,6 +3983,7 @@ struct ArkUISpanModifier { void (*setTextShadow)(ArkUINodeHandle node, struct ArkUITextShadowStruct* shadows, ArkUI_Uint32 length); void (*resetTextShadow)(ArkUINodeHandle node); void (*getTextShadows)(ArkUINodeHandle node, ArkUITextShadowStruct* textShadow, ArkUI_Uint32 size); + ArkUI_CharPtr (*getSpanFontFamily)(ArkUINodeHandle node); }; struct ArkUISelectModifier { diff --git a/frameworks/core/interfaces/native/node/node_span_modifier.cpp b/frameworks/core/interfaces/native/node/node_span_modifier.cpp index acc452c513e..97cee623574 100644 --- a/frameworks/core/interfaces/native/node/node_span_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_span_modifier.cpp @@ -443,6 +443,25 @@ void ResetTextTextShadow(ArkUINodeHandle node) shadow.SetOffsetY(0.0); SpanModelNG::SetTextShadow(frameNode, std::vector { shadow }); } + +ArkUI_CharPtr GetSpanFontFamily(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_RETURN(frameNode, nullptr); + std::vector fontFamilies = SpanModelNG::GetSpanFontFamily(frameNode); + std::string families; + //set index start + uint32_t index = 0; + for (auto& family : fontFamilies) { + families += family; + if (index != fontFamilies.size() - 1) { + families += ","; + } + index++; + } + g_strValue = families; + return g_strValue.c_str(); +} } // namespace namespace NodeModifier { const ArkUISpanModifier* GetSpanModifier() @@ -455,7 +474,7 @@ const ArkUISpanModifier* GetSpanModifier() SetSpanFontWeightStr, GetSpanContent, GetSpanDecoration, GetSpanFontColor, GetSpanFontSize, GetSpanFontStyle, GetSpanFontWeight, GetSpanLineHeight, GetSpanTextCase, GetSpanLetterSpacing, GetSpanBaselineOffset, SetSpanTextBackgroundStyle, ResetSpanTextBackgroundStyle, GetSpanTextBackgroundStyle, SetTextTextShadow, - ResetTextTextShadow, GetTextShadow }; + ResetTextTextShadow, GetTextShadow, GetSpanFontFamily }; return &modifier; } } // namespace NodeModifier diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index c59c4a8018e..90552b6b186 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -7356,8 +7356,13 @@ int32_t SetTextFontFamily(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item const ArkUI_AttributeItem* GetTextFontFamily(ArkUI_NodeHandle node) { - auto resultValue = GetFullImpl()->getNodeModifiers()->getTextModifier()->getFontFamily(node->uiNodeHandle); - g_attributeItem.string = resultValue; + if (node->type == ARKUI_NODE_SPAN) { + auto resultValue = GetFullImpl()->getNodeModifiers()->getSpanModifier()->getSpanFontFamily(node->uiNodeHandle); + g_attributeItem.string = resultValue; + } else { + auto resultValue = GetFullImpl()->getNodeModifiers()->getTextModifier()->getFontFamily(node->uiNodeHandle); + g_attributeItem.string = resultValue; + } g_attributeItem.size = 0; return &g_attributeItem; }