Flutter Engine
The Flutter Engine
third_party
txt
src
txt
paragraph.h
Go to the documentation of this file.
1
2
/*
3
* Copyright 2017 Google Inc.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
#ifndef LIB_TXT_SRC_PARAGRAPH_H_
19
#define LIB_TXT_SRC_PARAGRAPH_H_
20
21
#include "flutter/display_list/dl_builder.h"
22
#include "
line_metrics.h
"
23
#include "
paragraph_style.h
"
24
#include "
third_party/skia/include/core/SkFont.h
"
25
#include "
third_party/skia/include/core/SkRect.h
"
26
#include "
third_party/skia/modules/skparagraph/include/Metrics.h
"
27
#include "
third_party/skia/modules/skparagraph/include/Paragraph.h
"
28
29
class
SkCanvas
;
30
31
namespace
txt
{
32
33
// Interface for text layout engines. The current implementation is based on
34
// Skia's SkShaper/SkParagraph text layout module.
35
class
Paragraph
{
36
public
:
37
enum
Affinity
{
UPSTREAM
,
DOWNSTREAM
};
38
39
// Options for various types of bounding boxes provided by
40
// GetRectsForRange(...).
41
enum class
RectHeightStyle
{
42
// Provide tight bounding boxes that fit heights per run.
43
kTight,
44
45
// The height of the boxes will be the maximum height of all runs in the
46
// line. All rects in the same line will be the same height.
47
kMax,
48
49
// Extends the top and/or bottom edge of the bounds to fully cover any line
50
// spacing. The top edge of each line should be the same as the bottom edge
51
// of the line above. There should be no gaps in vertical coverage given any
52
// ParagraphStyle line_height.
53
//
54
// The top and bottom of each rect will cover half of the
55
// space above and half of the space below the line.
56
kIncludeLineSpacingMiddle,
57
// The line spacing will be added to the top of the rect.
58
kIncludeLineSpacingTop,
59
// The line spacing will be added to the bottom of the rect.
60
kIncludeLineSpacingBottom,
61
62
// Calculate boxes based on the strut's metrics.
63
kStrut
64
};
65
66
enum class
RectWidthStyle
{
67
// Provide tight bounding boxes that fit widths to the runs of each line
68
// independently.
69
kTight,
70
71
// Extends the width of the last rect of each line to match the position of
72
// the widest rect over all the lines.
73
kMax
74
};
75
76
struct
PositionWithAffinity
{
77
const
size_t
position
;
78
const
Affinity
affinity
;
79
80
PositionWithAffinity
(
size_t
p
,
Affinity
a
) :
position
(
p
),
affinity
(
a
) {}
81
};
82
83
struct
TextBox
{
84
SkRect
rect
;
85
TextDirection
direction
;
86
87
TextBox
(
SkRect
r,
TextDirection
d
) :
rect
(r),
direction
(
d
) {}
88
};
89
90
template
<
typename
T>
91
struct
Range
{
92
Range
() :
start
(),
end
() {}
93
Range
(
T
s
,
T
e
) :
start
(
s
),
end
(
e
) {}
94
95
T
start
,
end
;
96
97
bool
operator==
(
const
Range<T>
& other)
const
{
98
return
start
== other.
start
&&
end
== other.
end
;
99
}
100
101
T
width
()
const
{
return
end
-
start
; }
102
103
void
Shift
(
T
delta
) {
104
start
+=
delta
;
105
end
+=
delta
;
106
}
107
};
108
109
virtual
~Paragraph
() =
default
;
110
111
// Returns the width provided in the Layout() method. This is the maximum
112
// width any line in the laid out paragraph can occupy. We expect that
113
// GetMaxWidth() >= GetLayoutWidth().
114
virtual
double
GetMaxWidth
() = 0;
115
116
// Returns the height of the laid out paragraph. NOTE this is not a tight
117
// bounding height of the glyphs, as some glyphs do not reach as low as they
118
// can.
119
virtual
double
GetHeight
() = 0;
120
121
// Returns the width of the longest line as found in Layout(), which is
122
// defined as the horizontal distance from the left edge of the leftmost glyph
123
// to the right edge of the rightmost glyph. We expect that
124
// GetLongestLine() <= GetMaxWidth().
125
virtual
double
GetLongestLine
() = 0;
126
127
// Returns the actual max width of the longest line after Layout().
128
virtual
double
GetMinIntrinsicWidth
() = 0;
129
130
// Returns the total width covered by the paragraph without linebreaking.
131
virtual
double
GetMaxIntrinsicWidth
() = 0;
132
133
// Distance from top of paragraph to the Alphabetic baseline of the first
134
// line. Used for alphabetic fonts (A-Z, a-z, greek, etc.)
135
virtual
double
GetAlphabeticBaseline
() = 0;
136
137
// Distance from top of paragraph to the Ideographic baseline of the first
138
// line. Used for ideographic fonts (Chinese, Japanese, Korean, etc.)
139
virtual
double
GetIdeographicBaseline
() = 0;
140
141
// Checks if the layout extends past the maximum lines and had to be
142
// truncated.
143
virtual
bool
DidExceedMaxLines
() = 0;
144
145
// Layout calculates the positioning of all the glyphs. Must call this method
146
// before Painting and getting any statistics from this class.
147
virtual
void
Layout
(
double
width
) = 0;
148
149
// Paints the laid out text onto the supplied DisplayListBuilder at
150
// (x, y) offset from the origin. Only valid after Layout() is called.
151
virtual
bool
Paint
(
flutter::DisplayListBuilder
*
builder
,
152
double
x
,
153
double
y
) = 0;
154
155
// Returns a vector of bounding boxes that enclose all text between start and
156
// end glyph indexes, including start and excluding end.
157
virtual
std::vector<TextBox>
GetRectsForRange
(
158
size_t
start,
159
size_t
end,
160
RectHeightStyle
rect_height_style,
161
RectWidthStyle
rect_width_style) = 0;
162
163
// Returns a vector of bounding boxes that bound all inline placeholders in
164
// the paragraph.
165
//
166
// There will be one box for each inline placeholder. The boxes will be in the
167
// same order as they were added to the paragraph. The bounds will always be
168
// tight and should fully enclose the area where the placeholder should be.
169
//
170
// More granular boxes may be obtained through GetRectsForRange, which will
171
// return bounds on both text as well as inline placeholders.
172
virtual
std::vector<TextBox>
GetRectsForPlaceholders
() = 0;
173
174
// Returns the index of the glyph that corresponds to the provided coordinate,
175
// with the top left corner as the origin, and +y direction as down.
176
virtual
PositionWithAffinity
GetGlyphPositionAtCoordinate
(
double
dx
,
177
double
dy) = 0;
178
179
virtual
bool
GetGlyphInfoAt
(
180
unsigned
offset
,
181
skia::textlayout::Paragraph::GlyphInfo
* glyphInfo)
const
= 0;
182
183
virtual
bool
GetClosestGlyphInfoAtCoordinate
(
184
double
dx
,
185
double
dy,
186
skia::textlayout::Paragraph::GlyphInfo
* glyphInfo)
const
= 0;
187
188
// Finds the first and last glyphs that define a word containing the glyph at
189
// index offset.
190
virtual
Range<size_t>
GetWordBoundary
(
size_t
offset
) = 0;
191
192
virtual
std::vector<LineMetrics>&
GetLineMetrics
() = 0;
193
194
virtual
bool
GetLineMetricsAt
(
195
int
lineNumber,
196
skia::textlayout::LineMetrics
* lineMetrics)
const
= 0;
197
198
// Returns the total number of visible lines in the paragraph.
199
virtual
size_t
GetNumberOfLines
()
const
= 0;
200
201
// Returns the zero-indexed line number that contains the given code unit
202
// offset. Returns -1 if the given offset is out of bounds, or points to a
203
// codepoint that is logically after the last visible codepoint.
204
//
205
// If the offset points to a hard line break, this method returns the line
206
// number of the line this hard line break breaks, intead of the new line it
207
// creates.
208
virtual
int
GetLineNumberAt
(
size_t
utf16Offset)
const
= 0;
209
};
210
211
}
// namespace txt
212
213
#endif
// LIB_TXT_SRC_PARAGRAPH_H_
Metrics.h
Paragraph.h
SkFont.h
SkRect.h
SkCanvas
Definition:
SkCanvas.h:106
flutter::DisplayListBuilder
Definition:
dl_builder.h:30
flutter::Paragraph
Definition:
paragraph.h:15
flutter::Paragraph::width
double width()
Definition:
paragraph.cc:29
skia::textlayout::LineMetrics
Definition:
Metrics.h:39
txt::Paragraph::GetLongestLine
virtual double GetLongestLine()=0
txt::Paragraph::~Paragraph
virtual ~Paragraph()=default
txt::Paragraph::GetRectsForRange
virtual std::vector< TextBox > GetRectsForRange(size_t start, size_t end, RectHeightStyle rect_height_style, RectWidthStyle rect_width_style)=0
txt::Paragraph::Layout
virtual void Layout(double width)=0
txt::Paragraph::GetGlyphInfoAt
virtual bool GetGlyphInfoAt(unsigned offset, skia::textlayout::Paragraph::GlyphInfo *glyphInfo) const =0
txt::Paragraph::GetLineMetrics
virtual std::vector< LineMetrics > & GetLineMetrics()=0
txt::Paragraph::RectHeightStyle
RectHeightStyle
Definition:
paragraph.h:41
txt::Paragraph::GetNumberOfLines
virtual size_t GetNumberOfLines() const =0
txt::Paragraph::GetClosestGlyphInfoAtCoordinate
virtual bool GetClosestGlyphInfoAtCoordinate(double dx, double dy, skia::textlayout::Paragraph::GlyphInfo *glyphInfo) const =0
txt::Paragraph::DidExceedMaxLines
virtual bool DidExceedMaxLines()=0
txt::Paragraph::GetHeight
virtual double GetHeight()=0
txt::Paragraph::GetLineMetricsAt
virtual bool GetLineMetricsAt(int lineNumber, skia::textlayout::LineMetrics *lineMetrics) const =0
txt::Paragraph::GetMinIntrinsicWidth
virtual double GetMinIntrinsicWidth()=0
txt::Paragraph::GetAlphabeticBaseline
virtual double GetAlphabeticBaseline()=0
txt::Paragraph::GetLineNumberAt
virtual int GetLineNumberAt(size_t utf16Offset) const =0
txt::Paragraph::Paint
virtual bool Paint(flutter::DisplayListBuilder *builder, double x, double y)=0
txt::Paragraph::GetGlyphPositionAtCoordinate
virtual PositionWithAffinity GetGlyphPositionAtCoordinate(double dx, double dy)=0
txt::Paragraph::GetWordBoundary
virtual Range< size_t > GetWordBoundary(size_t offset)=0
txt::Paragraph::GetMaxIntrinsicWidth
virtual double GetMaxIntrinsicWidth()=0
txt::Paragraph::GetIdeographicBaseline
virtual double GetIdeographicBaseline()=0
txt::Paragraph::GetRectsForPlaceholders
virtual std::vector< TextBox > GetRectsForPlaceholders()=0
txt::Paragraph::GetMaxWidth
virtual double GetMaxWidth()=0
txt::Paragraph::Affinity
Affinity
Definition:
paragraph.h:37
txt::Paragraph::DOWNSTREAM
@ DOWNSTREAM
Definition:
paragraph.h:37
txt::Paragraph::UPSTREAM
@ UPSTREAM
Definition:
paragraph.h:37
txt::Paragraph::RectWidthStyle
RectWidthStyle
Definition:
paragraph.h:66
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
s
struct MyStruct s
a
struct MyStruct a[10]
line_metrics.h
y
double y
Definition:
mouse-input-test.cc:83
x
double x
Definition:
mouse-input-test.cc:82
SkRecords::dx
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition:
SkRecords.h:208
dart_profiler_symbols.p
p
Definition:
dart_profiler_symbols.py:55
dependency.builder
builder
Definition:
dependency.py:1
generate_fir_coeff.delta
int delta
Definition:
generate_fir_coeff.py:92
protoc_wrapper.e
e
Definition:
protoc_wrapper.py:226
txt
Definition:
paragraph_builder_skia.cc:27
txt::TextDirection
TextDirection
Definition:
paragraph_style.h:38
paragraph_style.h
T
#define T
Definition:
precompiler.cc:65
offset
SeparatedVector2 offset
Definition:
stroke_path_geometry.cc:311
SkRect
Definition:
extension.cpp:13
skia::textlayout::Paragraph::GlyphInfo
Definition:
Paragraph.h:211
txt::Paragraph::PositionWithAffinity
Definition:
paragraph.h:76
txt::Paragraph::PositionWithAffinity::PositionWithAffinity
PositionWithAffinity(size_t p, Affinity a)
Definition:
paragraph.h:80
txt::Paragraph::PositionWithAffinity::position
const size_t position
Definition:
paragraph.h:77
txt::Paragraph::PositionWithAffinity::affinity
const Affinity affinity
Definition:
paragraph.h:78
txt::Paragraph::Range
Definition:
paragraph.h:91
txt::Paragraph::Range::Shift
void Shift(T delta)
Definition:
paragraph.h:103
txt::Paragraph::Range::start
T start
Definition:
paragraph.h:95
txt::Paragraph::Range::Range
Range()
Definition:
paragraph.h:92
txt::Paragraph::Range::end
T end
Definition:
paragraph.h:95
txt::Paragraph::Range::width
T width() const
Definition:
paragraph.h:101
txt::Paragraph::Range::operator==
bool operator==(const Range< T > &other) const
Definition:
paragraph.h:97
txt::Paragraph::Range::Range
Range(T s, T e)
Definition:
paragraph.h:93
txt::Paragraph::TextBox
Definition:
paragraph.h:83
txt::Paragraph::TextBox::TextBox
TextBox(SkRect r, TextDirection d)
Definition:
paragraph.h:87
txt::Paragraph::TextBox::rect
SkRect rect
Definition:
paragraph.h:84
txt::Paragraph::TextBox::direction
TextDirection direction
Definition:
paragraph.h:85
Generated on Sun Jun 23 2024 21:55:06 for Flutter Engine by
1.9.4