[Skwasm] Forward text height from paragraph height to default text style (flutter/engine#51819)
We need to apply the paragraph style's height to the initial default text style on the stack. I also added a `toString` method for `StrutStyle` so that things are a bit easier to debug.
This commit is contained in:
@@ -681,6 +681,31 @@ final class SkwasmStrutStyle extends SkwasmObjectWrapper<RawStrutStyle> implemen
|
||||
_forceStrutHeight,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String result = super.toString();
|
||||
assert(() {
|
||||
final List<String>? fontFamilyFallback = _fontFamilyFallback;
|
||||
final double? fontSize = _fontSize;
|
||||
final double? height = _height;
|
||||
final double? leading = _leading;
|
||||
result = 'StrutStyle('
|
||||
'fontFamily: ${_fontFamily ?? "unspecified"}, '
|
||||
'fontFamilyFallback: ${_fontFamilyFallback ?? "unspecified"}, '
|
||||
'fontFamilyFallback: ${fontFamilyFallback != null && fontFamilyFallback.isNotEmpty ? fontFamilyFallback : "unspecified"}, '
|
||||
'fontSize: ${fontSize != null ? fontSize.toStringAsFixed(1) : "unspecified"}, '
|
||||
'height: ${height != null ? "${height.toStringAsFixed(1)}x" : "unspecified"}, '
|
||||
'leading: ${leading != null ? "${leading.toStringAsFixed(1)}x" : "unspecified"}, '
|
||||
'fontWeight: ${_fontWeight ?? "unspecified"}, '
|
||||
'fontStyle: ${_fontStyle ?? "unspecified"}, '
|
||||
'forceStrutHeight: ${_forceStrutHeight ?? "unspecified"}, '
|
||||
'leadingDistribution: ${_leadingDistribution ?? "unspecified"}, '
|
||||
')';
|
||||
return true;
|
||||
}());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class SkwasmParagraphStyle extends SkwasmObjectWrapper<RawParagraphStyle> implements ui.ParagraphStyle {
|
||||
@@ -741,6 +766,9 @@ class SkwasmParagraphStyle extends SkwasmObjectWrapper<RawParagraphStyle> implem
|
||||
if (fontSize != null) {
|
||||
textStyleSetFontSize(textStyleHandle, fontSize);
|
||||
}
|
||||
if (height != null) {
|
||||
textStyleSetHeight(textStyleHandle, height);
|
||||
}
|
||||
if (fontWeight != null || fontStyle != null) {
|
||||
fontWeight ??= ui.FontWeight.normal;
|
||||
fontStyle ??= ui.FontStyle.normal;
|
||||
|
||||
@@ -57,6 +57,20 @@ Future<void> testMain() async {
|
||||
expect(paragraph.getLineMetricsAt(7), isNull);
|
||||
});
|
||||
|
||||
test('respects paragraph height', () {
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(
|
||||
fontSize: 10,
|
||||
height: 1.5,
|
||||
))..addText('A' * 10);
|
||||
final ui.Paragraph paragraph = builder.build();
|
||||
paragraph.layout(const ui.ParagraphConstraints(width: double.infinity));
|
||||
|
||||
expect(paragraph.numberOfLines, 1);
|
||||
final ui.LineMetrics? metrics = paragraph.getLineMetricsAt(0);
|
||||
expect(metrics, isNotNull);
|
||||
expect(metrics!.height, 15);
|
||||
});
|
||||
|
||||
test('Basic glyph metrics', () {
|
||||
const double fontSize = 10;
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(
|
||||
|
||||
Reference in New Issue
Block a user