Unverified Commit eb5cc495 authored by Gary Qian's avatar Gary Qian Committed by GitHub

Provide defaulting for textScaleFactor when passing to dart:ui (#66375)

parent d5b715d7
......@@ -16,6 +16,11 @@ import 'text_span.dart';
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
/// a placeholder in text.
///
......@@ -420,6 +425,10 @@ class TextPainter {
) ?? ui.ParagraphStyle(
textAlign: textAlign,
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,
textHeightBehavior: _textHeightBehavior,
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'
'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:
// BuildContext context;
......@@ -512,9 +517,6 @@ class TextStyle with Diagnosticable {
/// isn't specified here.
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).
final FontWeight? fontWeight;
......@@ -1092,7 +1094,7 @@ class TextStyle with Diagnosticable {
fontWeight: fontWeight ?? this.fontWeight,
fontStyle: fontStyle ?? this.fontStyle,
fontFamily: fontFamily ?? this.fontFamily,
fontSize: (fontSize ?? this.fontSize ?? _defaultFontSize) * textScaleFactor,
fontSize: (fontSize ?? this.fontSize ?? _kDefaultFontSize) * textScaleFactor,
height: height ?? this.height,
textHeightBehavior: textHeightBehavior,
strutStyle: strutStyle == null ? null : ui.StrutStyle(
......
......@@ -192,6 +192,18 @@ void main() {
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', () {
final TextPainter painter = TextPainter(
text: const TextSpan(text: 'x'),
......
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