1 // Copyright 2019 Google LLC. 2 #ifndef ParagraphPainter_DEFINED 3 #define ParagraphPainter_DEFINED 4 5 #include "include/core/SkPaint.h" 6 #include "include/core/SkRRect.h" 7 #include "include/core/SkTextBlob.h" 8 9 #include <optional> 10 #include <variant> 11 12 namespace skia { 13 namespace textlayout { 14 15 class ParagraphPainter { 16 public: 17 typedef int PaintID; 18 typedef std::variant<SkPaint, PaintID> SkPaintOrID; 19 20 struct DashPathEffect { 21 DashPathEffect(SkScalar onLength, SkScalar offLength); 22 23 SkScalar fOnLength; 24 SkScalar fOffLength; 25 }; 26 27 class DecorationStyle { 28 public: 29 DecorationStyle(); 30 DecorationStyle(SkColor color, SkScalar strokeWidth, 31 std::optional<DashPathEffect> dashPathEffect); 32 getColor()33 SkColor getColor() const { return fColor; } getStrokeWidth()34 SkScalar getStrokeWidth() const { return fStrokeWidth; } getDashPathEffect()35 std::optional<DashPathEffect> getDashPathEffect() const { return fDashPathEffect; } skPaint()36 const SkPaint& skPaint() const { return fPaint; } 37 38 private: 39 SkColor fColor; 40 SkScalar fStrokeWidth; 41 std::optional<DashPathEffect> fDashPathEffect; 42 SkPaint fPaint; 43 }; 44 45 virtual ~ParagraphPainter() = default; 46 47 virtual void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaintOrID& paint) = 0; 48 virtual void drawTextShadow(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, SkColor color, SkScalar blurSigma) = 0; 49 virtual void drawRect(const SkRect& rect, const SkPaintOrID& paint) = 0; 50 virtual void drawRRect(const SkRRect& rrect, const SkColor color) = 0; 51 virtual void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) = 0; 52 virtual void drawPath(const SkPath& path, const DecorationStyle& decorStyle) = 0; 53 virtual void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) = 0; 54 55 virtual void clipRect(const SkRect& rect) = 0; 56 virtual void translate(SkScalar dx, SkScalar dy) = 0; 57 58 virtual void save() = 0; 59 virtual void restore() = 0; 60 }; 61 62 } // namespace textlayout 63 } // namespace skia 64 65 #endif // ParagraphPainter_DEFINED 66