Unverified Commit 04e0fcb0 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Fixed a typo in the render paragraph locale setter (#18189)

parent e8bceabb
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show Gradient, Shader, TextBox, Locale; import 'dart:ui' as ui show Gradient, Shader, TextBox;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -44,7 +44,7 @@ class RenderParagraph extends RenderBox { ...@@ -44,7 +44,7 @@ class RenderParagraph extends RenderBox {
TextOverflow overflow = TextOverflow.clip, TextOverflow overflow = TextOverflow.clip,
double textScaleFactor = 1.0, double textScaleFactor = 1.0,
int maxLines, int maxLines,
ui.Locale locale, Locale locale,
}) : assert(text != null), }) : assert(text != null),
assert(text.debugAssertIsValid()), assert(text.debugAssertIsValid()),
assert(textAlign != null), assert(textAlign != null),
...@@ -176,11 +176,19 @@ class RenderParagraph extends RenderBox { ...@@ -176,11 +176,19 @@ class RenderParagraph extends RenderBox {
markNeedsLayout(); markNeedsLayout();
} }
ui.Locale get locale => _textPainter.locale; /// Used by this paragraph's internal [TextPainter] to select a locale-specific
set locale(ui.Locale value) { /// font.
///
/// In some cases the same Unicode character may be rendered differently depending
/// on the locale. For example the '骨' character is rendered differently in
/// the Chinese and Japanese locales. In these cases the [locale] may be used
/// to select a locale-specific font.
Locale get locale => _textPainter.locale;
/// The value may be null.
set locale(Locale value) {
if (_textPainter.locale == value) if (_textPainter.locale == value)
return; return;
_textPainter.locale = locale; _textPainter.locale = value;
_overflowShader = null; _overflowShader = null;
markNeedsLayout(); markNeedsLayout();
} }
...@@ -286,6 +294,7 @@ class RenderParagraph extends RenderBox { ...@@ -286,6 +294,7 @@ class RenderParagraph extends RenderBox {
text: new TextSpan(style: _textPainter.text.style, text: '\u2026'), text: new TextSpan(style: _textPainter.text.style, text: '\u2026'),
textDirection: textDirection, textDirection: textDirection,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
locale: locale,
)..layout(); )..layout();
if (didOverflowWidth) { if (didOverflowWidth) {
double fadeEnd, fadeStart; double fadeEnd, fadeStart;
......
...@@ -235,7 +235,7 @@ class ShaderMask extends SingleChildRenderObjectWidget { ...@@ -235,7 +235,7 @@ class ShaderMask extends SingleChildRenderObjectWidget {
/// it can customize the shader to the size and location of the child. /// it can customize the shader to the size and location of the child.
/// ///
/// Typically this will use a [LinearGradient], [RadialGradient], or /// Typically this will use a [LinearGradient], [RadialGradient], or
/// [SweepGradient] to create the [dart:ui.Shader], though the /// [SweepGradient] to create the [dart:ui.Shader], though the
/// [dart:ui.ImageShader] class could also be used. /// [dart:ui.ImageShader] class could also be used.
final ShaderCallback shaderCallback; final ShaderCallback shaderCallback;
...@@ -4289,6 +4289,7 @@ class RichText extends LeafRenderObjectWidget { ...@@ -4289,6 +4289,7 @@ class RichText extends LeafRenderObjectWidget {
this.overflow = TextOverflow.clip, this.overflow = TextOverflow.clip,
this.textScaleFactor = 1.0, this.textScaleFactor = 1.0,
this.maxLines, this.maxLines,
this.locale,
}) : assert(text != null), }) : assert(text != null),
assert(textAlign != null), assert(textAlign != null),
assert(softWrap != null), assert(softWrap != null),
...@@ -4341,6 +4342,15 @@ class RichText extends LeafRenderObjectWidget { ...@@ -4341,6 +4342,15 @@ class RichText extends LeafRenderObjectWidget {
/// edge of the box. /// edge of the box.
final int maxLines; final int maxLines;
/// Used to select a font when the same Unicode character can
/// be rendered differently, depending on the locale.
///
/// It's rarely necessary to set this property. By default its value
/// is inherited from the enclosing app with `Localizations.localeOf(context)`.
///
/// See [RenderParagraph.locale] for more information.
final Locale locale;
@override @override
RenderParagraph createRenderObject(BuildContext context) { RenderParagraph createRenderObject(BuildContext context) {
assert(textDirection != null || debugCheckHasDirectionality(context)); assert(textDirection != null || debugCheckHasDirectionality(context));
...@@ -4351,7 +4361,7 @@ class RichText extends LeafRenderObjectWidget { ...@@ -4351,7 +4361,7 @@ class RichText extends LeafRenderObjectWidget {
overflow: overflow, overflow: overflow,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
maxLines: maxLines, maxLines: maxLines,
locale: Localizations.localeOf(context, nullOk: true), locale: locale ?? Localizations.localeOf(context, nullOk: true),
); );
} }
...@@ -4366,7 +4376,7 @@ class RichText extends LeafRenderObjectWidget { ...@@ -4366,7 +4376,7 @@ class RichText extends LeafRenderObjectWidget {
..overflow = overflow ..overflow = overflow
..textScaleFactor = textScaleFactor ..textScaleFactor = textScaleFactor
..maxLines = maxLines ..maxLines = maxLines
..locale = Localizations.localeOf(context, nullOk: true); ..locale = locale ?? Localizations.localeOf(context, nullOk: true);
} }
@override @override
......
...@@ -310,4 +310,19 @@ void main() { ...@@ -310,4 +310,19 @@ void main() {
), ),
); );
}); });
test('locale setter', () {
// Regression test for https://github.com/flutter/flutter/issues/18175
final RenderParagraph paragraph = new RenderParagraph(
const TextSpan(text: _kText),
locale: const Locale('zh', 'HK'),
textDirection: TextDirection.ltr,
);
expect(paragraph.locale, const Locale('zh', 'HK'));
paragraph.locale = const Locale('ja', 'JP');
expect(paragraph.locale, const Locale('ja', 'JP'));
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment