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