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