mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add support for locale-specific text styles (#16430)
See https://github.com/flutter/flutter/issues/12630 and https://github.com/flutter/flutter/issues/16408
This commit is contained in:
parent
c43134a71c
commit
c3ce892c9e
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle;
|
||||
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, Locale;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
@ -48,6 +48,7 @@ class TextPainter {
|
||||
double textScaleFactor: 1.0,
|
||||
int maxLines,
|
||||
String ellipsis,
|
||||
ui.Locale locale,
|
||||
}) : assert(text == null || text.debugAssertIsValid()),
|
||||
assert(textAlign != null),
|
||||
assert(textScaleFactor != null),
|
||||
@ -57,7 +58,8 @@ class TextPainter {
|
||||
_textDirection = textDirection,
|
||||
_textScaleFactor = textScaleFactor,
|
||||
_maxLines = maxLines,
|
||||
_ellipsis = ellipsis;
|
||||
_ellipsis = ellipsis,
|
||||
_locale = locale;
|
||||
|
||||
ui.Paragraph _paragraph;
|
||||
bool _needsLayout = true;
|
||||
@ -167,6 +169,17 @@ class TextPainter {
|
||||
_needsLayout = true;
|
||||
}
|
||||
|
||||
/// The locale used to select region-specific glyphs.
|
||||
ui.Locale get locale => _locale;
|
||||
ui.Locale _locale;
|
||||
set locale(ui.Locale value) {
|
||||
if (_locale == value)
|
||||
return;
|
||||
_locale = value;
|
||||
_paragraph = null;
|
||||
_needsLayout = true;
|
||||
}
|
||||
|
||||
/// An optional maximum number of lines for the text to span, wrapping if
|
||||
/// necessary.
|
||||
///
|
||||
@ -199,11 +212,13 @@ class TextPainter {
|
||||
textScaleFactor: textScaleFactor,
|
||||
maxLines: _maxLines,
|
||||
ellipsis: _ellipsis,
|
||||
locale: _locale,
|
||||
) ?? new ui.ParagraphStyle(
|
||||
textAlign: textAlign,
|
||||
textDirection: textDirection ?? defaultTextDirection,
|
||||
maxLines: maxLines,
|
||||
ellipsis: ellipsis,
|
||||
locale: locale,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble;
|
||||
import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble, Locale;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
@ -229,6 +229,7 @@ class TextStyle extends Diagnosticable {
|
||||
this.wordSpacing,
|
||||
this.textBaseline,
|
||||
this.height,
|
||||
this.locale,
|
||||
this.decoration,
|
||||
this.decorationColor,
|
||||
this.decorationStyle,
|
||||
@ -296,6 +297,9 @@ class TextStyle extends Diagnosticable {
|
||||
/// the font size.
|
||||
final double height;
|
||||
|
||||
/// The locale used to select region-specific glyphs.
|
||||
final ui.Locale locale;
|
||||
|
||||
/// The decorations to paint near the text (e.g., an underline).
|
||||
final TextDecoration decoration;
|
||||
|
||||
@ -330,6 +334,7 @@ class TextStyle extends Diagnosticable {
|
||||
double wordSpacing,
|
||||
TextBaseline textBaseline,
|
||||
double height,
|
||||
ui.Locale locale,
|
||||
TextDecoration decoration,
|
||||
Color decorationColor,
|
||||
TextDecorationStyle decorationStyle,
|
||||
@ -352,6 +357,7 @@ class TextStyle extends Diagnosticable {
|
||||
wordSpacing: wordSpacing ?? this.wordSpacing,
|
||||
textBaseline: textBaseline ?? this.textBaseline,
|
||||
height: height ?? this.height,
|
||||
locale: locale ?? this.locale,
|
||||
decoration: decoration ?? this.decoration,
|
||||
decorationColor: decorationColor ?? this.decorationColor,
|
||||
decorationStyle: decorationStyle ?? this.decorationStyle,
|
||||
@ -429,6 +435,7 @@ class TextStyle extends Diagnosticable {
|
||||
wordSpacing: wordSpacing == null ? null : wordSpacing * wordSpacingFactor + wordSpacingDelta,
|
||||
textBaseline: textBaseline,
|
||||
height: height == null ? null : height * heightFactor + heightDelta,
|
||||
locale: locale,
|
||||
decoration: decoration ?? this.decoration,
|
||||
decorationColor: decorationColor ?? this.decorationColor,
|
||||
decorationStyle: decorationStyle ?? this.decorationStyle,
|
||||
@ -473,6 +480,7 @@ class TextStyle extends Diagnosticable {
|
||||
wordSpacing: other.wordSpacing,
|
||||
textBaseline: other.textBaseline,
|
||||
height: other.height,
|
||||
locale: other.locale,
|
||||
decoration: other.decoration,
|
||||
decorationColor: other.decorationColor,
|
||||
decorationStyle: other.decorationStyle,
|
||||
@ -518,6 +526,7 @@ class TextStyle extends Diagnosticable {
|
||||
wordSpacing: ui.lerpDouble(a.wordSpacing ?? b.wordSpacing, b.wordSpacing ?? a.wordSpacing, t),
|
||||
textBaseline: t < 0.5 ? a.textBaseline : b.textBaseline,
|
||||
height: ui.lerpDouble(a.height ?? b.height, b.height ?? a.height, t),
|
||||
locale: t < 0.5 ? a.locale : b.locale,
|
||||
decoration: t < 0.5 ? a.decoration : b.decoration,
|
||||
decorationColor: Color.lerp(a.decorationColor, b.decorationColor, t),
|
||||
decorationStyle: t < 0.5 ? a.decorationStyle : b.decorationStyle,
|
||||
@ -539,7 +548,8 @@ class TextStyle extends Diagnosticable {
|
||||
fontSize: fontSize == null ? null : fontSize * textScaleFactor,
|
||||
letterSpacing: letterSpacing,
|
||||
wordSpacing: wordSpacing,
|
||||
height: height
|
||||
height: height,
|
||||
locale: locale,
|
||||
);
|
||||
}
|
||||
|
||||
@ -557,6 +567,7 @@ class TextStyle extends Diagnosticable {
|
||||
double textScaleFactor: 1.0,
|
||||
String ellipsis,
|
||||
int maxLines,
|
||||
ui.Locale locale,
|
||||
}) {
|
||||
assert(textScaleFactor != null);
|
||||
assert(maxLines == null || maxLines > 0);
|
||||
@ -570,6 +581,7 @@ class TextStyle extends Diagnosticable {
|
||||
lineHeight: height,
|
||||
maxLines: maxLines,
|
||||
ellipsis: ellipsis,
|
||||
locale: locale,
|
||||
);
|
||||
}
|
||||
|
||||
@ -590,7 +602,8 @@ class TextStyle extends Diagnosticable {
|
||||
letterSpacing != other.letterSpacing ||
|
||||
wordSpacing != other.wordSpacing ||
|
||||
textBaseline != other.textBaseline ||
|
||||
height != other.height)
|
||||
height != other.height ||
|
||||
locale != other.locale)
|
||||
return RenderComparison.layout;
|
||||
if (color != other.color ||
|
||||
decoration != other.decoration ||
|
||||
@ -617,6 +630,7 @@ class TextStyle extends Diagnosticable {
|
||||
wordSpacing == typedOther.wordSpacing &&
|
||||
textBaseline == typedOther.textBaseline &&
|
||||
height == typedOther.height &&
|
||||
locale == typedOther.locale &&
|
||||
decoration == typedOther.decoration &&
|
||||
decorationColor == typedOther.decorationColor &&
|
||||
decorationStyle == typedOther.decorationStyle;
|
||||
@ -635,6 +649,7 @@ class TextStyle extends Diagnosticable {
|
||||
wordSpacing,
|
||||
textBaseline,
|
||||
height,
|
||||
locale,
|
||||
decoration,
|
||||
decorationColor,
|
||||
decorationStyle
|
||||
@ -700,6 +715,7 @@ class TextStyle extends Diagnosticable {
|
||||
styles.add(new DoubleProperty('${prefix}wordSpacing', wordSpacing, defaultValue: null));
|
||||
styles.add(new EnumProperty<TextBaseline>('${prefix}baseline', textBaseline, defaultValue: null));
|
||||
styles.add(new DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null));
|
||||
styles.add(new StringProperty('${prefix}locale', locale?.toString(), defaultValue: null, quoted: false));
|
||||
if (decoration != null || decorationColor != null || decorationStyle != null) {
|
||||
final List<String> decorationDescription = <String>[];
|
||||
if (decorationStyle != null)
|
||||
|
@ -462,6 +462,7 @@ class _TextStyleProxy implements TextStyle {
|
||||
@override FontStyle get fontStyle => _delegate.fontStyle;
|
||||
@override FontWeight get fontWeight => _delegate.fontWeight;
|
||||
@override double get height => _delegate.height;
|
||||
@override ui.Locale get locale => _delegate.locale;
|
||||
@override bool get inherit => _delegate.inherit;
|
||||
@override double get letterSpacing => _delegate.letterSpacing;
|
||||
@override TextBaseline get textBaseline => _delegate.textBaseline;
|
||||
@ -488,7 +489,7 @@ class _TextStyleProxy implements TextStyle {
|
||||
}
|
||||
|
||||
@override
|
||||
TextStyle copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel}) {
|
||||
TextStyle copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, ui.Locale locale, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel}) {
|
||||
throw new UnimplementedError();
|
||||
}
|
||||
|
||||
@ -498,7 +499,7 @@ class _TextStyleProxy implements TextStyle {
|
||||
}
|
||||
|
||||
@override
|
||||
ui.ParagraphStyle getParagraphStyle({TextAlign textAlign, TextDirection textDirection, double textScaleFactor: 1.0, String ellipsis, int maxLines}) {
|
||||
ui.ParagraphStyle getParagraphStyle({TextAlign textAlign, TextDirection textDirection, double textScaleFactor: 1.0, String ellipsis, int maxLines, ui.Locale locale}) {
|
||||
throw new UnimplementedError();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user