Skip to content

Commit f0cc38f

Browse files
authored
[web] Set correct defaults for text in canvas (flutter#20067)
1 parent ad99f5e commit f0cc38f

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repository: https://github.com/flutter/goldens.git
2-
revision: 043f1bc2752e01400cea46318c78a6f1f015dadc
2+
revision: 4fb2ce1ea4b3a0bd48b01d7b3724be87244964d6

lib/web_ui/lib/src/engine/dom_renderer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ class DomRenderer {
207207

208208
static const String defaultFontStyle = 'normal';
209209
static const String defaultFontWeight = 'normal';
210-
static const String defaultFontSize = '14px';
210+
static const double defaultFontSize = 14;
211211
static const String defaultFontFamily = 'sans-serif';
212212
static const String defaultCssFont =
213-
'$defaultFontStyle $defaultFontWeight $defaultFontSize $defaultFontFamily';
213+
'$defaultFontStyle $defaultFontWeight ${defaultFontSize}px $defaultFontFamily';
214214

215215
void reset() {
216216
_styleElement?.remove();

lib/web_ui/lib/src/engine/text/paragraph.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// @dart = 2.10
66
part of engine;
77

8+
const ui.Color _defaultTextColor = ui.Color(0xFFFF0000);
9+
810
class EngineLineMetrics implements ui.LineMetrics {
911
EngineLineMetrics({
1012
required this.hardBreak,
@@ -1110,15 +1112,15 @@ class EngineParagraphBuilder implements ui.ParagraphBuilder {
11101112
/// paragraph. Plain text is more efficient to lay out and measure than rich
11111113
/// text.
11121114
EngineParagraph? _tryBuildPlainText() {
1113-
ui.Color? color;
1115+
ui.Color color = _defaultTextColor;
11141116
ui.TextDecoration? decoration;
11151117
ui.Color? decorationColor;
11161118
ui.TextDecorationStyle? decorationStyle;
11171119
ui.FontWeight? fontWeight = _paragraphStyle._fontWeight;
11181120
ui.FontStyle? fontStyle = _paragraphStyle._fontStyle;
11191121
ui.TextBaseline? textBaseline;
1120-
String? fontFamily = _paragraphStyle._fontFamily;
1121-
double? fontSize = _paragraphStyle._fontSize;
1122+
String fontFamily = _paragraphStyle._fontFamily ?? DomRenderer.defaultFontFamily;
1123+
double fontSize = _paragraphStyle._fontSize ?? DomRenderer.defaultFontSize;
11221124
final ui.TextAlign textAlign = _paragraphStyle._effectiveTextAlign;
11231125
final ui.TextDirection textDirection = _paragraphStyle._effectiveTextDirection;
11241126
double? letterSpacing;
@@ -1138,7 +1140,7 @@ class EngineParagraphBuilder implements ui.ParagraphBuilder {
11381140
while (i < _ops.length && _ops[i] is EngineTextStyle) {
11391141
final EngineTextStyle style = _ops[i];
11401142
if (style._color != null) {
1141-
color = style._color;
1143+
color = style._color!;
11421144
}
11431145
if (style._decoration != null) {
11441146
decoration = style._decoration;
@@ -1160,7 +1162,7 @@ class EngineParagraphBuilder implements ui.ParagraphBuilder {
11601162
}
11611163
fontFamily = style._fontFamily;
11621164
if (style._fontSize != null) {
1163-
fontSize = style._fontSize;
1165+
fontSize = style._fontSize!;
11641166
}
11651167
if (style._letterSpacing != null) {
11661168
letterSpacing = style._letterSpacing;
@@ -1210,9 +1212,7 @@ class EngineParagraphBuilder implements ui.ParagraphBuilder {
12101212
paint = foreground;
12111213
} else {
12121214
paint = ui.Paint();
1213-
if (color != null) {
1214-
paint.color = color;
1215-
}
1215+
paint.color = color;
12161216
}
12171217

12181218
if (i >= _ops.length) {

lib/web_ui/lib/src/engine/text/ruler.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ class ParagraphGeometricStyle {
8484

8585
if (fontSize != null) {
8686
result.write(fontSize!.floor());
87-
result.write('px');
8887
} else {
8988
result.write(DomRenderer.defaultFontSize);
9089
}
91-
result.write(' ');
90+
result.write('px ');
9291
result.write(canonicalizeFontFamily(effectiveFontFamily));
9392

9493
return result.toString();

0 commit comments

Comments
 (0)