Skip to content

Commit 04ad498

Browse files
authored
Merge branch 'master' into webparagraph_leading_distribution
2 parents 525c681 + 38785ef commit 04ad498

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

‎engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/layout.dart‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:ui/ui.dart' as ui;
99

1010
import '../canvaskit/canvaskit_api.dart';
1111
import '../dom.dart';
12+
import '../view_embedder/style_manager.dart';
1213
import 'bidi.dart';
1314
import 'code_unit_flags.dart';
1415
import 'debug.dart';
@@ -1193,12 +1194,14 @@ abstract class LineBlock {
11931194
this.textRange,
11941195
this.shiftFromLineStart,
11951196
) {
1196-
if (span.style.height == null) {
1197+
// When height is null or kTextHeightNone, disable the height multiplier
1198+
// and use the font's raw ascent and descent directly.
1199+
if (span.style.height == null || span.style.height == ui.kTextHeightNone) {
11971200
_multipliedFontBoundingBoxAscent = span.fontBoundingBoxAscent;
11981201
_multipliedFontBoundingBoxDescent = span.fontBoundingBoxDescent;
11991202
return;
12001203
}
1201-
final double fontSize = span.style.fontSize ?? 14.0;
1204+
final double fontSize = span.style.fontSize ?? StyleManager.defaultFontSize;
12021205
final double runHeight = span.style.height! * fontSize;
12031206
final double fontHeight = span.fontBoundingBoxAscent + span.fontBoundingBoxDescent;
12041207
switch (span.style.leadingDistribution) {

‎engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,11 @@ class ChildStyleNode extends StyleNode {
15071507
@override
15081508
double? get _wordSpacing => style.wordSpacing ?? parent._wordSpacing;
15091509

1510+
// Preserve `style.height` as-is (including `ui.kTextHeightNone`) so a child
1511+
// span can explicitly override a non-null parent height and disable the
1512+
// height multiplier during layout.
15101513
@override
1511-
double? get _height {
1512-
return style.height == ui.kTextHeightNone ? null : (style.height ?? parent._height);
1513-
}
1514+
double? get _height => style.height ?? parent._height;
15141515

15151516
@override
15161517
ui.TextLeadingDistribution? get _leadingDistribution =>

‎engine/src/flutter/lib/web_ui/test/webparagraph/paragraph_get_boxes_test.dart‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,47 @@ Future<void> testMain() async {
301301
expect(boxes2.isNotEmpty && boxes2.length == 1, true);
302302
expect(boxes1.first.toRect().bottom >= boxes2.first.toRect().top, true);
303303
});
304+
305+
test('layout with kTextHeightNone disables parent height multiplier', () {
306+
// Pushing a child TextStyle with kTextHeightNone overrides the parent ParagraphStyle's
307+
// height multiplier (3.0) and lays out the line at its unscaled font height.
308+
final builderWithNone = ui.ParagraphBuilder(
309+
ui.ParagraphStyle(fontFamily: 'Arial', fontSize: 20, height: 3.0),
310+
);
311+
builderWithNone.pushStyle(ui.TextStyle(height: ui.kTextHeightNone));
312+
builderWithNone.addText('Hello');
313+
final ui.Paragraph paragraphWithNone = builderWithNone.build()
314+
..layout(const ui.ParagraphConstraints(width: 500));
315+
316+
final builderDefault = ui.ParagraphBuilder(
317+
ui.ParagraphStyle(fontFamily: 'Arial', fontSize: 20),
318+
);
319+
builderDefault.addText('Hello');
320+
final ui.Paragraph paragraphDefault = builderDefault.build()
321+
..layout(const ui.ParagraphConstraints(width: 500));
322+
323+
expect(paragraphWithNone.height, greaterThan(0));
324+
expect(paragraphWithNone.height, paragraphDefault.height);
325+
});
326+
327+
test('layout with ParagraphStyle(kTextHeightNone)', () {
328+
// Passing kTextHeightNone directly on ParagraphStyle produces the same unscaled
329+
// line height as omitting height (null), rather than multiplying by 0.0.
330+
final builderWithNone = ui.ParagraphBuilder(
331+
ui.ParagraphStyle(fontFamily: 'Arial', fontSize: 20, height: ui.kTextHeightNone),
332+
);
333+
builderWithNone.addText('Hello');
334+
final ui.Paragraph paragraphWithNone = builderWithNone.build()
335+
..layout(const ui.ParagraphConstraints(width: 500));
336+
337+
final builderDefault = ui.ParagraphBuilder(
338+
ui.ParagraphStyle(fontFamily: 'Arial', fontSize: 20),
339+
);
340+
builderDefault.addText('Hello');
341+
final ui.Paragraph paragraphDefault = builderDefault.build()
342+
..layout(const ui.ParagraphConstraints(width: 500));
343+
344+
expect(paragraphWithNone.height, greaterThan(0));
345+
expect(paragraphWithNone.height, paragraphDefault.height);
346+
});
304347
}

0 commit comments

Comments
 (0)