1 /* 2 * Copyright (c) 2022-2023 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_RENDER_IMAGE_PAINT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_IMAGE_PAINT_H 18 19 #include "core/components_ng/render/canvas_image.h" 20 #include "core/components_ng/render/drawing.h" 21 22 namespace OHOS::Ace::NG { 23 24 class ImagePainter { 25 public: ImagePainter(const RefPtr<CanvasImage> & canvasImage)26 explicit ImagePainter(const RefPtr<CanvasImage>& canvasImage) : canvasImage_(canvasImage) {} 27 ~ImagePainter() = default; 28 29 void DrawObscuration(RSCanvas& canvas, const OffsetF& offset, const SizeF& contentSize) const; 30 void DrawImage(RSCanvas& canvas, const OffsetF& offset, const SizeF& contentSize) const; 31 void DrawStaticImage(RSCanvas& canvas, const OffsetF& offset, const SizeF& contentSize) const; 32 void DrawSVGImage(RSCanvas& canvas, const OffsetF& offset, const SizeF& svgContainerSize) const; 33 void DrawImageWithRepeat(RSCanvas& canvas, const RectF& rect) const; 34 35 static void ApplyImageFit( 36 ImageFit imageFit, const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, RectF& dstRect); 37 38 static void FlipHorizontal(RSCanvas& canvas, const SizeF& contentSize); 39 40 static SizeF CalculateBgImageSize( 41 const SizeF& boxPaintSize_, const SizeF& srcSize, const std::optional<BackgroundImageSize>& bgImageSizeOpt); 42 static OffsetF CalculateBgImagePosition(const SizeF& boxPaintSize_, const SizeF& imageRenderSize_, 43 const std::optional<BackgroundImagePosition>& bgImgPositionOpt); 44 45 private: 46 RefPtr<CanvasImage> canvasImage_; 47 static void ApplyImageAlignmentFit( 48 ImageFit imageFit, const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, RectF& dstRect); 49 static const std::unordered_map<ImageFit, std::function<Alignment(bool)>> ALIMENT_OPERATIONS; 50 }; 51 52 } // namespace OHOS::Ace::NG 53 54 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_IMAGE_PAINT_H