Provide defaulting for textScaleFactor when passing to dart:ui (#66375)
This commit is contained in:
parent
d5b715d7cb
commit
eb5cc495b3
@ -16,6 +16,11 @@ import 'text_span.dart';
|
|||||||
|
|
||||||
export 'package:flutter/services.dart' show TextRange, TextSelection;
|
export 'package:flutter/services.dart' show TextRange, TextSelection;
|
||||||
|
|
||||||
|
// The default font size if none is specified. This should be kept in
|
||||||
|
// sync with the default values in text_style.dart, as well as the
|
||||||
|
// defaults set in the engine (eg, LibTxt's text_style.h, paragraph_style.h).
|
||||||
|
const double _kDefaultFontSize = 14.0;
|
||||||
|
|
||||||
/// Holds the [Size] and baseline required to represent the dimensions of
|
/// Holds the [Size] and baseline required to represent the dimensions of
|
||||||
/// a placeholder in text.
|
/// a placeholder in text.
|
||||||
///
|
///
|
||||||
@ -420,6 +425,10 @@ class TextPainter {
|
|||||||
) ?? ui.ParagraphStyle(
|
) ?? ui.ParagraphStyle(
|
||||||
textAlign: textAlign,
|
textAlign: textAlign,
|
||||||
textDirection: textDirection ?? defaultTextDirection,
|
textDirection: textDirection ?? defaultTextDirection,
|
||||||
|
// Use the default font size to multiply by as RichText does not
|
||||||
|
// perform inheriting [TextStyle]s and would otherwise
|
||||||
|
// fail to apply textScaleFactor.
|
||||||
|
fontSize: _kDefaultFontSize * textScaleFactor,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
textHeightBehavior: _textHeightBehavior,
|
textHeightBehavior: _textHeightBehavior,
|
||||||
ellipsis: ellipsis,
|
ellipsis: ellipsis,
|
||||||
|
@ -19,6 +19,11 @@ const String _kColorForegroundWarning = 'Cannot provide both a color and a foreg
|
|||||||
const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor and a background\n'
|
const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor and a background\n'
|
||||||
'The backgroundColor argument is just a shorthand for "background: new Paint()..color = color".';
|
'The backgroundColor argument is just a shorthand for "background: new Paint()..color = color".';
|
||||||
|
|
||||||
|
// The default font size if none is specified. This should be kept in
|
||||||
|
// sync with the default values in text_painter.dart, as well as the
|
||||||
|
// defaults set in the engine (eg, LibTxt's text_style.h, paragraph_style.h).
|
||||||
|
const double _kDefaultFontSize = 14.0;
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// BuildContext context;
|
// BuildContext context;
|
||||||
|
|
||||||
@ -512,9 +517,6 @@ class TextStyle with Diagnosticable {
|
|||||||
/// isn't specified here.
|
/// isn't specified here.
|
||||||
final double? fontSize;
|
final double? fontSize;
|
||||||
|
|
||||||
// The default font size if none is specified.
|
|
||||||
static const double _defaultFontSize = 14.0;
|
|
||||||
|
|
||||||
/// The typeface thickness to use when painting the text (e.g., bold).
|
/// The typeface thickness to use when painting the text (e.g., bold).
|
||||||
final FontWeight? fontWeight;
|
final FontWeight? fontWeight;
|
||||||
|
|
||||||
@ -1092,7 +1094,7 @@ class TextStyle with Diagnosticable {
|
|||||||
fontWeight: fontWeight ?? this.fontWeight,
|
fontWeight: fontWeight ?? this.fontWeight,
|
||||||
fontStyle: fontStyle ?? this.fontStyle,
|
fontStyle: fontStyle ?? this.fontStyle,
|
||||||
fontFamily: fontFamily ?? this.fontFamily,
|
fontFamily: fontFamily ?? this.fontFamily,
|
||||||
fontSize: (fontSize ?? this.fontSize ?? _defaultFontSize) * textScaleFactor,
|
fontSize: (fontSize ?? this.fontSize ?? _kDefaultFontSize) * textScaleFactor,
|
||||||
height: height ?? this.height,
|
height: height ?? this.height,
|
||||||
textHeightBehavior: textHeightBehavior,
|
textHeightBehavior: textHeightBehavior,
|
||||||
strutStyle: strutStyle == null ? null : ui.StrutStyle(
|
strutStyle: strutStyle == null ? null : ui.StrutStyle(
|
||||||
|
@ -192,6 +192,18 @@ void main() {
|
|||||||
expect(painter.size, const Size(20.0, 20.0));
|
expect(painter.size, const Size(20.0, 20.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('TextPainter textScaleFactor null style test', () {
|
||||||
|
final TextPainter painter = TextPainter(
|
||||||
|
text: const TextSpan(
|
||||||
|
text: 'X',
|
||||||
|
),
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
textScaleFactor: 2.0,
|
||||||
|
);
|
||||||
|
painter.layout();
|
||||||
|
expect(painter.size, const Size(28.0, 28.0));
|
||||||
|
});
|
||||||
|
|
||||||
test('TextPainter default text height is 14 pixels', () {
|
test('TextPainter default text height is 14 pixels', () {
|
||||||
final TextPainter painter = TextPainter(
|
final TextPainter painter = TextPainter(
|
||||||
text: const TextSpan(text: 'x'),
|
text: const TextSpan(text: 'x'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user