Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Skwasm] Forward text height from paragraph height to default text style #51819

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "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 {
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions lib/web_ui/test/ui/line_metrics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down