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/Metrics.h" |
7 | #include "modules/skparagraph/include/ParagraphStyle.h" |
8 | #include "modules/skparagraph/include/TextStyle.h" |
9 | |
10 | class SkCanvas; |
11 | |
12 | namespace skia { |
13 | namespace textlayout { |
14 | |
15 | class Paragraph { |
16 | |
17 | public: |
18 | Paragraph(ParagraphStyle style, sk_sp<FontCollection> fonts); |
19 | |
20 | virtual ~Paragraph() = default; |
21 | |
22 | SkScalar getMaxWidth() { return fWidth; } |
23 | |
24 | SkScalar getHeight() { return fHeight; } |
25 | |
26 | SkScalar getMinIntrinsicWidth() { return fMinIntrinsicWidth; } |
27 | |
28 | SkScalar getMaxIntrinsicWidth() { return fMaxIntrinsicWidth; } |
29 | |
30 | SkScalar getAlphabeticBaseline() { return fAlphabeticBaseline; } |
31 | |
32 | SkScalar getIdeographicBaseline() { return fIdeographicBaseline; } |
33 | |
34 | SkScalar getLongestLine() { return fLongestLine; } |
35 | |
36 | bool didExceedMaxLines() { return fExceededMaxLines; } |
37 | |
38 | virtual void layout(SkScalar width) = 0; |
39 | |
40 | virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0; |
41 | |
42 | // Returns a vector of bounding boxes that enclose all text between |
43 | // start and end glyph indexes, including start and excluding end |
44 | virtual std::vector<TextBox> getRectsForRange(unsigned start, |
45 | unsigned end, |
46 | RectHeightStyle rectHeightStyle, |
47 | RectWidthStyle rectWidthStyle) = 0; |
48 | |
49 | virtual std::vector<TextBox> getRectsForPlaceholders() = 0; |
50 | |
51 | // Returns the index of the glyph that corresponds to the provided coordinate, |
52 | // with the top left corner as the origin, and +y direction as down |
53 | virtual PositionWithAffinity getGlyphPositionAtCoordinate(SkScalar dx, SkScalar dy) = 0; |
54 | |
55 | // Finds the first and last glyphs that define a word containing |
56 | // the glyph at index offset |
57 | virtual SkRange<size_t> getWordBoundary(unsigned offset) = 0; |
58 | |
59 | virtual void getLineMetrics(std::vector<LineMetrics>&) = 0; |
60 | |
61 | virtual size_t lineNumber() = 0; |
62 | |
63 | virtual void markDirty() = 0; |
64 | |
65 | // This function will return the number of unresolved glyphs or |
66 | // -1 if not applicable (has not been shaped yet - valid case) |
67 | virtual int32_t unresolvedGlyphs() = 0; |
68 | |
69 | // Experimental API that allows fast way to update "immutable" paragraph |
70 | virtual void updateTextAlign(TextAlign textAlign) = 0; |
71 | virtual void updateText(size_t from, SkString text) = 0; |
72 | virtual void updateFontSize(size_t from, size_t to, SkScalar fontSize) = 0; |
73 | virtual void updateForegroundPaint(size_t from, size_t to, SkPaint paint) = 0; |
74 | virtual void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) = 0; |
75 | |
76 | protected: |
77 | sk_sp<FontCollection> fFontCollection; |
78 | ParagraphStyle fParagraphStyle; |
79 | |
80 | // Things for Flutter |
81 | SkScalar fAlphabeticBaseline; |
82 | SkScalar fIdeographicBaseline; |
83 | SkScalar fHeight; |
84 | SkScalar fWidth; |
85 | SkScalar fMaxIntrinsicWidth; |
86 | SkScalar fMinIntrinsicWidth; |
87 | SkScalar fLongestLine; |
88 | bool fExceededMaxLines; |
89 | }; |
90 | } // namespace textlayout |
91 | } // namespace skia |
92 | |
93 | #endif // Paragraph_DEFINED |
94 | |