• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC.
2 #ifndef Paragraph_DEFINED
3 #define Paragraph_DEFINED
4 
5 #include "modules/skparagraph/include/FontCollection.h"
6 #include "modules/skparagraph/include/ParagraphStyle.h"
7 #include "modules/skparagraph/include/TextStyle.h"
8 
9 class SkCanvas;
10 
11 namespace skia {
12 namespace textlayout {
13 
14 class Paragraph {
15 
16 public:
Paragraph(ParagraphStyle style,sk_sp<FontCollection> fonts)17     Paragraph(ParagraphStyle style, sk_sp<FontCollection> fonts)
18             : fFontCollection(std::move(fonts)), fParagraphStyle(std::move(style)) {}
19 
20     virtual ~Paragraph() = default;
21 
getMaxWidth()22     SkScalar getMaxWidth() { return fWidth; }
23 
getHeight()24     SkScalar getHeight() { return fHeight; }
25 
getMinIntrinsicWidth()26     SkScalar getMinIntrinsicWidth() { return fMinIntrinsicWidth; }
27 
getMaxIntrinsicWidth()28     SkScalar getMaxIntrinsicWidth() { return fMaxIntrinsicWidth; }
29 
getAlphabeticBaseline()30     SkScalar getAlphabeticBaseline() { return fAlphabeticBaseline; }
31 
getIdeographicBaseline()32     SkScalar getIdeographicBaseline() { return fIdeographicBaseline; }
33 
34     virtual bool didExceedMaxLines() = 0;
35 
36     virtual void layout(SkScalar width) = 0;
37 
38     virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0;
39 
40     // Returns a vector of bounding boxes that enclose all text between
41     // start and end glyph indexes, including start and excluding end
42     virtual std::vector<TextBox> getRectsForRange(unsigned start,
43                                                   unsigned end,
44                                                   RectHeightStyle rectHeightStyle,
45                                                   RectWidthStyle rectWidthStyle) = 0;
46 
47     // Returns the index of the glyph that corresponds to the provided coordinate,
48     // with the top left corner as the origin, and +y direction as down
49     virtual PositionWithAffinity getGlyphPositionAtCoordinate(SkScalar dx, SkScalar dy) = 0;
50 
51     // Finds the first and last glyphs that define a word containing
52     // the glyph at index offset
53     virtual SkRange<size_t> getWordBoundary(unsigned offset) = 0;
54 
55     virtual size_t lineNumber() = 0;
56 
57     virtual void markDirty() = 0;
58 
59 protected:
60     sk_sp<FontCollection> fFontCollection;
61     ParagraphStyle fParagraphStyle;
62 
63     // Things for Flutter
64     SkScalar fAlphabeticBaseline;
65     SkScalar fIdeographicBaseline;
66     SkScalar fHeight;
67     SkScalar fWidth;
68     SkScalar fMaxIntrinsicWidth;
69     SkScalar fMinIntrinsicWidth;
70 };
71 }  // namespace textlayout
72 }  // namespace skia
73 
74 #endif  // Paragraph_DEFINED
75