Remove strut migration flag from TextPainter (#144242)

Fixes https://github.com/flutter/flutter/issues/142969.

G3fix: cl/610790040
This commit is contained in:
LongCatIsLooong 2024-02-27 11:13:58 -08:00 committed by GitHub
parent d1d9605974
commit a23c81333f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 27 deletions

View file

@ -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,
);
}

View file

@ -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 <ui.TextBox>[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 <ui.TextBox>[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>[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 {