From 1fde828482224498b992ea5d0d858087fb5f55f3 Mon Sep 17 00:00:00 2001 From: wangxiuxiu96 Date: Fri, 12 Sep 2025 15:17:50 +0800 Subject: [PATCH] feat: text lineheight method add options and add max&minlineheight method Signed-off-by: wangxiuxiu96 --- .../ark_component/export/arkComponent.d.ts | 4 +- .../ark_component/src/ArkClassDefine.ts | 14 +++ .../ark_component/src/ArkText.ts | 55 ++++++++++- .../engine/arkComponent.js | 66 ++++++++++++- .../arkts_native_api_impl_bridge.cpp | 8 ++ .../nativeModule/arkts_native_text_bridge.cpp | 72 ++++++++++++++ .../nativeModule/arkts_native_text_bridge.h | 4 + .../declarative_frontend/jsview/js_text.cpp | 53 ++++++++++ .../declarative_frontend/jsview/js_text.h | 2 + .../components/common/properties/text_style.h | 57 +++++++++++ .../components/font/constants_converter.cpp | 35 ++++++- .../pattern/text/text_layout_property.cpp | 3 + .../pattern/text/text_layout_property.h | 3 + .../components_ng/pattern/text/text_model.h | 3 + .../pattern/text/text_model_ng.cpp | 50 ++++++++++ .../pattern/text/text_model_ng.h | 8 ++ .../pattern/text/text_pattern.cpp | 3 + .../pattern/text/text_styles.cpp | 6 ++ .../components_ng/pattern/text/text_styles.h | 3 + .../core/interfaces/arkoala/arkoala_api.h | 11 +++ frameworks/core/interfaces/cjui/cjui_api.h | 11 +++ .../native/node/node_text_modifier.cpp | 96 +++++++++++++++++++ interfaces/native/node/style_modifier.cpp | 62 +++++++++++- test/unittest/core/pattern/text/text_base.cpp | 9 ++ test/unittest/core/pattern/text/text_base.h | 3 + .../core/pattern/text/text_testeleven_ng.cpp | 6 ++ .../core/pattern/text/text_testthree_ng.cpp | 6 ++ .../core/pattern/text/text_testtwo_ng.cpp | 6 ++ 28 files changed, 645 insertions(+), 14 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_component/export/arkComponent.d.ts b/frameworks/bridge/declarative_frontend/ark_component/export/arkComponent.d.ts index 1fc096775fd..c167c32732c 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/export/arkComponent.d.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/export/arkComponent.d.ts @@ -742,7 +742,9 @@ declare class ArkTextComponent extends ArkComponent implements TextAttribute { fontStyle(value: FontStyle): TextAttribute; fontWeight(value: number | FontWeight | string): TextAttribute; textAlign(value: TextAlign): TextAttribute; - lineHeight(value: number | string | Resource): TextAttribute; + lineHeight(value: number | string | Resource, options?: LineHeightOptions): TextAttribute; + minLineHeight(value: LengthMetrics): TextAttribute; + maxLineHeight(value: LengthMetrics): TextAttribute; textOverflow(value: { overflow: TextOverflow; }): TextAttribute; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts index 6f0c81f6b88..28798bf792b 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts @@ -1910,6 +1910,20 @@ class ArkTextFont { } } +class ArkLineHeight { + value: number | string | Resource; + enableMultiply: boolean; + + constructor() { + this.value = undefined; + this.enableMultiply = false; + } + isEqual(another: ArkLineHeight): boolean { + return this.value === another.value && + this.enableMultiply === another.enableMultiply && + } +} + class ArkLineSpacing { value: LengthMetrics; onlyBetweenLines: boolean; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts index 4ec6f899d61..d5cd8af9842 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts @@ -322,18 +322,18 @@ class TextMaxFontScaleModifier extends ModifierWithKey { } } -class TextLineHeightModifier extends ModifierWithKey { - constructor(value: number | string | Resource) { +class TextLineHeightModifier extends ModifierWithKey { + constructor(value: ArkLineHeight) { super(value); } static identity: Symbol = Symbol('textLineHeight'); applyPeer(node: KNode, reset: boolean): void { if (reset) { getUINativeModule().text.resetLineHeight(node); - } else if (!isNumber(this.value) && !isString(this.value) && !isResource(this.value)) { + } else if (!isNumber(this.value.value) && !isString(this.value.value) && !isResource(this.value.value)) { getUINativeModule().text.resetLineHeight(node); } else { - getUINativeModule().text.setLineHeight(node, this.value!); + getUINativeModule().text.setLineHeight(node, this.value.value!, this.value.enableMultiply); } } @@ -342,6 +342,40 @@ class TextLineHeightModifier extends ModifierWithKey } } +class TextMaxLineHeightModifier extends ModifierWithKey { + constructor(value: LengthMetrics) { + super(value); + } + static identity: Symbol = Symbol('textMaxLineHeight'); + applyPeer(node, reset) { + if (reset) { + getUINativeModule().text.resetMaxLineHeight(node); + } else { + getUINativeModule().text.setMaxLineHeight(node, this.value); + } + } + checkObjectDiff() { + return !isBaseOrResourceEqual(this.stageValue, this.value); + } +} + +class TextMinLineHeightModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + static identity: Symbol = Symbol('textMinLineHeight'); + applyPeer(node, reset) { + if (reset) { + getUINativeModule().text.resetMinLineHeight(node); + } else { + getUINativeModule().text.setMinLineHeight(node, this.value); + } + } + checkObjectDiff() { + return !isBaseOrResourceEqual(this.stageValue, this.value); + } +} + class TextCopyOptionModifier extends ModifierWithKey { constructor(value: CopyOptions) { super(value); @@ -1037,7 +1071,18 @@ class ArkTextComponent extends ArkComponent implements TextAttribute { modifierWithKey(this._modifiersWithKeys, TextContentAlignModifier.identity, TextContentAlignModifier, value); return this; } - lineHeight(value: number | string | Resource): TextAttribute { + lineHeight(value: number | string | Resource, options?: LineHeightOptions): TextAttribute { + let arkLineHeight = new ArkLineHeight(); + arkLineHeight.value = value; + arkLineHeight.enableMultiply = options?.enableMultiply; + modifierWithKey(this._modifiersWithKeys, TextLineHeightModifier.identity, TextLineHeightModifier, arkLineHeight); + return this; + } + maxLineHeight(value: LengthMetrics): TextAttribute { + modifierWithKey(this._modifiersWithKeys, TextLineHeightModifier.identity, TextLineHeightModifier, value); + return this; + } + minLineHeight(value: LengthMetrics): TextAttribute { modifierWithKey(this._modifiersWithKeys, TextLineHeightModifier.identity, TextLineHeightModifier, value); return this; } diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index eb2562e14c7..21e5ff9436b 100755 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -13629,11 +13629,11 @@ class TextLineHeightModifier extends ModifierWithKey { if (reset) { getUINativeModule().text.resetLineHeight(node); } - else if (!isNumber(this.value) && !isString(this.value) && !isResource(this.value)) { + else if (!isNumber(this.value.value) && !isString(this.value.value) && !isResource(this.value.value)) { getUINativeModule().text.resetLineHeight(node); } else { - getUINativeModule().text.setLineHeight(node, this.value); + getUINativeModule().text.setLineHeight(node, this.value.value, this.value.enableMultiply); } } checkObjectDiff() { @@ -13641,6 +13641,38 @@ class TextLineHeightModifier extends ModifierWithKey { } } TextLineHeightModifier.identity = Symbol('textLineHeight'); +class TextMaxLineHeightModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().text.resetMaxLineHeight(node); + } else { + getUINativeModule().text.setMaxLineHeight(node, this.value); + } + } + checkObjectDiff() { + return !isBaseOrResourceEqual(this.stageValue, this.value); + } +} +TextMaxLineHeightModifier.identity = Symbol('textMaxLineHeight'); +class TextMinLineHeightModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().text.resetMinLineHeight(node); + } else { + getUINativeModule().text.setMinLineHeight(node, this.value); + } + } + checkObjectDiff() { + return !isBaseOrResourceEqual(this.stageValue, this.value); + } +} +TextMinLineHeightModifier.identity = Symbol('textMinLineHeight'); class TextCopyOptionModifier extends ModifierWithKey { constructor(value) { super(value); @@ -14388,8 +14420,19 @@ class ArkTextComponent extends ArkComponent { modifierWithKey(this._modifiersWithKeys, TextContentAlignModifier.identity, TextContentAlignModifier, value); return this; } - lineHeight(value) { - modifierWithKey(this._modifiersWithKeys, TextLineHeightModifier.identity, TextLineHeightModifier, value); + lineHeight(value, options) { + let arkLineHeight = new ArkLineHeight(); + arkLineHeight.value = value; + arkLineHeight.enableMultiply = options?.enableMultiply; + modifierWithKey(this._modifiersWithKeys, TextLineHeightModifier.identity, TextLineHeightModifier, arkLineHeight); + return this; + } + maxLineHeight(value) { + modifierWithKey(this._modifiersWithKeys, TextMaxLineHeightModifier.identity, TextMaxLineHeightModifier, value); + return this; + } + minLineHeight(value) { + modifierWithKey(this._modifiersWithKeys, TextMinLineHeightModifier.identity, TextMinLineHeightModifier, value); return this; } textOverflow(value) { @@ -20079,6 +20122,21 @@ class ArkTextFont { } } +class ArkLineHeight{ + constructor() { + this.value = undefined; + this.enableMultiply = undefined; + } + isEqual(another) { + return (this.value === another.value) && + (this.enableMultiply === another.enableMultiply); + } + + checkObjectDiff(another) { + return !this.isEqual(another); + } +} + class ArkLineSpacing { constructor() { this.value = undefined; diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp index 03026a15fe2..64c3fce5274 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp @@ -1473,6 +1473,14 @@ ArkUINativeModuleValue ArkUINativeModule::GetArkUINativeModule(ArkUIRuntimeCallI panda::FunctionRef::New(const_cast(vm), TextBridge::SetLineHeight)); text->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetLineHeight"), panda::FunctionRef::New(const_cast(vm), TextBridge::ResetLineHeight)); + text->Set(vm, panda::StringRef::NewFromUtf8(vm, "setMaxLineHeight"), + panda::FunctionRef::New(const_cast(vm), TextBridge::SetMaximumLineHeight)); + text->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetMaxLineHeight"), + panda::FunctionRef::New(const_cast(vm), TextBridge::ResetMaximumLineHeight)); + text->Set(vm, panda::StringRef::NewFromUtf8(vm, "setMinLineHeight"), + panda::FunctionRef::New(const_cast(vm), TextBridge::SetMinimumLineHeight)); + text->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetMinLineHeight"), + panda::FunctionRef::New(const_cast(vm), TextBridge::ResetMinimumLineHeight)); text->Set(vm, panda::StringRef::NewFromUtf8(vm, "setTextOverflow"), panda::FunctionRef::New(const_cast(vm), TextBridge::SetTextOverflow)); text->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetTextOverflow"), diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.cpp index 31f18f8e050..897b35b372a 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.cpp @@ -285,6 +285,7 @@ ArkUINativeModuleValue TextBridge::SetLineHeight(ArkUIRuntimeCallInfo* runtimeCa CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2); CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); CalcDimension lineHeight(0.0, DEFAULT_SPAN_FONT_UNIT); @@ -297,6 +298,12 @@ ArkUINativeModuleValue TextBridge::SetLineHeight(ArkUIRuntimeCallInfo* runtimeCa } GetArkUINodeModifiers()->getTextModifier()->setTextLineHeight( nativeNode, lineHeight.Value(), static_cast(lineHeight.Unit()), AceType::RawPtr(lineHeightObj)); + if (!thirdArg->IsUndefined() && !thirdArg.IsNull() && thirdArg->IsBoolean()) { + if (thirdArg->ToBoolean(vm)->Value()) { + GetArkUINodeModifiers()->getTextModifier()->setTextLineHeightMultiply(nativeNode, lineHeight.Value(), + static_cast(lineHeight.Unit()), AceType::RawPtr(lineHeightObj)); + } + } return panda::JSValueRef::Undefined(vm); } @@ -308,6 +315,71 @@ ArkUINativeModuleValue TextBridge::ResetLineHeight(ArkUIRuntimeCallInfo* runtime CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); GetArkUINodeModifiers()->getTextModifier()->resetTextLineHeight(nativeNode); + GetArkUINodeModifiers()->getTextModifier()->resetTextLineHeightMultiply(nativeNode); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue TextBridge::SetMinimumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); + CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + CalcDimension minimumlineHeight(0.0, DEFAULT_SPAN_FONT_UNIT); + RefPtr minimumlineHeightObj; + if (!ArkTSUtils::ParseJsLengthMetrics(vm, secondArg, minimumlineHeight, minimumlineHeightObj)) { + minimumlineHeight.Reset(); + } + if (minimumlineHeight.IsNegative()) { + minimumlineHeight.Reset(); + } + GetArkUINodeModifiers()->getTextModifier()->setTextMinimumLineHeight(nativeNode, minimumlineHeight.Value(), + static_cast(minimumlineHeight.Unit()), AceType::RawPtr(minimumlineHeightObj)); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue TextBridge::ResetMinimumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + GetArkUINodeModifiers()->getTextModifier()->resetTextMinimumLineHeight(nativeNode); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue TextBridge::SetMaximumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); + CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + CalcDimension maximumlineHeight(0.0, DEFAULT_SPAN_FONT_UNIT); + RefPtr maximumlineHeightObj; + if (!ArkTSUtils::ParseJsLengthMetrics(vm, secondArg, maximumlineHeight, maximumlineHeightObj)) { + maximumlineHeight.Reset(); + } + if (maximumlineHeight.IsNegative()) { + maximumlineHeight.Reset(); + } + GetArkUINodeModifiers()->getTextModifier()->setTextMaximumLineHeight(nativeNode, maximumlineHeight.Value(), + static_cast(maximumlineHeight.Unit()), AceType::RawPtr(maximumlineHeightObj)); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue TextBridge::ResetMaximumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + GetArkUINodeModifiers()->getTextModifier()->resetTextMaximumLineHeight(nativeNode); return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.h index 6f86377c717..bf69231429d 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.h @@ -35,6 +35,10 @@ public: static ArkUINativeModuleValue ResetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue SetMinimumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetMinimumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue SetMaximumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetMaximumLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetTextOverflow(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetTextOverflow(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetDecoration(ArkUIRuntimeCallInfo* runtimeCallInfo); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp index 540adb095f4..86c38bd5deb 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp @@ -557,6 +557,57 @@ void JSText::SetLineHeight(const JSCallbackInfo& info) value.Reset(); } TextModel::GetInstance()->SetLineHeight(value); + + if (info.Length() < 2) { + return; + } + auto jsonValue = info[1]; + UnRegisterResource("LineHeightMultiply"); + if (!jsonValue->IsObject()) { + return; + } + auto paramObject = JSRef::Cast(jsonValue); + auto param1 = paramObject->GetProperty("enableMultiply"); + if (param1->IsBoolean() && !param1->IsUndefined() && !param1->IsNull()) { + if (param1->ToBoolean()) { + if (SystemProperties::ConfigChangePerform() && resObj) { + RegisterResource("LineHeightMultiply", resObj, value); + } + TextModel::GetInstance()->SetLineHeightMultiply(value); + } + } +} + +void JSText::SetMinimumLineHeight(const JSCallbackInfo& info) +{ + CalcDimension value; + JSRef args = info[0]; + UnRegisterResource("MinimumLineHeight"); + RefPtr resObj; + if (ParseLengthMetricsToDimension(args, value, resObj)) { + if (SystemProperties::ConfigChangePerform() && resObj) { + RegisterResource("MinimumLineHeight", resObj, value); + } + } else { + value.Reset(); + } + TextModel::GetInstance()->SetMinimumLineHeight(value); +} + +void JSText::SetMaximumLineHeight(const JSCallbackInfo& info) +{ + CalcDimension value; + JSRef args = info[0]; + UnRegisterResource("MaximumLineHeight"); + RefPtr resObj; + if (ParseLengthMetricsToDimension(args, value, resObj) || value.IsNegative()) { + if (SystemProperties::ConfigChangePerform() && resObj) { + RegisterResource("MaximumLineHeight", resObj, value); + } + } else { + value.Reset(); + } + TextModel::GetInstance()->SetMaximumLineHeight(value); } void JSText::SetLineSpacing(const JSCallbackInfo& info) @@ -1307,6 +1358,8 @@ void JSText::JSBind(BindingTarget globalObj) JSClass::StaticMethod("enableAutoSpacing", &JSText::SetEnableAutoSpacing); JSClass::StaticMethod("textVerticalAlign", &JSText::SetTextVerticalAlign); JSClass::StaticMethod("shaderStyle", &JSText::SetShaderStyle); + JSClass::StaticMethod("maxLineHeight", &JSText::SetMaximumLineHeight); + JSClass::StaticMethod("minLineHeight", &JSText::SetMinimumLineHeight); JSClass::InheritAndBind(globalObj); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_text.h b/frameworks/bridge/declarative_frontend/jsview/js_text.h index 6a347fb947c..ae568876776 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_text.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_text.h @@ -49,6 +49,8 @@ public: static void SetTextContentAlign(const JSCallbackInfo& info); static void SetTextAlign(int32_t value); static void SetLineHeight(const JSCallbackInfo& info); + static void SetMinimumLineHeight(const JSCallbackInfo& info); + static void SetMaximumLineHeight(const JSCallbackInfo& info); static void SetLineSpacing(const JSCallbackInfo& info); static void SetOptimizeTrailingSpace(const JSCallbackInfo& info); static void SetShaderStyle(const JSCallbackInfo& info); diff --git a/frameworks/core/components/common/properties/text_style.h b/frameworks/core/components/common/properties/text_style.h index 94c6bcc7880..68360f8d16c 100644 --- a/frameworks/core/components/common/properties/text_style.h +++ b/frameworks/core/components/common/properties/text_style.h @@ -1039,6 +1039,60 @@ public: hasHeightOverride_ = hasHeightOverride; } + const Dimension& GetMinimumLineHeight() const + { + return minimumLineHeight_.value; + } + + void SetMinimumLineHeight(const Dimension& minimumLineHeight) + { + auto actualValue = minimumLineHeight.ConvertToPxDistribute(GetMinFontScale(), GetMaxFontScale(), + IsAllowScale()); + auto newValue = DimensionWithActual(minimumLineHeight, static_cast(actualValue)); + if (NearEqual(newValue, minimumLineHeight_)) { + return; + } + reLayoutTextStyleBitmap_.set(static_cast(TextStyleAttribute::HEIGHT_SCALE)); + reLayoutTextStyleBitmap_.set(static_cast(TextStyleAttribute::HEIGHT_ONLY)); + minimumLineHeight_ = newValue; + } + + const Dimension& GetMaximumLineHeight() const + { + return maximumLineHeight_.value; + } + + void SetMaximumLineHeight(const Dimension& maximumLineHeight) + { + auto actualValue = maximumLineHeight.ConvertToPxDistribute(GetMinFontScale(), GetMaxFontScale(), + IsAllowScale()); + auto newValue = DimensionWithActual(maximumLineHeight, static_cast(actualValue)); + if (NearEqual(newValue, maximumLineHeight_)) { + return; + } + reLayoutTextStyleBitmap_.set(static_cast(TextStyleAttribute::HEIGHT_SCALE)); + reLayoutTextStyleBitmap_.set(static_cast(TextStyleAttribute::HEIGHT_ONLY)); + maximumLineHeight_ = newValue; + } + + const Dimension& GetLineHeightMultiply() const + { + return lineHeightMultiply_.value; + } + + void SetLineHeightMultiply(const Dimension& lineHeightMultiply) + { + auto actualValue = lineHeightMultiply.ConvertToPxDistribute(GetMinFontScale(), GetMaxFontScale(), + IsAllowScale()); + auto newValue = DimensionWithActual(lineHeightMultiply, static_cast(actualValue)); + if (NearEqual(newValue, lineHeightMultiply_)) { + return; + } + reLayoutTextStyleBitmap_.set(static_cast(TextStyleAttribute::HEIGHT_SCALE)); + reLayoutTextStyleBitmap_.set(static_cast(TextStyleAttribute::HEIGHT_ONLY)); + lineHeightMultiply_ = newValue; + } + void SetTextDecoration(TextDecoration value) { std::vector array { value }; @@ -1326,6 +1380,9 @@ private: bool hasHeightOverride_ = false; bool adaptTextSize_ = false; bool adaptHeight_ = false; // whether adjust text size with height. + DimensionWithActual minimumLineHeight_; + DimensionWithActual maximumLineHeight_; + DimensionWithActual lineHeightMultiply_; RefPtr advancedTextStyle_; RefPtr symbolTextStyle_; diff --git a/frameworks/core/components/font/constants_converter.cpp b/frameworks/core/components/font/constants_converter.cpp index e8c9fb93596..9b1fa6a0dea 100644 --- a/frameworks/core/components/font/constants_converter.cpp +++ b/frameworks/core/components/font/constants_converter.cpp @@ -43,6 +43,9 @@ struct LineSpaceAndHeightInfo { double lineSpacingScale = 0.0; bool lineHeightOnly = false; bool lineSpacingOnly = false; + double minimumLineHeight = 0.0; + double maximumLineHeight = 0.0; + double lineHeightMultiply = 1.0; }; } // namespace @@ -469,6 +472,29 @@ void ConvertSpacingAndHeigh( } } +void CheckMinMaxLineHeight(const TextStyle& textStyle, Rosen::TextStyle& txtStyle, LineSpaceAndHeightInfo& info) +{ + double minimumLineHeight = NormalizeToPx(textStyle.GetMinimumLineHeight()); + double maximumLineHeight = NormalizeToPx(textStyle.GetMaximumLineHeight()); + double lineHeightMultiply = textStyle.GetLineHeightMultiply().Value(); + + if (minimumLineHeight > 0.0) { + info.minimumLineHeight = minimumLineHeight; + } + if (maximumLineHeight > 0.0) { + if (info.minimumLineHeight > 0.0) { + info.maximumLineHeight = std::max(maximumLineHeight, info.minimumLineHeight); + } else { + info.maximumLineHeight = maximumLineHeight; + } + } else { + info.maximumLineHeight = std::numeric_limits::max(); + } + if (lineHeightMultiply > 0.0) { + info.lineHeightMultiply = lineHeightMultiply; + } +} + void ConvertGradiantColor( const TextStyle& textStyle, const WeakPtr& context, Rosen::TextStyle& txtStyle, OHOS::Ace::FontForegroudGradiantColor & gradiantColor) @@ -597,7 +623,14 @@ void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& co } else { txtStyle.heightScale = 1; } - + CheckMinMaxLineHeight(textStyle, txtStyle, info); + txtStyle.minLineHeight = static_cast(info.minimumLineHeight); + txtStyle.maxLineHeight = static_cast(info.maximumLineHeight); + bool hasLineHeightOptions = textStyle.GetLineHeightMultiply() != Dimension(0); + if (hasLineHeightOptions) { + txtStyle.lineHeightStyle = Rosen::LineHeightStyle::kFontHeight; + txtStyle.heightScale = static_cast(info.lineHeightMultiply); + } // set font variant auto fontFeatures = textStyle.GetFontFeatures(); if (!fontFeatures.empty()) { diff --git a/frameworks/core/components_ng/pattern/text/text_layout_property.cpp b/frameworks/core/components_ng/pattern/text/text_layout_property.cpp index 25ee19b5d6c..df1a4ee9dd9 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_property.cpp +++ b/frameworks/core/components_ng/pattern/text/text_layout_property.cpp @@ -193,6 +193,9 @@ void TextLayoutProperty::ToJsonValue(std::unique_ptr& json, const Ins json->PutExtAttr("lineSpacing", GetLineSpacing().value_or(0.0_vp).ToString().c_str(), filter); json->PutExtAttr("onlyBetweenLines", GetIsOnlyBetweenLines().value_or(false) ? "true" : "false", filter); json->PutExtAttr("optimizeTrailingSpace", GetOptimizeTrailingSpace().value_or(false) ? "true" : "false", filter); + json->PutExtAttr("enableMultiply", HasLineHeightMultiply() ? "true" : "false", filter); + json->PutExtAttr("maxLineHeight", GetMaximumLineHeight().value_or(0.0_fp).ToString().c_str(), filter); + json->PutExtAttr("minLineHeight", GetMinimumLineHeight().value_or(0.0_fp).ToString().c_str(), filter); if (GetTextEffectStrategyValue(TextEffectStrategy::NONE) != TextEffectStrategy::NONE) { auto jsonNumericTransiton = JsonUtil::Create(true); diff --git a/frameworks/core/components_ng/pattern/text/text_layout_property.h b/frameworks/core/components_ng/pattern/text/text_layout_property.h index 850ab8f712d..90ae0b09dec 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_property.h +++ b/frameworks/core/components_ng/pattern/text/text_layout_property.h @@ -179,6 +179,9 @@ public: FontForegroudGradiantColor, FontForegroudGradiantColor, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_GROUP(TextLineStyle, TextLineStyle); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, LineHeight, Dimension, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, LineHeightMultiply, Dimension, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, MinimumLineHeight, Dimension, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, MaximumLineHeight, Dimension, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, LineSpacing, Dimension, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, IsOnlyBetweenLines, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, OptimizeTrailingSpace, bool, PROPERTY_UPDATE_MEASURE); diff --git a/frameworks/core/components_ng/pattern/text/text_model.h b/frameworks/core/components_ng/pattern/text/text_model.h index 136555bb89c..5c76d0d5d99 100644 --- a/frameworks/core/components_ng/pattern/text/text_model.h +++ b/frameworks/core/components_ng/pattern/text/text_model.h @@ -218,6 +218,9 @@ public: virtual void SetColorShaderStyle(const Color& value) = 0; virtual void ResetGradientShaderStyle() = 0; virtual void SetTextVerticalAlign(TextVerticalAlign verticalAlign) = 0; + virtual void SetLineHeightMultiply(const Dimension& value) {}; + virtual void SetMinimumLineHeight(const Dimension& value) {}; + virtual void SetMaximumLineHeight(const Dimension& value) {}; private: static std::unique_ptr instance_; 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 a0c31567542..35ed4e791fe 100644 --- a/frameworks/core/components_ng/pattern/text/text_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/text/text_model_ng.cpp @@ -360,6 +360,36 @@ void TextModelNG::SetLineHeight(FrameNode* frameNode, const Dimension& value) ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, LineHeight, value, frameNode); } +void TextModelNG::SetLineHeightMultiply(const Dimension& value) +{ + ACE_UPDATE_LAYOUT_PROPERTY(TextLayoutProperty, LineHeightMultiply, value); +} + +void TextModelNG::SetLineHeightMultiply(FrameNode* frameNode, const Dimension& value) +{ + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, LineHeightMultiply, value, frameNode); +} + +void TextModelNG::SetMinimumLineHeight(const Dimension& value) +{ + ACE_UPDATE_LAYOUT_PROPERTY(TextLayoutProperty, MinimumLineHeight, value); +} + +void TextModelNG::SetMinimumLineHeight(FrameNode* frameNode, const Dimension& value) +{ + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, MinimumLineHeight, value, frameNode); +} + +void TextModelNG::SetMaximumLineHeight(const Dimension& value) +{ + ACE_UPDATE_LAYOUT_PROPERTY(TextLayoutProperty, MaximumLineHeight, value); +} + +void TextModelNG::SetMaximumLineHeight(FrameNode* frameNode, const Dimension& value) +{ + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, MaximumLineHeight, value, frameNode); +} + void TextModelNG::SetLineSpacing(const Dimension& value) { ACE_UPDATE_LAYOUT_PROPERTY(TextLayoutProperty, LineSpacing, value); @@ -884,6 +914,26 @@ float TextModelNG::GetLineHeight(FrameNode* frameNode) return static_cast(value.Value()); } +float TextModelNG::GetTextMaximumLineHeight(FrameNode* frameNode) +{ + CHECK_NULL_RETURN(frameNode, 0.0f); + auto layoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(layoutProperty, 0.0f); + Dimension defaultLineHeight(0); + auto value = layoutProperty->GetMaximumLineHeight().value_or(defaultLineHeight); + return static_cast(value.Value()); +} + +float TextModelNG::GetTextMinimumLineHeight(FrameNode* frameNode) +{ + CHECK_NULL_RETURN(frameNode, 0.0f); + auto layoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(layoutProperty, 0.0f); + Dimension defaultLineHeight(0); + auto value = layoutProperty->GetMinimumLineHeight().value_or(defaultLineHeight); + return static_cast(value.Value()); +} + float TextModelNG::GetLineSpacing(FrameNode* frameNode) { CHECK_NULL_RETURN(frameNode, 0.0f); 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 7228c4e46e5..95bdb9a91d5 100644 --- a/frameworks/core/components_ng/pattern/text/text_model_ng.h +++ b/frameworks/core/components_ng/pattern/text/text_model_ng.h @@ -53,6 +53,9 @@ public: void SetMaxLines(uint32_t value) override; void SetTextIndent(const Dimension& value) override; void SetLineHeight(const Dimension& value) override; + void SetLineHeightMultiply(const Dimension& value) override; + void SetMinimumLineHeight(const Dimension& value) override; + void SetMaximumLineHeight(const Dimension& value) override; void SetLineSpacing(const Dimension& value) override; void SetIsOnlyBetweenLines(bool isOnlyBetweenLines) override; void SetTextDecoration(TextDecoration value) override; @@ -116,6 +119,9 @@ public: static void ResetTextColor(FrameNode* frameNode); static void SetFontSize(FrameNode* frameNode, const Dimension& value); static void SetLineHeight(FrameNode* frameNode, const Dimension& value); + static void SetLineHeightMultiply(FrameNode* frameNode, const Dimension& value); + static void SetMinimumLineHeight(FrameNode* frameNode, const Dimension& value); + static void SetMaximumLineHeight(FrameNode* frameNode, const Dimension& value); static void SetLineSpacing(FrameNode* frameNode, const Dimension& value, bool isOnlyBetweenLines); static void SetTextOverflow(FrameNode* frameNode, TextOverflow value); static void SetTextDecoration(FrameNode* frameNode, TextDecoration value); @@ -158,6 +164,8 @@ public: static Font GetFont(FrameNode* frameNode); static std::u16string GetContent(FrameNode* frameNode); static float GetLineHeight(FrameNode* frameNode); + static float GetTextMaximumLineHeight(FrameNode* frameNode); + static float GetTextMinimumLineHeight(FrameNode* frameNode); static float GetLineSpacing(FrameNode* frameNode); static TextDecoration GetDecoration(FrameNode* frameNode); static Color GetTextDecorationColor(FrameNode* frameNode); diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.cpp b/frameworks/core/components_ng/pattern/text/text_pattern.cpp index 14780293e39..ae014a8e64e 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text/text_pattern.cpp @@ -6805,6 +6805,9 @@ void TextPattern::UpdatePropertyImpl(const std::string& key, RefPtr& property, TextStyle UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, BaselineOffset, BaselineOffset); UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, TextIndent, TextIndent); UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, LineSpacing, LineSpacing); + UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, LineHeightMultiply, LineHeightMultiply); + UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, MinimumLineHeight, MinimumLineHeight); + UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, MaximumLineHeight, MaximumLineHeight); UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, TextBaseline, TextBaseline); UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, TextOverflow, TextOverflow); UPDATE_TEXT_STYLE_WITH_THEME(textLineStyle, TextAlign, TextAlign); @@ -154,6 +157,9 @@ void UseSelfStyle(const std::unique_ptr& fontStyle, const std::unique } if (textLineStyle) { UPDATE_TEXT_STYLE(textLineStyle, LineHeight, SetLineHeight); + UPDATE_TEXT_STYLE(textLineStyle, MinimumLineHeight, SetMinimumLineHeight); + UPDATE_TEXT_STYLE(textLineStyle, MaximumLineHeight, SetMaximumLineHeight); + UPDATE_TEXT_STYLE(textLineStyle, LineHeightMultiply, SetLineHeightMultiply); UPDATE_TEXT_STYLE(textLineStyle, BaselineOffset, SetBaselineOffset); UPDATE_TEXT_STYLE(textLineStyle, TextIndent, SetTextIndent); UPDATE_TEXT_STYLE(textLineStyle, LineSpacing, SetLineSpacing); diff --git a/frameworks/core/components_ng/pattern/text/text_styles.h b/frameworks/core/components_ng/pattern/text/text_styles.h index 5259d423700..67b6fe4caf0 100644 --- a/frameworks/core/components_ng/pattern/text/text_styles.h +++ b/frameworks/core/components_ng/pattern/text/text_styles.h @@ -262,6 +262,9 @@ struct TextLineStyle { ACE_DEFINE_PROPERTY_GROUP_ITEM(ParagraphSpacing, Dimension); ACE_DEFINE_PROPERTY_GROUP_ITEM(OptimizeTrailingSpace, bool); ACE_DEFINE_PROPERTY_GROUP_ITEM(TextContentAlign, TextContentAlign); + ACE_DEFINE_PROPERTY_GROUP_ITEM(LineHeightMultiply, Dimension); + ACE_DEFINE_PROPERTY_GROUP_ITEM(MinimumLineHeight, Dimension); + ACE_DEFINE_PROPERTY_GROUP_ITEM(MaximumLineHeight, Dimension); }; struct HandleInfoNG { diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 0eb1bd41151..3e54678868e 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -2962,6 +2962,17 @@ struct ArkUITextModifier { void (*resetFontSize)(ArkUINodeHandle node); void (*setTextLineHeight)(ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* lineHeightRawPtr); void (*resetTextLineHeight)(ArkUINodeHandle node); + void (*setTextLineHeightMultiply)( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* lineHeightMultiplyRawPtr); + void (*resetTextLineHeightMultiply)(ArkUINodeHandle node); + void (*setTextMinimumLineHeight)( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* minimumlineHeightRawPtr); + ArkUI_Float32 (*getTextMinimumLineHeight)(ArkUINodeHandle node); + void (*resetTextMinimumLineHeight)(ArkUINodeHandle node); + void (*setTextMaximumLineHeight)( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* maximumlineHeightRawPtr); + ArkUI_Float32 (*getTextMaximumLineHeight)(ArkUINodeHandle node); + void (*resetTextMaximumLineHeight)(ArkUINodeHandle node); void (*setTextOverflow)(ArkUINodeHandle node, ArkUI_Int32 value); void (*resetTextOverflow)(ArkUINodeHandle node); void (*setTextDecoration)( diff --git a/frameworks/core/interfaces/cjui/cjui_api.h b/frameworks/core/interfaces/cjui/cjui_api.h index ce93bd87bef..0f6902d638a 100644 --- a/frameworks/core/interfaces/cjui/cjui_api.h +++ b/frameworks/core/interfaces/cjui/cjui_api.h @@ -582,6 +582,17 @@ struct CJUITextModifier { void (*resetFontSize)(ArkUINodeHandle node); void (*setTextLineHeight)(ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* lineHeightRawPtr); void (*resetTextLineHeight)(ArkUINodeHandle node); + void (*setTextLineHeightMultiply)( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* lineHeightMultiplyRawPtr); + void (*resetTextLineHeightMultiply)(ArkUINodeHandle node); + void (*setTextMinimumLineHeight)( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* minimumlineHeightRawPtr); + ArkUI_Float32 (*getTextMinimumLineHeight)(ArkUINodeHandle node); + void (*resetTextMinimumLineHeight)(ArkUINodeHandle node); + void (*setTextMaximumLineHeight)( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* maximumlineHeightRawPtr); + ArkUI_Float32 (*getTextMaximumLineHeight)(ArkUINodeHandle node); + void (*resetTextMaximumLineHeight)(ArkUINodeHandle node); void (*setTextOverflow)(ArkUINodeHandle node, ArkUI_Int32 value); void (*resetTextOverflow)(ArkUINodeHandle node); void (*setTextDecoration)(ArkUINodeHandle node, ArkUI_Int32 decoration, ArkUI_Uint32 color, diff --git a/frameworks/core/interfaces/native/node/node_text_modifier.cpp b/frameworks/core/interfaces/native/node/node_text_modifier.cpp index be655ac77e5..ce2d61fc473 100644 --- a/frameworks/core/interfaces/native/node/node_text_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_text_modifier.cpp @@ -377,6 +377,86 @@ void ResetTextLineHeight(ArkUINodeHandle node) } } +void SetTextLineHeightMultiply( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* lineHeightMultiplyRawPtr) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + TextModelNG::SetLineHeightMultiply(frameNode, Dimension(number, static_cast(unit))); + NodeModifier::ProcessResourceObj( + frameNode, "LineHeightMultiply", Dimension(number, static_cast(unit)), lineHeightMultiplyRawPtr); +} + +void ResetTextLineHeightMultiply(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + TextModelNG::SetLineHeightMultiply(frameNode, DEFAULT_LINE_HEIGHT); + if (SystemProperties::ConfigChangePerform()) { + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->UnRegisterResource("LineHeightMultiply"); + } +} + +void SetTextMinimumLineHeight( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* minimumlineHeightRawPtr) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + TextModelNG::SetMinimumLineHeight(frameNode, Dimension(number, static_cast(unit))); + NodeModifier::ProcessResourceObj( + frameNode, "MinimumLineHeight", Dimension(number, static_cast(unit)), minimumlineHeightRawPtr); +} + +float GetTextMinimumLineHeight(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_RETURN(frameNode, 0.0f); + return TextModelNG::GetTextMinimumLineHeight(frameNode); +} + +void ResetTextMinimumLineHeight(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + TextModelNG::SetMinimumLineHeight(frameNode, DEFAULT_LINE_HEIGHT); + if (SystemProperties::ConfigChangePerform()) { + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->UnRegisterResource("MinimumLineHeight"); + } +} + +void SetTextMaximumLineHeight( + ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit, void* maximumlineHeightRawPtr) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + TextModelNG::SetMaximumLineHeight(frameNode, Dimension(number, static_cast(unit))); + NodeModifier::ProcessResourceObj( + frameNode, "MaximumLineHeight", Dimension(number, static_cast(unit)), maximumlineHeightRawPtr); +} + +float GetTextMaximumLineHeight(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_RETURN(frameNode, 0.0f); + return TextModelNG::GetTextMaximumLineHeight(frameNode); +} + +void ResetTextMaximumLineHeight(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + TextModelNG::SetMaximumLineHeight(frameNode, DEFAULT_LINE_HEIGHT); + if (SystemProperties::ConfigChangePerform()) { + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->UnRegisterResource("MaximumLineHeight"); + } +} + void SetTextTextOverflow(ArkUINodeHandle node, ArkUI_Int32 value) { auto* frameNode = reinterpret_cast(node); @@ -1871,6 +1951,14 @@ const ArkUITextModifier* GetTextModifier() .resetFontSize = ResetFontSize, .setTextLineHeight = SetTextLineHeight, .resetTextLineHeight = ResetTextLineHeight, + .setTextLineHeightMultiply = SetTextLineHeightMultiply, + .resetTextLineHeightMultiply = ResetTextLineHeightMultiply, + .setTextMinimumLineHeight = SetTextMinimumLineHeight, + .getTextMinimumLineHeight = GetTextMinimumLineHeight, + .resetTextMinimumLineHeight = ResetTextMinimumLineHeight, + .setTextMaximumLineHeight = SetTextMaximumLineHeight, + .getTextMaximumLineHeight = GetTextMaximumLineHeight, + .resetTextMaximumLineHeight = ResetTextMaximumLineHeight, .setTextOverflow = SetTextTextOverflow, .resetTextOverflow = ResetTextTextOverflow, .setTextDecoration = SetTextDecoration, @@ -2029,6 +2117,14 @@ const CJUITextModifier* GetCJUITextModifier() .resetFontSize = ResetFontSize, .setTextLineHeight = SetTextLineHeight, .resetTextLineHeight = ResetTextLineHeight, + .setTextLineHeightMultiply = SetTextLineHeightMultiply, + .resetTextLineHeightMultiply = ResetTextLineHeightMultiply, + .setTextMinimumLineHeight = SetTextMinimumLineHeight, + .getTextMinimumLineHeight = GetTextMinimumLineHeight, + .resetTextMinimumLineHeight = ResetTextMinimumLineHeight, + .setTextMaximumLineHeight = SetTextMaximumLineHeight, + .getTextMaximumLineHeight = GetTextMaximumLineHeight, + .resetTextMaximumLineHeight = ResetTextMaximumLineHeight, .setTextOverflow = SetTextTextOverflow, .resetTextOverflow = ResetTextTextOverflow, .setTextDecoration = SetTextDecoration, diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index d2439150dfb..541e18acc03 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -11905,6 +11905,60 @@ void ResetTextContentAlign(ArkUI_NodeHandle node) fullImpl->getNodeModifiers()->getTextModifier()->resetTextContentAlign(node->uiNodeHandle); } +int32_t SetMaxLineHeight(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) +{ + auto* fullImpl = GetFullImpl(); + auto actualSize = CheckAttributeItemArray(item, REQUIRED_ONE_PARAM); + if (actualSize < 0) { + return ERROR_CODE_PARAM_INVALID; + } + int32_t unit = GetDefaultUnit(node, UNIT_FP); + fullImpl->getNodeModifiers()->getTextModifier()->setTextMaximumLineHeight( + node->uiNodeHandle, item->value[0].f32, unit, nullptr); + return ERROR_CODE_NO_ERROR; +} + +int32_t SetMinLineHeight(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) +{ + auto* fullImpl = GetFullImpl(); + auto actualSize = CheckAttributeItemArray(item, REQUIRED_ONE_PARAM); + if (actualSize < 0) { + return ERROR_CODE_PARAM_INVALID; + } + int32_t unit = GetDefaultUnit(node, UNIT_FP); + fullImpl->getNodeModifiers()->getTextModifier()->setTextMinimumLineHeight( + node->uiNodeHandle, item->value[0].f32, unit, nullptr); + return ERROR_CODE_NO_ERROR; +} + +const ArkUI_AttributeItem* GetMaxLineHeight(ArkUI_NodeHandle node) +{ + auto fullImpl = GetFullImpl(); + g_numberValues[0].f32 = fullImpl->getNodeModifiers()->getTextModifier()->getTextMaximumLineHeight(node->uiNodeHandle); + g_attributeItem.size = REQUIRED_ONE_PARAM; + return &g_attributeItem; +} + +const ArkUI_AttributeItem* GetMinLineHeight(ArkUI_NodeHandle node) +{ + auto fullImpl = GetFullImpl(); + g_numberValues[0].f32 = fullImpl->getNodeModifiers()->getTextModifier()->getTextMinimumLineHeight(node->uiNodeHandle); + g_attributeItem.size = REQUIRED_ONE_PARAM; + return &g_attributeItem; +} + +void ResetMinLineHeight(ArkUI_NodeHandle node) +{ + auto fullImpl = GetFullImpl(); + fullImpl->getNodeModifiers()->getTextModifier()->resetTextMinimumLineHeight(node->uiNodeHandle); +} + +void ResetMaxLineHeight(ArkUI_NodeHandle node) +{ + auto fullImpl = GetFullImpl(); + fullImpl->getNodeModifiers()->getTextModifier()->resetTextMaximumLineHeight(node->uiNodeHandle); +} + const ArkUI_AttributeItem* GetTextEllipsisMode(ArkUI_NodeHandle node) { auto fullImpl = GetFullImpl(); @@ -16700,7 +16754,8 @@ int32_t SetTextAttribute(ArkUI_NodeHandle node, int32_t subTypeId, const ArkUI_A SetTextHeightAdaptivePolicy, SetTextIndent, SetTextWordBreak, SetTextEllipsisMode, SetLineSpacing, SetFontFeature, SetTextEnableDateDetector, SetTextDataDetectorConfig, SetTextSelectedBackgroundColor, SetTextContentWithStyledString, SetHalfLeading, SetImmutableFontWeight, SetLineCount, SetOptimizeTrailingSpace, - SetTextLinearGradient, SetTextRadialGradient, SetTextVerticalAlign, SetTextContentAlign }; + SetTextLinearGradient, SetTextRadialGradient, SetTextVerticalAlign, SetTextContentAlign, SetMinLineHeight, + SetMaxLineHeight }; 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; @@ -16716,7 +16771,7 @@ const ArkUI_AttributeItem* GetTextAttribute(ArkUI_NodeHandle node, int32_t subTy GetTextHeightAdaptivePolicy, GetTextIndent, GetTextWordBreak, GetTextEllipsisMode, GetLineSpacing, GetFontFeature, GetTextEnableDateDetector, GetTextDataDetectorConfig, GetTextSelectedBackgroundColor, nullptr, GetHalfLeading, GetFontWeight, GetLineCount, GetOptimizeTrailingSpace, GetTextLinearGradient, - GetTextRadialGradient, GetTextVerticalAlign, GetTextContentAlign }; + GetTextRadialGradient, GetTextVerticalAlign, GetTextContentAlign, GetMinLineHeight, GetMaxLineHeight }; 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; @@ -16734,7 +16789,8 @@ void ResetTextAttribute(ArkUI_NodeHandle node, int32_t subTypeId) ResetTextWordBreak, ResetTextEllipsisMode, ResetLineSpacing, ResetFontFeature, ResetTextEnableDateDetector, ResetTextDataDetectorConfig, ResetTextSelectedBackgroundColor, ResetTextContentWithStyledString, ResetHalfLeading, ResetFontWeight, ResetLineCount, ResetOptimizeTrailingSpace, ResetTextLinearGradient, - ResetTextRadialGradient, ResetTextVerticalAlign, ResetTextContentAlign }; + ResetTextRadialGradient, ResetTextVerticalAlign, ResetTextContentAlign, ResetMinLineHeight, + ResetMaxLineHeight }; if (static_cast(subTypeId) >= sizeof(resetters) / sizeof(Resetter*)) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "text node attribute: %{public}d NOT IMPLEMENT", subTypeId); return; diff --git a/test/unittest/core/pattern/text/text_base.cpp b/test/unittest/core/pattern/text/text_base.cpp index 9b872c186e5..85027833c9e 100644 --- a/test/unittest/core/pattern/text/text_base.cpp +++ b/test/unittest/core/pattern/text/text_base.cpp @@ -209,6 +209,15 @@ RefPtr TextBases::CreateTextParagraph(const std::u16string& createVal if (testProperty.lineHeightValue.has_value()) { textModel.SetLineHeight(testProperty.lineHeightValue.value()); } + if (testProperty.lineHeightMultiply.has_value()) { + textModel.SetLineHeightMultiply(testProperty.lineHeightMultiply.value()); + } + if (testProperty.minimumLineHeight.has_value()) { + textModel.SetMinimumLineHeight(testProperty.minimumLineHeight.value()); + } + if (testProperty.maximumLineHeight.has_value()) { + textModel.SetMaximumLineHeight(testProperty.maximumLineHeight.value()); + } if (testProperty.lineSpacingValue.has_value()) { textModel.SetLineSpacing(testProperty.lineSpacingValue.value()); } diff --git a/test/unittest/core/pattern/text/text_base.h b/test/unittest/core/pattern/text/text_base.h index 6da1ced7a9c..91903dd78cd 100644 --- a/test/unittest/core/pattern/text/text_base.h +++ b/test/unittest/core/pattern/text/text_base.h @@ -162,6 +162,9 @@ struct TestProperty { std::optional textOverflowValue = std::nullopt; std::optional maxLinesValue = std::nullopt; std::optional lineHeightValue = std::nullopt; + std::optional lineHeightMultiply = std::nullopt; + std::optional minimumLineHeight = std::nullopt; + std::optional maximumLineHeight = std::nullopt; std::optional lineSpacingValue = std::nullopt; std::optional isOnlyBetweenLines = std::nullopt; std::optional textDecorationValue = std::nullopt; diff --git a/test/unittest/core/pattern/text/text_testeleven_ng.cpp b/test/unittest/core/pattern/text/text_testeleven_ng.cpp index 76b39e771f5..ac9227ad8e6 100644 --- a/test/unittest/core/pattern/text/text_testeleven_ng.cpp +++ b/test/unittest/core/pattern/text/text_testeleven_ng.cpp @@ -1050,6 +1050,9 @@ HWTEST_F(TextTestNg, GetSpanItemAttributeUseForHtml, TestSize.Level1) textStyle->SetFontSize(Dimension(NG::TEXT_DEFAULT_FONT_SIZE)); textStyle->SetFontWeight(FontWeight::MEDIUM); textStyle->SetLineHeight(Dimension(2.2)); + textStyle->SetLineHeightMultiply(Dimension(2.2)); + textStyle->SetMaximumLineHeight(Dimension(2.2)); + textStyle->SetMinimumLineHeight(Dimension(2.2)); NG::FontStyle fontStyle; NG::TextLineStyle textLineStyle; /** @@ -1059,6 +1062,9 @@ HWTEST_F(TextTestNg, GetSpanItemAttributeUseForHtml, TestSize.Level1) EXPECT_EQ(fontStyle.GetFontSize(), Dimension(NG::TEXT_DEFAULT_FONT_SIZE)); EXPECT_EQ(fontStyle.GetFontWeight(), FontWeight::MEDIUM); EXPECT_EQ(textLineStyle.GetLineHeight(), Dimension(2.2)); + EXPECT_EQ(textLineStyle.GetLineHeightMultiply(), Dimension(2.2)); + EXPECT_EQ(textLineStyle.GetMaximumLineHeight(), Dimension(2.2)); + EXPECT_EQ(textLineStyle.GetMinimumLineHeight(), Dimension(2.2)); } /** diff --git a/test/unittest/core/pattern/text/text_testthree_ng.cpp b/test/unittest/core/pattern/text/text_testthree_ng.cpp index 580eb2ea438..b9412689f23 100644 --- a/test/unittest/core/pattern/text/text_testthree_ng.cpp +++ b/test/unittest/core/pattern/text/text_testthree_ng.cpp @@ -2124,6 +2124,9 @@ HWTEST_F(TextTestThreeNg, TextModelNgProperty001, TestSize.Level1) TextModelNG::SetTextColor(node, Color::RED); TextModelNG::SetFontSize(node, FONT_SIZE_VALUE); TextModelNG::SetLineHeight(node, ADAPT_LINE_HEIGHT_VALUE); + TextModelNG::SetLineHeightMultiply(node, ADAPT_LINE_HEIGHT_VALUE); + TextModelNG::SetMaximumLineHeight(node, ADAPT_LINE_HEIGHT_VALUE); + TextModelNG::SetMinimumLineHeight(node, ADAPT_LINE_HEIGHT_VALUE); TextModelNG::SetTextOverflow(node, TextOverflow::ELLIPSIS); TextModelNG::SetTextDecoration(node, TextDecoration::UNDERLINE); TextModelNG::SetTextDecorationColor(node, Color::BLACK); @@ -2142,6 +2145,9 @@ HWTEST_F(TextTestThreeNg, TextModelNgProperty001, TestSize.Level1) EXPECT_EQ(layoutProperty->GetTextColor().value(), Color::RED); EXPECT_EQ(layoutProperty->GetFontSize().value(), FONT_SIZE_VALUE); EXPECT_EQ(layoutProperty->GetLineHeight().value(), ADAPT_LINE_HEIGHT_VALUE); + EXPECT_EQ(layoutProperty->GetLineHeightMultiply().value(), ADAPT_LINE_HEIGHT_VALUE); + EXPECT_EQ(layoutProperty->GetMaximumLineHeight().value(), ADAPT_LINE_HEIGHT_VALUE); + EXPECT_EQ(layoutProperty->GetMinimumLineHeight().value(), ADAPT_LINE_HEIGHT_VALUE); EXPECT_EQ(layoutProperty->GetTextOverflow().value(), TextOverflow::ELLIPSIS); EXPECT_EQ(layoutProperty->GetTextDecorationFirst(), TextDecoration::UNDERLINE); EXPECT_EQ(layoutProperty->GetTextDecorationColor().value(), Color::BLACK); diff --git a/test/unittest/core/pattern/text/text_testtwo_ng.cpp b/test/unittest/core/pattern/text/text_testtwo_ng.cpp index 14bdbb8e136..ddded22799b 100644 --- a/test/unittest/core/pattern/text/text_testtwo_ng.cpp +++ b/test/unittest/core/pattern/text/text_testtwo_ng.cpp @@ -1120,6 +1120,9 @@ HWTEST_F(TextTestTwoNg, UpdateChildProperty001, TestSize.Level1) testProperty.textCaseValue = std::make_optional(TEXT_CASE_VALUE); testProperty.letterSpacing = std::make_optional(LETTER_SPACING); testProperty.lineHeightValue = std::make_optional(LINE_HEIGHT_VALUE); + testProperty.minimumLineHeight = std::make_optional(LINE_HEIGHT_VALUE); + testProperty.lineHeightMultiply = std::make_optional(LINE_HEIGHT_VALUE); + testProperty.maximumLineHeight = std::make_optional(LINE_HEIGHT_VALUE); testProperty.fontFamilyValue = std::make_optional(FONT_FAMILY_VALUE); testProperty.lineSpacingValue = std::make_optional(LINE_SPACING_VALUE); testProperty.isOnlyBetweenLines = std::make_optional(true); @@ -1176,6 +1179,9 @@ HWTEST_F(TextTestTwoNg, UpdateChildProperty001, TestSize.Level1) EXPECT_EQ(spanTextStyle.GetTextCase(), TEXT_CASE_VALUE); EXPECT_EQ(spanTextStyle.GetLetterSpacing(), LETTER_SPACING); EXPECT_EQ(spanTextStyle.GetLineHeight(), LINE_HEIGHT_VALUE); + EXPECT_EQ(spanTextStyle.GetLineHeightMultiply(), LINE_HEIGHT_VALUE); + EXPECT_EQ(spanTextStyle.GetMinimumLineHeight(), LINE_HEIGHT_VALUE); + EXPECT_EQ(spanTextStyle.GetMaximumLineHeight(), LINE_HEIGHT_VALUE); EXPECT_EQ(spanTextStyle.GetFontFamilies(), FONT_FAMILY_VALUE); EXPECT_EQ(spanTextStyle.GetLineSpacing(), LINE_SPACING_VALUE); EXPECT_EQ(spanTextStyle.GetIsOnlyBetweenLines(), true); -- Gitee