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_BORDER_IMAGE_PAINT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_BORDER_IMAGE_PAINT_H 18 19 #include <cmath> 20 21 #include "base/geometry/ng/size_t.h" 22 #include "base/memory/ace_type.h" 23 #include "core/components/common/properties/border_image.h" 24 #include "core/components_ng/property/gradient_property.h" 25 #include "core/components_ng/render/drawing.h" 26 #include "core/components_ng/render/render_property.h" 27 28 namespace OHOS::Ace::NG { 29 struct DisplayScaleInfo { 30 double vpScale = 0.0; 31 double lpxScale = 0.0; 32 }; 33 class BorderImagePainter : public virtual AceType { 34 DECLARE_ACE_TYPE(BorderImagePainter, AceType); 35 36 public: 37 BorderImagePainter(BorderImageProperty bdImageProps, const std::unique_ptr<BorderWidthProperty>& widthProp, 38 const SizeF& paintSize, const RSImage& image, const DisplayScaleInfo& dipscaleInfoe); 39 ~BorderImagePainter() override = default; 40 void PaintBorderImage(const OffsetF& offset, RSCanvas& canvas) const; 41 RectF GetDrawRect(const OffsetF& offset); 42 43 private: 44 void InitPainter(); 45 void PaintBorderImageCorners(const OffsetF& offset, RSCanvas& canvas) const; 46 void PaintBorderImageStretch(const OffsetF& offset, RSCanvas& canvas) const; 47 void PaintBorderImageRound(const OffsetF& offset, RSCanvas& canvas) const; 48 void PaintBorderImageSpace(const OffsetF& offset, RSCanvas& canvas) const; 49 void PaintBorderImageRepeat(const OffsetF& offset, RSCanvas& canvas) const; 50 void FillBorderImageCenter(const OffsetF& offset, RSCanvas& canvas) const; 51 52 void InitBorderImageSlice(); 53 void InitBorderImageWidth(); 54 void InitBorderImageOutset(); 55 void ParseNegativeNumberToZeroOrCeil(double& value); 56 57 bool hasWidthProp_ = false; 58 BorderImageProperty borderImageProperty_; 59 BorderWidthProperty widthProp_; 60 SizeF paintSize_; 61 RSImage image_; 62 63 double imageWidth_ = 0.0; 64 double imageHeight_ = 0.0; 65 double imageCenterWidth_ = 0.0; 66 double imageCenterHeight_ = 0.0; 67 double borderCenterWidth_ = 0.0; 68 double borderCenterHeight_ = 0.0; 69 70 double dipScale_ = 0.0; 71 double lpxScale_ = 0.0; 72 double leftWidth_ = 0.0; 73 double topWidth_ = 0.0; 74 double rightWidth_ = 0.0; 75 double bottomWidth_ = 0.0; 76 77 double leftSlice_ = 0.0; 78 double topSlice_ = 0.0; 79 double rightSlice_ = 0.0; 80 double bottomSlice_ = 0.0; 81 82 double leftOutset_ = 0.0; 83 double topOutset_ = 0.0; 84 double rightOutset_ = 0.0; 85 double bottomOutset_ = 0.0; 86 87 RSRect srcRectLeft_; 88 RSRect srcRectRight_; 89 RSRect srcRectTop_; 90 RSRect srcRectBottom_; 91 92 bool paintCornersOnly_ = false; 93 }; 94 } // namespace OHOS::Ace::NG 95 96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_BORDER_IMAGE_PAINT_H 97