• 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();
41     TextDirection GetSystemDirection() override;
GetWidth()42     int32_t GetWidth()
43     {
44         return width_;
45     }
GetHeight()46     int32_t GetHeight()
47     {
48         return height_;
49     }
GetBitmapSize()50     size_t GetBitmapSize()
51     {
52         return bitmapSize_;
53     }
54 private:
55     void InitBitmap();
56 #ifndef ACE_UNITTEST
57     void ConvertTxtStyle(const TextStyle& textStyle, Rosen::TextStyle& txtStyle) override;
58 #endif
59 
60     RSBitmap bitmap_;
61 
62     int32_t width_;
63     int32_t height_;
64     size_t bitmapSize_ = 0;
65 };
66 } // namespace OHOS::Ace::NG
67 
68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_CUSTOM_PAINT_PAINT_METHOD_H
69