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