From 73aa1c3e6ffa522968d448433428ee30faba3226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=85=A8=E8=B6=85?= Date: Fri, 29 Aug 2025 16:50:22 +0800 Subject: [PATCH] =?UTF-8?q?image=E7=BB=84=E4=BB=B6=E9=80=8F=E4=BC=A0suppor?= =?UTF-8?q?tSvg2=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张全超 --- .../ark_component/src/ArkImage.ts | 20 ++++++++++++ .../engine/arkComponent.js | 23 ++++++++++++- .../arkts_native_api_impl_bridge.cpp | 4 +++ .../arkts_native_image_bridge.cpp | 32 +++++++++++++++++++ .../nativeModule/arkts_native_image_bridge.h | 2 ++ .../declarative_frontend/jsview/js_image.cpp | 9 ++++++ .../declarative_frontend/jsview/js_image.h | 1 + .../jsview/models/image_model_impl.h | 1 + .../image_provider/image_loading_context.h | 5 +++ .../components_ng/pattern/image/image_model.h | 1 + .../pattern/image/image_model_ng.cpp | 19 +++++++++++ .../pattern/image/image_model_ng.h | 3 ++ .../pattern/image/image_pattern.cpp | 3 ++ .../pattern/image/image_pattern.h | 6 ++++ frameworks/core/image/image_source_info.cpp | 5 ++- frameworks/core/image/image_source_info.h | 11 +++++++ .../core/interfaces/arkoala/arkoala_api.h | 2 ++ .../native/node/node_image_modifier.cpp | 16 ++++++++++ 18 files changed, 161 insertions(+), 2 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts index 69ebf1a7c7f..bd1316e7712 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts @@ -716,6 +716,22 @@ class ImageOnCompleteModifier extends ModifierWithKey<(event?: { } } } +class ImageSupportSvg2Modifier extends ModifierWithKey { + constructor(value: boolean) { + super(value); + } + static identity: Symbol = Symbol('supportSvg2'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().image.resetSupportSvg2(node); + } else { + getUINativeModule().image.setSupportSvg2(node, this.value!); + } + } + checkObjectDiff(): boolean { + return this.stageValue !== this.value; + } +} class ArkImageComponent extends ArkComponent implements ImageAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); @@ -885,6 +901,10 @@ class ArkImageComponent extends ArkComponent implements ImageAttribute { modifierWithKey(this._modifiersWithKeys, ImageResizableModifier.identity, ImageResizableModifier, value); return this; } + supportSvg2(value: boolean): this { + modifierWithKey(this._modifiersWithKeys, ImageSupportSvg2Modifier.identity, ImageSupportSvg2Modifier, value); + return this; + } } // @ts-ignore globalThis.Image.attributeModifier = function (modifier: ArkComponent): void { diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index 32d38ffa8de..c6abf4d98f8 100755 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -8683,7 +8683,23 @@ class ImageOnFinishModifier extends ModifierWithKey { } } ImageOnFinishModifier.identity = Symbol('imageOnFinish'); - +class ImageSupportSvg2Modifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().image.resetSupportSvg2(node); + } + else { + getUINativeModule().image.setSupportSvg2(node, this.value); + } + } + checkObjectDiff() { + return this.stageValue !== this.value; + } +} +ImageSupportSvg2Modifier.identity = Symbol('supportSvg2'); class ArkImageComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); @@ -8829,6 +8845,11 @@ class ArkImageComponent extends ArkComponent { this._modifiersWithKeys, ImageAnalyzerConfigModifier.identity, ImageAnalyzerConfigModifier, value); return this; } + supportSvg2(value) { + modifierWithKey( + this._modifiersWithKeys, ImageSupportSvg2Modifier.identity, ImageSupportSvg2Modifier, value); + return this; + } } // @ts-ignore if (globalThis.Image !== 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 267264f9408..2e6a40c4442 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 @@ -4343,6 +4343,10 @@ void ArkUINativeModule::RegisterImageAttributes(Local object, panda::FunctionRef::New(const_cast(vm), ImageBridge::SetOnFinish)); image->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnFinish"), panda::FunctionRef::New(const_cast(vm), ImageBridge::ResetOnFinish)); + image->Set(vm, panda::StringRef::NewFromUtf8(vm, "setSupportSvg2"), + panda::FunctionRef::New(const_cast(vm), ImageBridge::SetSupportSvg2)); + image->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetSupportSvg2"), + panda::FunctionRef::New(const_cast(vm), ImageBridge::ResetSupportSvg2)); object->Set(vm, panda::StringRef::NewFromUtf8(vm, "image"), image); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.cpp index 0d0f86016ea..23027a18e3c 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.cpp @@ -1345,4 +1345,36 @@ ArkUINativeModuleValue ImageBridge::ResetOrientation(ArkUIRuntimeCallInfo* runti nodeModifiers->getImageModifier()->resetImageRotateOrientation(nativeNode); return panda::JSValueRef::Undefined(vm); } + +ArkUINativeModuleValue ImageBridge::SetSupportSvg2(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); + Local firstArg = runtimeCallInfo->GetCallArgRef(0); + CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + auto nodeModifiers = GetArkUINodeModifiers(); + CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm)); + Local secondArg = runtimeCallInfo->GetCallArgRef(1); + if (secondArg->IsBoolean()) { + bool supportSvg2 = secondArg->ToBoolean(vm)->Value(); + nodeModifiers->getImageModifier()->setSupportSvg2(nativeNode, supportSvg2); + } else { + nodeModifiers->getImageModifier()->resetSupportSvg2(nativeNode); + } + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue ImageBridge::ResetSupportSvg2(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); + Local firstArg = runtimeCallInfo->GetCallArgRef(0); + CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm)); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + auto nodeModifiers = GetArkUINodeModifiers(); + CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm)); + nodeModifiers->getImageModifier()->resetSupportSvg2(nativeNode); + return panda::JSValueRef::Undefined(vm); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.h index 1c1001b87ff..5ebb0a6d73e 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.h @@ -84,6 +84,8 @@ public: static ArkUINativeModuleValue ResetOnFinish(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetOrientation(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetOrientation(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue SetSupportSvg2(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetSupportSvg2(ArkUIRuntimeCallInfo* runtimeCallInfo); }; } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_image.cpp b/frameworks/bridge/declarative_frontend/jsview/js_image.cpp index e5dfe6b1be1..016cc18d971 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_image.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_image.cpp @@ -1122,6 +1122,7 @@ void JSImage::JSBind(BindingTarget globalObj) JSClass::StaticMethod("copyOption", &JSImage::SetCopyOption); JSClass::StaticMethod("enableAnalyzer", &JSImage::EnableAnalyzer); JSClass::StaticMethod("analyzerConfig", &JSImage::AnalyzerConfig); + JSClass::StaticMethod("supportSvg2", &JSImage::SupportSvg2); // override method JSClass::StaticMethod("opacity", &JSImage::JsOpacity); @@ -1243,4 +1244,12 @@ void JSImage::AnalyzerConfig(const JSCallbackInfo& info) ImageModel::GetInstance()->SetImageAnalyzerConfig(analyzerConfig); } +void JSImage::SupportSvg2(const JSCallbackInfo& info) +{ + bool enable = false; + if (info.Length() > 0) { + ParseJsBool(info[0], enable); + } + ImageModel::GetInstance()->SetSupportSvg2(enable); +} } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_image.h b/frameworks/bridge/declarative_frontend/jsview/js_image.h index 571c52899e4..f383368f048 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_image.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_image.h @@ -77,6 +77,7 @@ public: static void EnableAnalyzer(bool isEnableAnalyzer); static void AnalyzerConfig(const JSCallbackInfo& info); + static void SupportSvg2(const JSCallbackInfo& info); static void ParseResizableSlice(const JSRef& info); static void ParseResizableLattice(const JSRef& info); static void JsImageResizable(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/image_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/image_model_impl.h index e0fc02b17d4..5a35a0b12f0 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/image_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/image_model_impl.h @@ -79,6 +79,7 @@ public: bool GetIsAnimation() override; void CreateWithResourceObj(ImageResourceType resourceType, const RefPtr& resObject) override {}; void SetImageFillSetByUser(bool value) override {}; + void SetSupportSvg2(bool enable) override {}; }; } // namespace OHOS::Ace::Framework diff --git a/frameworks/core/components_ng/image_provider/image_loading_context.h b/frameworks/core/components_ng/image_provider/image_loading_context.h index 2ec86bc4a46..95a32d03398 100644 --- a/frameworks/core/components_ng/image_provider/image_loading_context.h +++ b/frameworks/core/components_ng/image_provider/image_loading_context.h @@ -166,6 +166,11 @@ public: return onProgressCallback_; } + void SetSupportSvg2(bool enable) + { + src_.SetSupportSvg2(enable); + } + private: #define DEFINE_SET_NOTIFY_TASK(loadResult) \ void Set##loadResult##NotifyTask(loadResult##NotifyTask&& loadResult##NotifyTask) \ diff --git a/frameworks/core/components_ng/pattern/image/image_model.h b/frameworks/core/components_ng/pattern/image/image_model.h index ee006a153f4..cf1299b9a50 100644 --- a/frameworks/core/components_ng/pattern/image/image_model.h +++ b/frameworks/core/components_ng/pattern/image/image_model.h @@ -108,6 +108,7 @@ public: virtual bool GetIsAnimation() = 0; virtual void CreateWithResourceObj(ImageResourceType resourceType, const RefPtr& resObject) = 0; virtual void SetImageFillSetByUser(bool value) = 0; + virtual void SetSupportSvg2(bool enable) = 0; private: static std::unique_ptr instance_; diff --git a/frameworks/core/components_ng/pattern/image/image_model_ng.cpp b/frameworks/core/components_ng/pattern/image/image_model_ng.cpp index 1935dc9a2fa..0cdc60a4666 100644 --- a/frameworks/core/components_ng/pattern/image/image_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/image/image_model_ng.cpp @@ -1363,5 +1363,24 @@ void ImageModelNG::SetImageFillSetByUser(bool value) ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageFillSetByUser, value); } } + +void ImageModelNG::SetSupportSvg2(bool enable) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + SetSupportSvg2(frameNode, enable); +} + +void ImageModelNG::SetSupportSvg2(FrameNode* frameNode, bool enable) +{ + CHECK_NULL_VOID(frameNode); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->SetSupportSvg2(enable); +} + +void ImageModelNG::ResetSupportSvg2(FrameNode* frameNode) +{ + SetSupportSvg2(frameNode, false); +} } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_CPP diff --git a/frameworks/core/components_ng/pattern/image/image_model_ng.h b/frameworks/core/components_ng/pattern/image/image_model_ng.h index 774b1b0891e..e4fd057c7cb 100644 --- a/frameworks/core/components_ng/pattern/image/image_model_ng.h +++ b/frameworks/core/components_ng/pattern/image/image_model_ng.h @@ -80,6 +80,7 @@ public: void SetResizableLattice(const RefPtr& lattice) override; void ResetResizableLattice() override; void SetImageFillSetByUser(bool value) override; + void SetSupportSvg2(bool enable) override; static RefPtr CreateFrameNode(int32_t nodeId, const std::string& src, RefPtr& pixMap, const std::string& bundleName, const std::string& moduleName, bool isUriPureNumber = false); static void InitImage(FrameNode* frameNode, std::string& src); @@ -160,6 +161,8 @@ public: static void SetAltResource(FrameNode* frameNode, void* resource); static void CreateWithResourceObj( FrameNode* frameNode, ImageResourceType resourceType, const RefPtr& resObject); + static void SetSupportSvg2(FrameNode* frameNode, bool enable); + static void ResetSupportSvg2(FrameNode* frameNode); private: ImagePattern* GetImagePattern(); diff --git a/frameworks/core/components_ng/pattern/image/image_pattern.cpp b/frameworks/core/components_ng/pattern/image/image_pattern.cpp index d2cacca8803..a75e54d31a8 100644 --- a/frameworks/core/components_ng/pattern/image/image_pattern.cpp +++ b/frameworks/core/components_ng/pattern/image/image_pattern.cpp @@ -887,6 +887,7 @@ void ImagePattern::LoadImage(const ImageSourceInfo& src, bool needLayout) loadingCtx_ = AceType::MakeRefPtr( src, std::move(loadNotifier), syncLoad_, isSceneBoardWindow_, imageDfxConfig_); + loadingCtx_->SetSupportSvg2(supportSvg2_); if (SystemProperties::GetDebugEnabled()) { TAG_LOGI(AceLogTag::ACE_IMAGE, "load image, %{private}s", imageDfxConfig_.ToStringWithSrc().c_str()); @@ -914,6 +915,7 @@ void ImagePattern::LoadAltImage(const ImageSourceInfo& altImageSourceInfo) altImageDfxConfig_ = CreateImageDfxConfig(altImageSourceInfo); altLoadingCtx_ = AceType::MakeRefPtr( altImageSourceInfo, std::move(altLoadNotifier), false, isSceneBoardWindow_, altImageDfxConfig_); + altLoadingCtx_->SetSupportSvg2(supportSvg2_); altLoadingCtx_->LoadImageData(); } } @@ -1966,6 +1968,7 @@ void ImagePattern::DumpSvgInfo() { DumpLog::GetInstance().AddDesc("---- SVG Related Dump ----"); DumpLog::GetInstance().AddDesc("Your SVG related log description here"); + DumpLog::GetInstance().AddDesc(std::string("SupportSvg2:").append(supportSvg2_?"True":"False")); auto imageLayoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(imageLayoutProperty); auto imageSourceInfo = imageLayoutProperty->GetImageSourceInfo(); diff --git a/frameworks/core/components_ng/pattern/image/image_pattern.h b/frameworks/core/components_ng/pattern/image/image_pattern.h index 90ec91990d2..c12fb1b2262 100644 --- a/frameworks/core/components_ng/pattern/image/image_pattern.h +++ b/frameworks/core/components_ng/pattern/image/image_pattern.h @@ -409,6 +409,11 @@ public: void UpdateImageAlt(const ImageSourceInfo& sourceInfo); void OnColorModeChange(uint32_t colorMode) override; + void SetSupportSvg2(bool enable) + { + supportSvg2_ = enable; + } + protected: void RegisterWindowStateChangedCallback(); void UnregisterWindowStateChangedCallback(); @@ -628,6 +633,7 @@ private: bool isNeedReset_ = false; bool hasSetPixelMapMemoryName_ = false; bool previousVisibility_ = false; + bool supportSvg2_ = false; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/image/image_source_info.cpp b/frameworks/core/image/image_source_info.cpp index a9bc6ab6435..61ee36d5a2a 100644 --- a/frameworks/core/image/image_source_info.cpp +++ b/frameworks/core/image/image_source_info.cpp @@ -437,7 +437,10 @@ std::string ImageSourceInfo::GetTaskKey() const { // only svg sets fillColor if (isSvg_ && fillColor_.has_value()) { - return cacheKey_ + fillColor_.value().ColorToString() + std::to_string(containerId_); + return cacheKey_ + fillColor_.value().ColorToString() + std::to_string(containerId_) + + std::string(supportSvg2_ ? "true" : "false"); + } else if (isSvg_) { + return cacheKey_ + std::to_string(containerId_) + std::string(supportSvg2_ ? "true" : "false"); } return cacheKey_ + std::to_string(containerId_) + std::to_string(isHdr_); } diff --git a/frameworks/core/image/image_source_info.h b/frameworks/core/image/image_source_info.h index 037a9b0cab4..2a847980cc4 100644 --- a/frameworks/core/image/image_source_info.h +++ b/frameworks/core/image/image_source_info.h @@ -146,6 +146,16 @@ public: return srcType_ == SrcType::NETWORK || srcType_ == SrcType::RESOURCE; } + void SetSupportSvg2(bool enable) + { + supportSvg2_ = enable; + } + + bool IsSupportSvg2() const + { + return supportSvg2_; + } + private: SrcType ResolveSrcType() const; @@ -173,6 +183,7 @@ private: SrcType srcType_ = SrcType::UNSUPPORTED; ColorMode localColorMode_ = ColorMode::COLOR_MODE_UNDEFINED; + bool supportSvg2_ = false; }; } // namespace OHOS::Ace diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index c1daf320456..8bc94a1933d 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -3291,6 +3291,8 @@ struct ArkUIImageModifier { void (*resetImageOnFinish)(ArkUINodeHandle node); void (*setResizableLattice)(ArkUINodeHandle node, void* lattice); void (*resetResizableLattice)(ArkUINodeHandle node); + void (*setSupportSvg2)(ArkUINodeHandle node, ArkUI_Bool enable); + void (*resetSupportSvg2)(ArkUINodeHandle node); }; struct ArkUIColumnModifier { diff --git a/frameworks/core/interfaces/native/node/node_image_modifier.cpp b/frameworks/core/interfaces/native/node/node_image_modifier.cpp index ddd89760ec2..38199651367 100644 --- a/frameworks/core/interfaces/native/node/node_image_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_image_modifier.cpp @@ -1224,6 +1224,20 @@ void ResetImageRotateOrientation(ArkUINodeHandle node) CHECK_NULL_VOID(frameNode); ImageModelNG::SetOrientation(frameNode, ImageRotateOrientation::UP); } + +void SetSupportSvg2(ArkUINodeHandle node, ArkUI_Bool supportSvg2) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + ImageModelNG::SetSupportSvg2(frameNode, supportSvg2); +} + +void ResetSupportSvg2(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + ImageModelNG::ResetSupportSvg2(frameNode); +} } // namespace namespace NodeModifier { @@ -1338,6 +1352,8 @@ const ArkUIImageModifier* GetImageModifier() .resetImageOnFinish = ResetImageOnFinish, .setResizableLattice = SetResizableLattice, .resetResizableLattice = ResetResizableLattice, + .setSupportSvg2 = SetSupportSvg2, + .resetSupportSvg2 = ResetSupportSvg2, }; CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line return &modifier; -- Gitee