Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 404fe66

Browse files
[Skwasm] Forward text height from paragraph height to default text style (#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.
1 parent 9cc9cdc commit 404fe66

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,31 @@ final class SkwasmStrutStyle extends SkwasmObjectWrapper<RawStrutStyle> implemen
681681
_forceStrutHeight,
682682
);
683683
}
684+
685+
@override
686+
String toString() {
687+
String result = super.toString();
688+
assert(() {
689+
final List<String>? fontFamilyFallback = _fontFamilyFallback;
690+
final double? fontSize = _fontSize;
691+
final double? height = _height;
692+
final double? leading = _leading;
693+
result = 'StrutStyle('
694+
'fontFamily: ${_fontFamily ?? "unspecified"}, '
695+
'fontFamilyFallback: ${_fontFamilyFallback ?? "unspecified"}, '
696+
'fontFamilyFallback: ${fontFamilyFallback != null && fontFamilyFallback.isNotEmpty ? fontFamilyFallback : "unspecified"}, '
697+
'fontSize: ${fontSize != null ? fontSize.toStringAsFixed(1) : "unspecified"}, '
698+
'height: ${height != null ? "${height.toStringAsFixed(1)}x" : "unspecified"}, '
699+
'leading: ${leading != null ? "${leading.toStringAsFixed(1)}x" : "unspecified"}, '
700+
'fontWeight: ${_fontWeight ?? "unspecified"}, '
701+
'fontStyle: ${_fontStyle ?? "unspecified"}, '
702+
'forceStrutHeight: ${_forceStrutHeight ?? "unspecified"}, '
703+
'leadingDistribution: ${_leadingDistribution ?? "unspecified"}, '
704+
')';
705+
return true;
706+
}());
707+
return result;
708+
}
684709
}
685710

686711
class SkwasmParagraphStyle extends SkwasmObjectWrapper<RawParagraphStyle> implements ui.ParagraphStyle {
@@ -741,6 +766,9 @@ class SkwasmParagraphStyle extends SkwasmObjectWrapper<RawParagraphStyle> implem
741766
if (fontSize != null) {
742767
textStyleSetFontSize(textStyleHandle, fontSize);
743768
}
769+
if (height != null) {
770+
textStyleSetHeight(textStyleHandle, height);
771+
}
744772
if (fontWeight != null || fontStyle != null) {
745773
fontWeight ??= ui.FontWeight.normal;
746774
fontStyle ??= ui.FontStyle.normal;

lib/web_ui/test/ui/line_metrics_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ Future<void> testMain() async {
5757
expect(paragraph.getLineMetricsAt(7), isNull);
5858
});
5959

60+
test('respects paragraph height', () {
61+
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(
62+
fontSize: 10,
63+
height: 1.5,
64+
))..addText('A' * 10);
65+
final ui.Paragraph paragraph = builder.build();
66+
paragraph.layout(const ui.ParagraphConstraints(width: double.infinity));
67+
68+
expect(paragraph.numberOfLines, 1);
69+
final ui.LineMetrics? metrics = paragraph.getLineMetricsAt(0);
70+
expect(metrics, isNotNull);
71+
expect(metrics!.height, 15);
72+
});
73+
6074
test('Basic glyph metrics', () {
6175
const double fontSize = 10;
6276
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(

0 commit comments

Comments
 (0)