From c7c12db6a50733e560ab82fa5edf848d21570729 Mon Sep 17 00:00:00 2001 From: guanzengkun Date: Wed, 25 Jun 2025 17:57:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DColorConetnt.ORIGIN=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9B=B4=E6=8E=A5=E7=99=BD=E5=B1=8F=20issueNo:=20http?= =?UTF-8?q?s://gitee.com/openharmony/arkui=5Face=5Fengine/issues/ICHRW0=3F?= =?UTF-8?q?from=3Dproject-issue=20Description:=20=E4=BF=AE=E5=A4=8DColorCo?= =?UTF-8?q?netnt.ORIGIN=E5=AF=BC=E8=87=B4=E7=9B=B4=E6=8E=A5=E7=99=BD?= =?UTF-8?q?=E5=B1=8F=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20?= =?UTF-8?q?Bugfix:Feature=20Binary=20Source:No=20TDD:Pass=20XTS:Pass=20?= =?UTF-8?q?=E9=A2=84=E6=B5=8B=E8=AF=95:Pass=20Signed-off-by:guanzengkun=20?= =?UTF-8?q??= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arkui-ohos/src/component/image.ts | 15 +--- .../src/handwritten/component/image.ts | 74 +++++++++++++++++++ .../native/implementation/image_modifier.cpp | 3 +- 3 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/image.ts diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/image.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/image.ts index b838416a34a..7e24d081062 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/image.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/image.ts @@ -594,8 +594,6 @@ export interface ImageSourceSize { width: number; height: number; } -export interface ColorContent { -} export interface Type_ImageAttribute_onComplete_callback_event { width: number; height: number; @@ -820,18 +818,7 @@ export class ArkImageComponent extends ArkCommonMethodComponent implements Image } public fillColor(value: ResourceColor | undefined | ResourceColor | ColorContent | undefined): this { if (this.checkPriority("fillColor")) { - const value_type = runtimeType(value) - if ((RuntimeType.NUMBER == value_type) || (RuntimeType.NUMBER == value_type) || (RuntimeType.STRING == value_type) || (RuntimeType.OBJECT == value_type) || (RuntimeType.UNDEFINED == value_type)) { - const value_casted = value as (ResourceColor | undefined) - this.getPeer()?.fillColor0Attribute(value_casted) - return this - } - if ((RuntimeType.NUMBER == value_type) || (RuntimeType.NUMBER == value_type) || (RuntimeType.STRING == value_type) || (RuntimeType.OBJECT == value_type) || (RuntimeType.OBJECT == value_type) || (RuntimeType.UNDEFINED == value_type)) { - const value_casted = value as (ResourceColor | ColorContent | undefined) - this.getPeer()?.fillColor1Attribute(value_casted) - return this - } - throw new Error("Can not select appropriate overload") + hookSetImageFillColor(this.getPeer().getPeerPtr(), value) } return this } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/image.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/image.ts new file mode 100644 index 00000000000..61a77f04657 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/image.ts @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class ColorContent { + constructor() {} + public static readonly ORIGIN: ColorContent = new ColorContent(); +} +function fillColor0Attribute(peer: KPointer, value: ResourceColor | undefined): void { + const thisSerializer: Serializer = Serializer.hold() + let value_type: int32 = RuntimeType.UNDEFINED + value_type = runtimeType(value) + thisSerializer.writeInt8(value_type as int32) + if ((RuntimeType.UNDEFINED) != (value_type)) { + const value_value = value! + let value_value_type: int32 = RuntimeType.UNDEFINED + value_value_type = runtimeType(value_value) + if (TypeChecker.isColor(value_value)) { + thisSerializer.writeInt8(0 as int32) + const value_value_0 = value_value as Color + thisSerializer.writeInt32(TypeChecker.Color_ToNumeric(value_value_0)) + } + else if (RuntimeType.NUMBER == value_value_type) { + thisSerializer.writeInt8(1 as int32) + const value_value_1 = value_value as number + thisSerializer.writeNumber(value_value_1) + } + else if (RuntimeType.STRING == value_value_type) { + thisSerializer.writeInt8(2 as int32) + const value_value_2 = value_value as string + thisSerializer.writeString(value_value_2) + } + else if (RuntimeType.OBJECT == value_value_type) { + thisSerializer.writeInt8(3 as int32) + const value_value_3 = value_value as Resource + thisSerializer.writeResource(value_value_3) + } + } + ArkUIGeneratedNativeModule._ImageAttribute_fillColor0(peer, thisSerializer.asBuffer(), thisSerializer.length()) + thisSerializer.release() +} +function fillColor1Attribute(peer: KPointer, value: ColorContent | undefined): void { + const thisSerializer: Serializer = Serializer.hold() + let value_type: int32 = RuntimeType.UNDEFINED + value_type = runtimeType(value) + thisSerializer.writeInt8(value_type as int32) + const value_value = value! + thisSerializer.writeInt8(1 as int32) + const value_value_1 = value_value as ColorContent + thisSerializer.writeColorContent(value_value_1) + ArkUIGeneratedNativeModule._ImageAttribute_fillColor1(peer, thisSerializer.asBuffer(), thisSerializer.length()) + thisSerializer.release() +} + +function hookSetImageFillColor(peer: KPointer, value: ResourceColor | undefined | ResourceColor | ColorContent | undefined): void { + if (value instanceof ColorContent) { + const value_casted = value as ColorContent + fillColor1Attribute(peer, value_casted) + } else { + const value_casted = value as (ResourceColor | undefined) + fillColor0Attribute(peer, value_casted) + } +} diff --git a/frameworks/core/interfaces/native/implementation/image_modifier.cpp b/frameworks/core/interfaces/native/implementation/image_modifier.cpp index 4241b0ad8bf..fcea70de448 100644 --- a/frameworks/core/interfaces/native/implementation/image_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/image_modifier.cpp @@ -195,8 +195,7 @@ void FillColor1Impl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - //auto convValue = value ? Converter::OptConvert(*value) : std::nullopt; - //ImageModelNG::SetFillColor1(frameNode, convValue); + ImageModelNG::ResetImageFill(frameNode); } void ObjectFitImpl(Ark_NativePointer node, const Opt_ImageFit* value) -- Gitee