Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7e361d74
Unverified
Commit
7e361d74
authored
Aug 30, 2019
by
Gary Qian
Committed by
GitHub
Aug 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reland "Expose LineMetrics in TextPainter (#39282)" (#39519)
parent
37846b03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
1 deletion
+82
-1
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+21
-1
text_painter_test.dart
packages/flutter/test/painting/text_painter_test.dart
+61
-0
No files found.
packages/flutter/lib/src/painting/text_painter.dart
View file @
7e361d74
...
...
@@ -3,7 +3,7 @@
// found in the LICENSE file.
import
'dart:math'
show
min
,
max
;
import
'dart:ui'
as
ui
show
Paragraph
,
ParagraphBuilder
,
ParagraphConstraints
,
ParagraphStyle
,
PlaceholderAlignment
;
import
'dart:ui'
as
ui
show
Paragraph
,
ParagraphBuilder
,
ParagraphConstraints
,
ParagraphStyle
,
PlaceholderAlignment
,
LineMetrics
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -816,4 +816,24 @@ class TextPainter {
final
List
<
int
>
indices
=
_paragraph
.
getWordBoundary
(
position
.
offset
);
return
TextRange
(
start:
indices
[
0
],
end:
indices
[
1
]);
}
/// Returns the full list of [LineMetrics] that describe in detail the various
/// metrics of each laid out line.
///
/// The [LineMetrics] list is presented in the order of the lines they represent.
/// For example, the first line is in the zeroth index.
///
/// [LineMetrics] contains measurements such as ascent, descent, baseline, and
/// width for the line as a whole, and may be useful for aligning additional
/// widgets to a particular line.
///
/// Valid only after [layout] has been called.
///
/// This can potentially return a large amount of data, so it is not recommended
/// to repeatedly call this. Instead, cache the results. The cached results
/// should be invalidated upon the next sucessful [layout].
List
<
ui
.
LineMetrics
>
computeLineMetrics
()
{
assert
(!
_needsLayout
);
return
_paragraph
.
computeLineMetrics
();
}
}
packages/flutter/test/painting/text_painter_test.dart
View file @
7e361d74
...
...
@@ -729,4 +729,65 @@ void main() {
expect
(
painter
.
inlinePlaceholderBoxes
[
12
],
const
TextBox
.
fromLTRBD
(
300
,
30
,
351
,
60
,
TextDirection
.
ltr
));
expect
(
painter
.
inlinePlaceholderBoxes
[
13
],
const
TextBox
.
fromLTRBD
(
351
,
30
,
401
,
60
,
TextDirection
.
ltr
));
},
skip:
isBrowser
);
test
(
'TextPainter line metrics'
,
()
{
final
TextPainter
painter
=
TextPainter
()
..
textDirection
=
TextDirection
.
ltr
;
const
String
text
=
'test1
\n
hello line two really long for soft break
\n
final line 4'
;
painter
.
text
=
const
TextSpan
(
text:
text
,
);
painter
.
layout
(
maxWidth:
300
);
final
List
<
ui
.
LineMetrics
>
lines
=
painter
.
computeLineMetrics
();
expect
(
lines
.
length
,
4
);
expect
(
lines
[
0
].
hardBreak
,
true
);
expect
(
lines
[
1
].
hardBreak
,
false
);
expect
(
lines
[
2
].
hardBreak
,
true
);
expect
(
lines
[
3
].
hardBreak
,
true
);
expect
(
lines
[
0
].
ascent
,
11.199999809265137
);
expect
(
lines
[
1
].
ascent
,
11.199999809265137
);
expect
(
lines
[
2
].
ascent
,
11.199999809265137
);
expect
(
lines
[
3
].
ascent
,
11.199999809265137
);
expect
(
lines
[
0
].
descent
,
2.799999952316284
);
expect
(
lines
[
1
].
descent
,
2.799999952316284
);
expect
(
lines
[
2
].
descent
,
2.799999952316284
);
expect
(
lines
[
3
].
descent
,
2.799999952316284
);
expect
(
lines
[
0
].
unscaledAscent
,
11.199999809265137
);
expect
(
lines
[
1
].
unscaledAscent
,
11.199999809265137
);
expect
(
lines
[
2
].
unscaledAscent
,
11.199999809265137
);
expect
(
lines
[
3
].
unscaledAscent
,
11.199999809265137
);
expect
(
lines
[
0
].
baseline
,
11.200000047683716
);
expect
(
lines
[
1
].
baseline
,
25.200000047683716
);
expect
(
lines
[
2
].
baseline
,
39.200000047683716
);
expect
(
lines
[
3
].
baseline
,
53.200000047683716
);
expect
(
lines
[
0
].
height
,
14
);
expect
(
lines
[
1
].
height
,
14
);
expect
(
lines
[
2
].
height
,
14
);
expect
(
lines
[
3
].
height
,
14
);
expect
(
lines
[
0
].
width
,
70
);
expect
(
lines
[
1
].
width
,
294
);
expect
(
lines
[
2
].
width
,
266
);
expect
(
lines
[
3
].
width
,
168
);
expect
(
lines
[
0
].
left
,
0
);
expect
(
lines
[
1
].
left
,
0
);
expect
(
lines
[
2
].
left
,
0
);
expect
(
lines
[
3
].
left
,
0
);
expect
(
lines
[
0
].
lineNumber
,
0
);
expect
(
lines
[
1
].
lineNumber
,
1
);
expect
(
lines
[
2
].
lineNumber
,
2
);
expect
(
lines
[
3
].
lineNumber
,
3
);
},
skip:
!
isLinux
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment