• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_PATTERN_CUSTOM_PAINT_OFFSCREEN_CANVAS_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_OFFSCREEN_CANVAS_PAINT_METHOD_H
18 
19 #include "core/components_ng/pattern/canvas/custom_paint_paint_method.h"
20 
21 namespace OHOS::Ace::NG {
22 using setColorFunc = std::function<void (const std::string&)>;
23 
24 class OffscreenCanvasPaintMethod : public CustomPaintPaintMethod {
25     DECLARE_ACE_TYPE(OffscreenCanvasPaintMethod, CustomPaintPaintMethod)
26 public:
27     OffscreenCanvasPaintMethod() = default;
28     OffscreenCanvasPaintMethod(int32_t width, int32_t height);
29     ~OffscreenCanvasPaintMethod() override = default;
30 
31     RefPtr<PixelMap> TransferToImageBitmap();
32     void DrawPixelMap(RefPtr<PixelMap> pixelMap, const Ace::CanvasImage& canvasImage);
33     std::unique_ptr<Ace::ImageData> GetImageData(double left, double top, double width, double height);
34     void GetImageData(const std::shared_ptr<Ace::ImageData>& imageData);
35     std::string ToDataURL(const std::string& type, const double quality);
36 
37     TransformParam GetTransform() const override;
38     LineDashParam GetLineDash() const override;
39     void UpdateSize(int32_t width, int32_t height);
40     void Reset();
GetWidth()41     int32_t GetWidth()
42     {
43         return width_;
44     }
GetHeight()45     int32_t GetHeight()
46     {
47         return height_;
48     }
GetBitmapSize()49     size_t GetBitmapSize()
50     {
51         return bitmapSize_;
52     }
53 private:
54     void InitBitmap();
55 #ifndef ACE_UNITTEST
56     void ConvertTxtStyle(const TextStyle& textStyle, Rosen::TextStyle& txtStyle) override;
57 #endif
58 
59     RSBitmap bitmap_;
60 
61     int32_t width_;
62     int32_t height_;
63     size_t bitmapSize_ = 0;
64 };
65 } // namespace OHOS::Ace::NG
66 
67 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_CUSTOM_PAINT_PAINT_METHOD_H
68