1 /* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_CONTENT_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_CONTENT_MODIFIER_H 18 19 #include "base/geometry/ng/size_t.h" 20 #include "core/components_ng/base/modifier.h" 21 #include "core/components_ng/render/canvas_image.h" 22 23 namespace OHOS::Ace::NG { 24 class ImagePattern; 25 class ImageContentModifier : public ContentModifier { 26 DECLARE_ACE_TYPE(ImageContentModifier, ContentModifier); 27 28 public: 29 ImageContentModifier(); 30 explicit ImageContentModifier(const WeakPtr<ImagePattern>& pattern); 31 ~ImageContentModifier() override = default; 32 33 void onDraw(DrawingContext& drawingContext) override; 34 35 void DrawDrawable(DrawingContext& drawingContext); 36 SetSensitive(bool sensitive)37 void SetSensitive(bool sensitive) 38 { 39 CHECK_NULL_VOID(sensitive_); 40 sensitive_->Set(sensitive); 41 } 42 SetSize(const SizeF & size)43 void SetSize(const SizeF& size) 44 { 45 CHECK_NULL_VOID(size_); 46 size_->Set(size); 47 } 48 SetCanvasImageWrapper(const CanvasImageModifierWrapper & wrapper)49 void SetCanvasImageWrapper(const CanvasImageModifierWrapper& wrapper) 50 { 51 CHECK_NULL_VOID(canvasImageWrapper_); 52 canvasImageWrapper_->Set(wrapper); 53 } 54 55 private: 56 // The same svg resource has only one copy of SVGDOM in the object cache. Therefore 57 // the value of fill color must be changed on the modifier berfore the onDraw method 58 static void UpdateSvgColorFilter(const RefPtr<CanvasImage>& canvasImage); 59 60 WeakPtr<ImagePattern> pattern_; 61 RefPtr<PropertyBool> sensitive_; 62 RefPtr<PropertySizeF> size_; 63 RefPtr<PropertyCanvasImageModifierWrapper> canvasImageWrapper_; 64 65 ACE_DISALLOW_COPY_AND_MOVE(ImageContentModifier); 66 }; 67 } // namespace OHOS::Ace::NG 68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_CONTENT_MODIFIER_H 69