diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts index 69ebf1a7c7f24e56280e96217a25a34e3ab3fe56..bd1316e7712c5a0b983481e16367d3f9139bbcd6 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 32d38ffa8deb829fb0f61bf86eda7a68cf5d6bd1..c6abf4d98f80c43b14711305392d2dd66b843c31 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 267264f9408639a47560e4ea60143948577a1f89..2e6a40c44428d8a5eba777211b8ae41ecc7e1f19 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 0d0f86016ea8de003b7bdb7fc4e9f960e59770c7..23027a18e3cfc36415b390fd1e378629d126d86a 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 1c1001b87ff6775eae58783e551496279b99fe98..5ebb0a6d73e0f5a6c59b1c09db813bd6cc083c86 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 e5dfe6b1be118683ac8ed53bcf29a5e4f4d5bbbf..016cc18d971ecd083e2fa22cc01839c31f8c16aa 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 571c52899e4a5bcc5ec7aa93693be079277efe95..f383368f048baa92d7bf58c92ecf799f047585c3 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 e0fc02b17d4b3255fec1510675b0cace99cdd27c..5a35a0b12f018071631733f88daac00224249dce 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 2ec86bc4a46e95aaa15c2ef1585bc2e6e3196ace..95a32d033984c2fbc66303e463d260e50dd404a5 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 ee006a153f4acad44d5904fc4a07c1f1cd08fb34..cf1299b9a5026a9286493c55c0e9f32f2b4773bd 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 1935dc9a2fade26dcb2efc88fe08f808efd9f84a..0cdc60a4666774fff5d3b9625caa46ec359ecf73 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 774b1b0891ec1cdc17c5d203e61ac5525afc3750..e4fd057c7cbeabfc56873f4c5e788292f26af787 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 d2cacca8803f939ff0ae62531d62e1de7ca590c6..a75e54d31a8fe46c8f44a3bbee1b1cde54200455 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 90ec91990d22017d19004049cc5bfefe28f0f04b..c12fb1b226210fd6cf9fe67b47d0ec02ece10c35 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 a9bc6ab6435783ede44e8ceecc301269e4c47524..61ee36d5a2a03f5062c78801d28edf365e50c39b 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 037a9b0cab4fa7445b03432e2f8bd030c9d0b021..2a847980cc4d00e1e4ec8ca186a75c6b7c01a7d8 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 c1daf3204560eb5d87f26ca67c2565dcaf413da1..8bc94a1933d8dbe47d663f18433ee5be3a94692f 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 ddd89760ec2a50005a6ac7c7c9f0d23068d40ee9..381996513672cb99ba723932ae20ba52a5f31c6a 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;