From 561735ad89a14c63597f9acb77d447c7e0ed4fec Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Thu, 23 Jul 2020 10:35:21 -0700 Subject: [PATCH] Revert "remove usage to applyTextScaleFactorToWidgetSpan (#61636)" (#62144) This reverts commit c816fabd0af48a861afdeb78bb6ebe4b7cbd3707. --- packages/flutter/lib/src/rendering/paragraph.dart | 13 ++++++++++++- packages/flutter/lib/src/widgets/basic.dart | 4 ++++ packages/flutter/lib/src/widgets/text.dart | 5 +++++ packages/flutter/test/widgets/text_test.dart | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index d407403409..c764eac8cc 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -79,6 +79,13 @@ class RenderParagraph extends RenderBox StrutStyle strutStyle, TextWidthBasis textWidthBasis = TextWidthBasis.parent, ui.TextHeightBehavior textHeightBehavior, + @Deprecated( + 'This parameter is a temporary flag to migrate the internal tests and ' + 'should not be used in other contexts. For more details, please check ' + 'https://github.com/flutter/flutter/issues/59316. ' + 'This feature was deprecated after v1.19.0.' + ) + bool applyTextScaleFactorToWidgetSpan = false, List children, }) : assert(text != null), assert(text.debugAssertIsValid()), @@ -91,6 +98,7 @@ class RenderParagraph extends RenderBox assert(textWidthBasis != null), _softWrap = softWrap, _overflow = overflow, + _applyTextScaleFactorToWidgetSpan = applyTextScaleFactorToWidgetSpan, _textPainter = TextPainter( text: text, textAlign: textAlign, @@ -290,6 +298,8 @@ class RenderParagraph extends RenderBox markNeedsLayout(); } + final bool _applyTextScaleFactorToWidgetSpan; + @override double computeMinIntrinsicWidth(double height) { if (!_canComputeIntrinsics()) { @@ -530,7 +540,8 @@ class RenderParagraph extends RenderBox // The content will be enlarged by textScaleFactor during painting phase. // We reduce constraint by textScaleFactor so that the content will fit // into the box once it is enlarged. - boxConstraints = boxConstraints / textScaleFactor; + if (_applyTextScaleFactorToWidgetSpan) + boxConstraints = boxConstraints / textScaleFactor; while (child != null) { // Only constrain the width to the maximum width of the paragraph. // Leave height unconstrained, which will overflow if expanded past. diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 4868f19fb9..5df22117fb 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -5200,6 +5200,7 @@ class RichText extends MultiChildRenderObjectWidget { assert(textScaleFactor != null), assert(maxLines == null || maxLines > 0), assert(textWidthBasis != null), + _applyTextScaleFactorToWidgetSpan = applyTextScaleFactorToWidgetSpan, super(key: key, children: _extractChildren(text)); // Traverses the InlineSpan tree and depth-first collects the list of @@ -5277,6 +5278,8 @@ class RichText extends MultiChildRenderObjectWidget { /// {@macro flutter.dart:ui.textHeightBehavior} final ui.TextHeightBehavior textHeightBehavior; + final bool _applyTextScaleFactorToWidgetSpan; + @override RenderParagraph createRenderObject(BuildContext context) { assert(textDirection != null || debugCheckHasDirectionality(context)); @@ -5290,6 +5293,7 @@ class RichText extends MultiChildRenderObjectWidget { strutStyle: strutStyle, textWidthBasis: textWidthBasis, textHeightBehavior: textHeightBehavior, + applyTextScaleFactorToWidgetSpan: _applyTextScaleFactorToWidgetSpan, locale: locale ?? Localizations.localeOf(context, nullOk: true), ); } diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index 1b63929377..eb91a7a5ce 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -361,6 +361,7 @@ class Text extends StatelessWidget { 'A non-null String must be provided to a Text widget.', ), textSpan = null, + _applyTextScaleFactorToWidgetSpan = true, super(key: key); /// Creates a text widget with a [InlineSpan]. @@ -400,6 +401,7 @@ class Text extends StatelessWidget { 'A non-null TextSpan must be provided to a Text.rich widget.', ), data = null, + _applyTextScaleFactorToWidgetSpan = applyTextScaleFactorToWidgetSpan, super(key: key); /// The text to display. @@ -502,6 +504,8 @@ class Text extends StatelessWidget { /// {@macro flutter.dart:ui.textHeightBehavior} final ui.TextHeightBehavior textHeightBehavior; + final bool _applyTextScaleFactorToWidgetSpan; + @override Widget build(BuildContext context) { final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context); @@ -521,6 +525,7 @@ class Text extends StatelessWidget { strutStyle: strutStyle, textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis, textHeightBehavior: textHeightBehavior ?? defaultTextStyle.textHeightBehavior ?? DefaultTextHeightBehavior.of(context), + applyTextScaleFactorToWidgetSpan: _applyTextScaleFactorToWidgetSpan, text: TextSpan( style: effectiveTextStyle, text: data, diff --git a/packages/flutter/test/widgets/text_test.dart b/packages/flutter/test/widgets/text_test.dart index bb0f9694c4..646711717c 100644 --- a/packages/flutter/test/widgets/text_test.dart +++ b/packages/flutter/test/widgets/text_test.dart @@ -186,6 +186,7 @@ void main() { key: key, textDirection: TextDirection.ltr, textScaleFactor: textScaleFactor, + applyTextScaleFactorToWidgetSpan: true, ), ), ), @@ -214,6 +215,7 @@ void main() { key: key, textDirection: TextDirection.ltr, textScaleFactor: textScaleFactor, + applyTextScaleFactorToWidgetSpan: true, ), ), ),