1 // Copyright 2019 Google LLC. 2 #ifndef ParagraphPainterImpl_DEFINED 3 #define ParagraphPainterImpl_DEFINED 4 5 #include "include/core/SkCanvas.h" 6 #include "modules/skparagraph/include/ParagraphPainter.h" 7 8 namespace skia { 9 namespace textlayout { 10 11 class CanvasParagraphPainter : public ParagraphPainter { 12 public: 13 CanvasParagraphPainter(SkCanvas* canvas); 14 15 void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaintOrID& paint) override; 16 void drawTextShadow(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, SkColor color, SkScalar blurSigma) override; 17 void drawRect(const SkRect& rect, const SkPaintOrID& paint) override; 18 void drawRRect(const SkRRect& rrect, const SkColor color) override; 19 void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) override; 20 void drawPath(const SkPath& path, const DecorationStyle& decorStyle) override; 21 void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) override; 22 23 void clipRect(const SkRect& rect) override; 24 void translate(SkScalar dx, SkScalar dy) override; 25 26 void save() override; 27 void restore() override; 28 29 private: 30 SkCanvas* fCanvas; 31 }; 32 33 class ParagraphPainterAutoRestore { 34 public: ParagraphPainterAutoRestore(ParagraphPainter * painter)35 ParagraphPainterAutoRestore(ParagraphPainter* painter) 36 : fPainter(painter) { 37 fPainter->save(); 38 } 39 ~ParagraphPainterAutoRestore()40 ~ParagraphPainterAutoRestore() { 41 fPainter->restore(); 42 } 43 44 private: 45 ParagraphPainter* fPainter; 46 }; 47 48 } // namespace textlayout 49 } // namespace skia 50 51 #endif // ParagraphPainterImpl_DEFINED 52