• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.. All rights reserved.
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 ROSEN_MODULES_SPTEXT_DRAWING_PAINTER_IMPL_H
17 #define ROSEN_MODULES_SPTEXT_DRAWING_PAINTER_IMPL_H
18 
19 #include <memory>
20 
21 #include "draw/canvas.h"
22 #include "modules/skparagraph/include/ParagraphPainter.h"
23 #include "rosen_text/symbol_animation_config.h"
24 #include "symbol_engine/hm_symbol_run.h"
25 #include "txt/paint_record.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace SPText {
30 using ParagraphPainter = skia::textlayout::ParagraphPainter;
31 
32 class RSCanvasParagraphPainter : public ParagraphPainter {
33 public:
34     RSCanvasParagraphPainter(Drawing::Canvas* canvas, const std::vector<PaintRecord>& paints);
35 
36     void drawTextBlob(const std::shared_ptr<RSTextBlob>& blob, SkScalar x, SkScalar y,
37         const SkPaintOrID& paint) override;
38     void drawTextShadow(const std::shared_ptr<RSTextBlob>& blob, SkScalar x, SkScalar y, SkColor color,
39         SkScalar blurSigma) override;
40     void drawRect(const SkRect& rect, const SkPaintOrID& paint) override;
41     void drawRRect(const SkRRect& rrect, const SkColor color) override;
42     void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) override;
43     void drawPath(const RSPath& path, const DecorationStyle& decorStyle) override;
44     void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) override;
45     void SymbolAnimation(const PaintRecord &pr);
46     void DrawSymbolSkiaTxt(const std::shared_ptr<RSTextBlob>& blob, const RSPoint& offset, const PaintRecord &pr);
47 
48     void clipRect(const SkRect& rect) override;
49     void translate(SkScalar dx, SkScalar dy) override;
50 
51     void save() override;
52     void restore() override;
53 
SetAnimation(std::function<bool (const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig> &)> & animationFunc)54     void SetAnimation(
55         std::function<bool(const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)>& animationFunc
56     )
57     {
58         if (animationFunc != nullptr) {
59             animationFunc_ = animationFunc;
60         }
61     }
62 
SetHmSymbols(const std::vector<std::shared_ptr<HMSymbolRun>> & hmSymbols)63     void SetHmSymbols(const std::vector<std::shared_ptr<HMSymbolRun>>& hmSymbols)
64     {
65         hmSymbols_ = hmSymbols;
66     }
67 
68     std::shared_ptr<HMSymbolRun> generateSymbolRun(const std::shared_ptr<RSTextBlob>& blob, const PaintRecord& pr);
69 
70 private:
71     Drawing::Canvas* canvas_;
72     const std::vector<PaintRecord>& paints_;
73     std::function<bool(
74         const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)> animationFunc_ = nullptr;
75     std::vector<std::shared_ptr<HMSymbolRun>> hmSymbols_;
76 };
77 } // namespace SPText
78 } // namespace Rosen
79 } // namespace OHOS
80 
81 #endif // ROSEN_MODULES_SPTEXT_DRAWING_PAINTER_IMPL_H
82