mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
Remove strut migration flag from TextPainter
(#144242)
Fixes https://github.com/flutter/flutter/issues/142969. G3fix: cl/610790040
This commit is contained in:
parent
d1d9605974
commit
a23c81333f
|
@ -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.
|
// Whether textWidthBasis has changed after the most recent `layout` call.
|
||||||
bool _debugNeedsRelayout = true;
|
bool _debugNeedsRelayout = true;
|
||||||
// The result of the most recent `layout` call.
|
// The result of the most recent `layout` call.
|
||||||
|
@ -1024,25 +1018,6 @@ class TextPainter {
|
||||||
ui.ParagraphStyle _createParagraphStyle([ TextAlign? textAlignOverride ]) {
|
ui.ParagraphStyle _createParagraphStyle([ TextAlign? textAlignOverride ]) {
|
||||||
assert(textDirection != null, 'TextPainter.textDirection must be set to a non-null value before using the TextPainter.');
|
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 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(
|
return baseStyle.getParagraphStyle(
|
||||||
textAlign: textAlignOverride ?? textAlign,
|
textAlign: textAlignOverride ?? textAlign,
|
||||||
textDirection: textDirection,
|
textDirection: textDirection,
|
||||||
|
@ -1051,7 +1026,7 @@ class TextPainter {
|
||||||
textHeightBehavior: _textHeightBehavior,
|
textHeightBehavior: _textHeightBehavior,
|
||||||
ellipsis: _ellipsis,
|
ellipsis: _ellipsis,
|
||||||
locale: _locale,
|
locale: _locale,
|
||||||
strutStyle: strutStyleForMigration,
|
strutStyle: _strutStyle,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1632,7 +1632,7 @@ void main() {
|
||||||
expect(painter.computeDistanceToActualBaseline(TextBaseline.alphabetic), 10 + 10 * 7.5);
|
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);
|
const StrutStyle strut = StrutStyle(height: 10, fontSize: 10, forceStrutHeight: true);
|
||||||
final TextPainter painter = TextPainter(
|
final TextPainter painter = TextPainter(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
|
@ -1646,6 +1646,34 @@ void main() {
|
||||||
const <ui.TextBox>[TextBox.fromLTRBD(0, baseline - 15, 20, baseline + 5, TextDirection.ltr)],
|
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.
|
}, skip: kIsWeb && !isCanvasKit); // [intended] strut spport for HTML renderer https://github.com/flutter/flutter/issues/32243.
|
||||||
|
|
||||||
test('TextPainter dispatches memory events', () async {
|
test('TextPainter dispatches memory events', () async {
|
||||||
|
|
Loading…
Reference in a new issue