• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Google LLC.
2 #ifndef Decorations_DEFINED
3 #define Decorations_DEFINED
4 
5 #include "include/core/SkPath.h"
6 #include "modules/skparagraph/include/ParagraphPainter.h"
7 #include "modules/skparagraph/include/TextStyle.h"
8 #include "modules/skparagraph/src/TextLine.h"
9 
10 namespace skia {
11 namespace textlayout {
12 
13 class Decorations {
14     public:
15     void paint(ParagraphPainter* painter, const TextStyle& textStyle, const TextLine::ClipContext& context, SkScalar baseline);
16     SkScalar calculateThickness(const TextStyle& textStyle, const TextLine::ClipContext& context);
setThickness(SkScalar thickness)17     void setThickness(SkScalar thickness)
18     {
19         fThickness = thickness;
20     }
setDecorationContext(DecorationContext context)21     void setDecorationContext(DecorationContext context)
22     {
23         fDecorationContext = context;
24         setThickness(fDecorationContext.thickness);
25     }
26 
27     private:
28 
29 #ifndef USE_SKIA_TXT
30     void calculateThickness(TextStyle textStyle, sk_sp<SkTypeface> typeface);
31 #else
32     void calculateThickness(TextStyle textStyle, std::shared_ptr<RSTypeface> typeface);
33 #endif
34     void calculatePosition(TextDecoration decoration, SkScalar ascent, const TextDecorationStyle textDecorationStyle,
35         SkScalar textBaselineShift);
36     void calculatePaint(const TextStyle& textStyle);
37     void calculateWaves(const TextStyle& textStyle, SkRect clip);
38     void calculateAvoidanceWaves(const TextStyle& textStyle, SkRect clip);
39     void calculateGaps(const TextLine::ClipContext& context, const SkRect& rect, SkScalar baseline,
40         SkScalar halo, const TextStyle& textStyle);
41 
42     SkScalar fThickness;
43     SkScalar fPosition;
44     DecorationContext fDecorationContext;
45 
46 #ifndef USE_SKIA_TXT
47     SkFontMetrics fFontMetrics;
48     ParagraphPainter::DecorationStyle fDecorStyle;
49     SkPath fPath;
50 #else
51     RSFontMetrics fFontMetrics;
52     ParagraphPainter::DecorationStyle fDecorStyle;
53     RSPath fPath;
54 #endif
55 };
56 }  // namespace textlayout
57 }  // namespace skia
58 #endif
59