@@ -24,6 +24,7 @@ import 'placeholder_span.dart';
24
24
import 'strut_style.dart' ;
25
25
import 'text_scaler.dart' ;
26
26
import 'text_span.dart' ;
27
+ import 'text_style.dart' ;
27
28
28
29
export 'dart:ui' show LineMetrics;
29
30
export 'package:flutter/services.dart' show TextRange, TextSelection;
@@ -632,6 +633,12 @@ class TextPainter {
632
633
}
633
634
}
634
635
636
+ @Deprecated ( // flutter_ignore: deprecation_syntax (see analyze.dart)
637
+ 'The disableStrutHalfLeading flag is for internal migration purposes only and should not be used.'
638
+ )
639
+ /// Migration only flag, do not use.
640
+ static bool disableStrutHalfLeading = true ;
641
+
635
642
// Whether textWidthBasis has changed after the most recent `layout` call.
636
643
bool _debugNeedsRelayout = true ;
637
644
// The result of the most recent `layout` call.
@@ -968,26 +975,35 @@ class TextPainter {
968
975
// The defaultTextDirection argument is used for preferredLineHeight in case
969
976
// textDirection hasn't yet been set.
970
977
assert (textDirection != null || defaultTextDirection != null , 'TextPainter.textDirection must be set to a non-null value before using the TextPainter.' );
971
- return _text! .style? .getParagraphStyle (
978
+ final TextStyle baseStyle = _text? .style ?? const TextStyle ();
979
+ final StrutStyle ? strutStyle = _strutStyle;
980
+
981
+ final bool applyMigration = ! kIsWeb && TextPainter .disableStrutHalfLeading
982
+ && strutStyle != null && (strutStyle.forceStrutHeight ?? false )
983
+ && strutStyle.leadingDistribution == TextLeadingDistribution .even;
984
+ final StrutStyle ? strutStyleForMigration = ! applyMigration
985
+ ? strutStyle
986
+ : StrutStyle (
987
+ fontFamily: strutStyle.fontFamily,
988
+ fontFamilyFallback: strutStyle.fontFamilyFallback,
989
+ fontSize: strutStyle.fontSize,
990
+ height: strutStyle.height,
991
+ leadingDistribution: TextLeadingDistribution .proportional,
992
+ leading: strutStyle.leading,
993
+ fontWeight: strutStyle.fontWeight,
994
+ fontStyle: strutStyle.fontStyle,
995
+ forceStrutHeight: strutStyle.forceStrutHeight,
996
+ );
997
+
998
+ return baseStyle.getParagraphStyle (
972
999
textAlign: textAlign,
973
1000
textDirection: textDirection ?? defaultTextDirection,
974
1001
textScaler: textScaler,
975
1002
maxLines: _maxLines,
976
1003
textHeightBehavior: _textHeightBehavior,
977
1004
ellipsis: _ellipsis,
978
1005
locale: _locale,
979
- strutStyle: _strutStyle,
980
- ) ?? ui.ParagraphStyle (
981
- textAlign: textAlign,
982
- textDirection: textDirection ?? defaultTextDirection,
983
- // Use the default font size to multiply by as RichText does not
984
- // perform inheriting [TextStyle]s and would otherwise
985
- // fail to apply textScaler.
986
- fontSize: textScaler.scale (kDefaultFontSize),
987
- maxLines: maxLines,
988
- textHeightBehavior: _textHeightBehavior,
989
- ellipsis: ellipsis,
990
- locale: locale,
1006
+ strutStyle: strutStyleForMigration,
991
1007
);
992
1008
}
993
1009
0 commit comments