Skip to content

Commit a23c813

Browse files
Remove strut migration flag from TextPainter (#144242)
Fixes flutter/flutter#142969. G3fix: cl/610790040
1 parent d1d9605 commit a23c813

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

packages/flutter/lib/src/painting/text_painter.dart

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,6 @@ class TextPainter {
683683
}
684684
}
685685

686-
@Deprecated( // flutter_ignore: deprecation_syntax (see analyze.dart)
687-
'The disableStrutHalfLeading flag is for internal migration purposes only and should not be used.'
688-
)
689-
/// Migration only flag, do not use.
690-
static bool disableStrutHalfLeading = true;
691-
692686
// Whether textWidthBasis has changed after the most recent `layout` call.
693687
bool _debugNeedsRelayout = true;
694688
// The result of the most recent `layout` call.
@@ -1024,25 +1018,6 @@ class TextPainter {
10241018
ui.ParagraphStyle _createParagraphStyle([ TextAlign? textAlignOverride ]) {
10251019
assert(textDirection != null, 'TextPainter.textDirection must be set to a non-null value before using the TextPainter.');
10261020
final TextStyle baseStyle = _text?.style ?? const TextStyle();
1027-
final StrutStyle? strutStyle = _strutStyle;
1028-
1029-
final bool applyMigration = !kIsWeb && TextPainter.disableStrutHalfLeading
1030-
&& strutStyle != null && (strutStyle.forceStrutHeight ?? false)
1031-
&& strutStyle.leadingDistribution == TextLeadingDistribution.even;
1032-
final StrutStyle? strutStyleForMigration = !applyMigration
1033-
? strutStyle
1034-
: StrutStyle(
1035-
fontFamily: strutStyle.fontFamily,
1036-
fontFamilyFallback: strutStyle.fontFamilyFallback,
1037-
fontSize: strutStyle.fontSize,
1038-
height: strutStyle.height,
1039-
leadingDistribution: TextLeadingDistribution.proportional,
1040-
leading: strutStyle.leading,
1041-
fontWeight: strutStyle.fontWeight,
1042-
fontStyle: strutStyle.fontStyle,
1043-
forceStrutHeight: strutStyle.forceStrutHeight,
1044-
);
1045-
10461021
return baseStyle.getParagraphStyle(
10471022
textAlign: textAlignOverride ?? textAlign,
10481023
textDirection: textDirection,
@@ -1051,7 +1026,7 @@ class TextPainter {
10511026
textHeightBehavior: _textHeightBehavior,
10521027
ellipsis: _ellipsis,
10531028
locale: _locale,
1054-
strutStyle: strutStyleForMigration,
1029+
strutStyle: _strutStyle,
10551030
);
10561031
}
10571032

packages/flutter/test/painting/text_painter_test.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ void main() {
16321632
expect(painter.computeDistanceToActualBaseline(TextBaseline.alphabetic), 10 + 10 * 7.5);
16331633
});
16341634

1635-
test('force strut height', () {
1635+
test('strut no half leading + force strut height', () {
16361636
const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true);
16371637
final TextPainter painter = TextPainter(
16381638
textDirection: TextDirection.ltr,
@@ -1646,6 +1646,34 @@ void main() {
16461646
const <ui.TextBox>[TextBox.fromLTRBD(0, baseline - 15, 20, baseline + 5, TextDirection.ltr)],
16471647
);
16481648
});
1649+
1650+
test('strut half leading + force strut height', () {
1651+
const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true, leadingDistribution: TextLeadingDistribution.even);
1652+
final TextPainter painter = TextPainter(
1653+
textDirection: TextDirection.ltr,
1654+
text: const TextSpan(text: 'A', style: TextStyle(fontSize: 20)),
1655+
strutStyle: strut,
1656+
)..layout();
1657+
expect(painter.height, 100);
1658+
const double baseline = 45 + 7.5;
1659+
expect(
1660+
painter.getBoxesForSelection(const TextSelection(baseOffset: 0, extentOffset: 1)),
1661+
const <ui.TextBox>[TextBox.fromLTRBD(0, baseline - 15, 20, baseline + 5, TextDirection.ltr)],
1662+
);
1663+
});
1664+
1665+
test('force strut height applies to widget spans', () {
1666+
const Size placeholderSize = Size(1000, 1000);
1667+
const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true);
1668+
final TextPainter painter = TextPainter(
1669+
textDirection: TextDirection.ltr,
1670+
text: const WidgetSpan(child: SizedBox()),
1671+
strutStyle: strut,
1672+
)
1673+
..setPlaceholderDimensions(const <PlaceholderDimensions>[PlaceholderDimensions(size: placeholderSize, alignment: PlaceholderAlignment.bottom)])
1674+
..layout();
1675+
expect(painter.height, 100);
1676+
});
16491677
}, skip: kIsWeb && !isCanvasKit); // [intended] strut spport for HTML renderer https://github.com/flutter/flutter/issues/32243.
16501678

16511679
test('TextPainter dispatches memory events', () async {

0 commit comments

Comments
 (0)