Unverified Commit 8ebd45d3 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Workaround for TextPainter.computeDistanceToActualBaseline when the text is empty (#13305)

parent 2135f3c0
......@@ -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;
}
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment