Unverified Commit d8f2f369 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Use a space instead of a zero-width space to calculate the preferred height of...

Use a space instead of a zero-width space to calculate the preferred height of a line of text (#16972)

The zero-width space character may not be supported by the font requested in
the text style.  If that happens, then libtxt will fall back to another font
to render that character, resulting in text metrics that do not match the
intended font.

Fixes https://github.com/flutter/flutter/issues/16257
parent 9765f0af
......@@ -13,8 +13,6 @@ import 'text_span.dart';
export 'package:flutter/services.dart' show TextRange, TextSelection;
final String _kZeroWidthSpace = new String.fromCharCode(0x200B);
/// An object that paints a [TextSpan] tree into a [Canvas].
///
/// To use a [TextPainter], follow these steps:
......@@ -222,7 +220,7 @@ class TextPainter {
);
}
/// The height of a zero-width space in [text] in logical pixels.
/// The height of a space in [text] in logical pixels.
///
/// Not every line of text in [text] will have this height, but this height
/// is "typical" for text in [text] and useful for sizing other objects
......@@ -238,10 +236,10 @@ class TextPainter {
if (_layoutTemplate == null) {
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(
_createParagraphStyle(TextDirection.rtl),
); // direction doesn't matter, text is just a zero width space
); // direction doesn't matter, text is just a space
if (text?.style != null)
builder.pushStyle(text.style.getTextStyle(textScaleFactor: textScaleFactor));
builder.addText(_kZeroWidthSpace);
builder.addText(' ');
_layoutTemplate = builder.build()
..layout(new ui.ParagraphConstraints(width: double.infinity));
}
......
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