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
This commit is contained in:
parent
9765f0af00
commit
d8f2f36935
@ -13,8 +13,6 @@ import 'text_span.dart';
|
|||||||
|
|
||||||
export 'package:flutter/services.dart' show TextRange, TextSelection;
|
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].
|
/// An object that paints a [TextSpan] tree into a [Canvas].
|
||||||
///
|
///
|
||||||
/// To use a [TextPainter], follow these steps:
|
/// 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
|
/// 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
|
/// is "typical" for text in [text] and useful for sizing other objects
|
||||||
@ -238,10 +236,10 @@ class TextPainter {
|
|||||||
if (_layoutTemplate == null) {
|
if (_layoutTemplate == null) {
|
||||||
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(
|
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(
|
||||||
_createParagraphStyle(TextDirection.rtl),
|
_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)
|
if (text?.style != null)
|
||||||
builder.pushStyle(text.style.getTextStyle(textScaleFactor: textScaleFactor));
|
builder.pushStyle(text.style.getTextStyle(textScaleFactor: textScaleFactor));
|
||||||
builder.addText(_kZeroWidthSpace);
|
builder.addText(' ');
|
||||||
_layoutTemplate = builder.build()
|
_layoutTemplate = builder.build()
|
||||||
..layout(new ui.ParagraphConstraints(width: double.infinity));
|
..layout(new ui.ParagraphConstraints(width: double.infinity));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user