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
8ebd45d3
Unverified
Commit
8ebd45d3
authored
Dec 01, 2017
by
Hans Muller
Committed by
GitHub
Dec 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Workaround for TextPainter.computeDistanceToActualBaseline when the text is empty (#13305)
parent
2135f3c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
2 deletions
+40
-2
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+25
-2
text_painter_rtl_test.dart
packages/flutter/test/painting/text_painter_rtl_test.dart
+15
-0
No files found.
packages/flutter/lib/src/painting/text_painter.dart
View file @
8ebd45d3
...
...
@@ -285,6 +285,29 @@ class TextPainter {
return
new
Size
(
width
,
height
);
}
// Workaround for https://github.com/flutter/flutter/issues/13303
double
_workaroundBaselineBug
(
double
value
,
TextBaseline
baseline
)
{
if
(
value
>=
0.0
)
return
value
;
final
ui
.
ParagraphBuilder
builder
=
new
ui
.
ParagraphBuilder
(
_createParagraphStyle
(
TextDirection
.
ltr
),
);
if
(
text
?.
style
!=
null
)
builder
.
pushStyle
(
text
.
style
.
getTextStyle
(
textScaleFactor:
textScaleFactor
));
builder
.
addText
(
_kZeroWidthSpace
);
final
ui
.
Paragraph
paragraph
=
builder
.
build
()
..
layout
(
new
ui
.
ParagraphConstraints
(
width:
double
.
INFINITY
));
switch
(
baseline
)
{
case
TextBaseline
.
alphabetic
:
return
paragraph
.
alphabeticBaseline
;
case
TextBaseline
.
ideographic
:
return
paragraph
.
ideographicBaseline
;
}
return
null
;
}
/// Returns the distance from the top of the text to the first baseline of the
/// given type.
///
...
...
@@ -294,9 +317,9 @@ class TextPainter {
assert
(
baseline
!=
null
);
switch
(
baseline
)
{
case
TextBaseline
.
alphabetic
:
return
_
paragraph
.
alphabeticBaseline
;
return
_
workaroundBaselineBug
(
_paragraph
.
alphabeticBaseline
,
baseline
)
;
case
TextBaseline
.
ideographic
:
return
_paragraph
.
ideographicBaseline
;
return
_workaroundBaselineBug
(
_paragraph
.
ideographicBaseline
,
baseline
)
;
}
return
null
;
}
...
...
packages/flutter/test/painting/text_painter_rtl_test.dart
View file @
8ebd45d3
...
...
@@ -658,6 +658,21 @@ void main() {
skip:
skipExpectsWithKnownBugs
,
);
},
skip:
skipTestsWithKnownBugs
);
test
(
'TextPainter - empty text baseline'
,
()
{
final
TextPainter
painter
=
new
TextPainter
()
..
textDirection
=
TextDirection
.
ltr
;
painter
.
text
=
const
TextSpan
(
text:
''
,
style:
const
TextStyle
(
fontFamily:
'Ahem'
,
fontSize:
100.0
,
height:
1.0
),
);
painter
.
layout
();
expect
(
// Returns -1
painter
.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
),
80.0
,
skip:
skipExpectsWithKnownBugs
,
);
},
skip:
skipTestsWithKnownBugs
);
}
...
...
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