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