diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index 2a74499c78b..fa7ff59307c 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -683,12 +683,6 @@ class TextPainter { } } - @Deprecated( // flutter_ignore: deprecation_syntax (see analyze.dart) - 'The disableStrutHalfLeading flag is for internal migration purposes only and should not be used.' - ) - /// Migration only flag, do not use. - static bool disableStrutHalfLeading = true; - // Whether textWidthBasis has changed after the most recent `layout` call. bool _debugNeedsRelayout = true; // The result of the most recent `layout` call. @@ -1024,25 +1018,6 @@ class TextPainter { ui.ParagraphStyle _createParagraphStyle([ TextAlign? textAlignOverride ]) { assert(textDirection != null, 'TextPainter.textDirection must be set to a non-null value before using the TextPainter.'); final TextStyle baseStyle = _text?.style ?? const TextStyle(); - final StrutStyle? strutStyle = _strutStyle; - - final bool applyMigration = !kIsWeb && TextPainter.disableStrutHalfLeading - && strutStyle != null && (strutStyle.forceStrutHeight ?? false) - && strutStyle.leadingDistribution == TextLeadingDistribution.even; - final StrutStyle? strutStyleForMigration = !applyMigration - ? strutStyle - : StrutStyle( - fontFamily: strutStyle.fontFamily, - fontFamilyFallback: strutStyle.fontFamilyFallback, - fontSize: strutStyle.fontSize, - height: strutStyle.height, - leadingDistribution: TextLeadingDistribution.proportional, - leading: strutStyle.leading, - fontWeight: strutStyle.fontWeight, - fontStyle: strutStyle.fontStyle, - forceStrutHeight: strutStyle.forceStrutHeight, - ); - return baseStyle.getParagraphStyle( textAlign: textAlignOverride ?? textAlign, textDirection: textDirection, @@ -1051,7 +1026,7 @@ class TextPainter { textHeightBehavior: _textHeightBehavior, ellipsis: _ellipsis, locale: _locale, - strutStyle: strutStyleForMigration, + strutStyle: _strutStyle, ); } diff --git a/packages/flutter/test/painting/text_painter_test.dart b/packages/flutter/test/painting/text_painter_test.dart index 2acf6e8ad0d..004e306f734 100644 --- a/packages/flutter/test/painting/text_painter_test.dart +++ b/packages/flutter/test/painting/text_painter_test.dart @@ -1632,7 +1632,7 @@ void main() { expect(painter.computeDistanceToActualBaseline(TextBaseline.alphabetic), 10 + 10 * 7.5); }); - test('force strut height', () { + test('strut no half leading + force strut height', () { const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true); final TextPainter painter = TextPainter( textDirection: TextDirection.ltr, @@ -1646,6 +1646,34 @@ void main() { const [TextBox.fromLTRBD(0, baseline - 15, 20, baseline + 5, TextDirection.ltr)], ); }); + + test('strut half leading + force strut height', () { + const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true, leadingDistribution: TextLeadingDistribution.even); + final TextPainter painter = TextPainter( + textDirection: TextDirection.ltr, + text: const TextSpan(text: 'A', style: TextStyle(fontSize: 20)), + strutStyle: strut, + )..layout(); + expect(painter.height, 100); + const double baseline = 45 + 7.5; + expect( + painter.getBoxesForSelection(const TextSelection(baseOffset: 0, extentOffset: 1)), + const [TextBox.fromLTRBD(0, baseline - 15, 20, baseline + 5, TextDirection.ltr)], + ); + }); + + test('force strut height applies to widget spans', () { + const Size placeholderSize = Size(1000, 1000); + const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true); + final TextPainter painter = TextPainter( + textDirection: TextDirection.ltr, + text: const WidgetSpan(child: SizedBox()), + strutStyle: strut, + ) + ..setPlaceholderDimensions(const [PlaceholderDimensions(size: placeholderSize, alignment: PlaceholderAlignment.bottom)]) + ..layout(); + expect(painter.height, 100); + }); }, skip: kIsWeb && !isCanvasKit); // [intended] strut spport for HTML renderer https://github.com/flutter/flutter/issues/32243. test('TextPainter dispatches memory events', () async {