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 drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) override; 19 void drawPath(const SkPath& path, const DecorationStyle& decorStyle) override; 20 void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) override; 21 22 void clipRect(const SkRect& rect) override; 23 void translate(SkScalar dx, SkScalar dy) override; 24 25 void save() override; 26 void restore() override; 27 28 private: 29 SkCanvas* fCanvas; 30 }; 31 32 class ParagraphPainterAutoRestore { 33 public: ParagraphPainterAutoRestore(ParagraphPainter * painter)34 ParagraphPainterAutoRestore(ParagraphPainter* painter) 35 : fPainter(painter) { 36 fPainter->save(); 37 } 38 ~ParagraphPainterAutoRestore()39 ~ParagraphPainterAutoRestore() { 40 fPainter->restore(); 41 } 42 43 private: 44 ParagraphPainter* fPainter; 45 }; 46 47 } // namespace textlayout 48 } // namespace skia 49 50 #endif // ParagraphPainterImpl_DEFINED 51