From 14c8c2445627dff7c88d49648a4782c54d594d09 Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Thu, 10 Dec 2020 16:30:09 -0800 Subject: [PATCH] [web] Fix regression in foreground style (#22999) --- lib/web_ui/lib/src/engine/text/paragraph.dart | 8 ++++++-- lib/web_ui/test/paragraph_builder_test.dart | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/web_ui/lib/src/engine/text/paragraph.dart b/lib/web_ui/lib/src/engine/text/paragraph.dart index 17fcf213e..5be563aa7 100644 --- a/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -1328,7 +1328,7 @@ class DomParagraphBuilder implements ui.ParagraphBuilder { /// paragraph. Plain text is more efficient to lay out and measure than rich /// text. EngineParagraph? _tryBuildPlainText() { - ui.Color color = _defaultTextColor; + ui.Color? color; ui.TextDecoration? decoration; ui.Color? decorationColor; ui.TextDecorationStyle? decorationStyle; @@ -1416,6 +1416,10 @@ class DomParagraphBuilder implements ui.ParagraphBuilder { i++; } + if (color == null && foreground == null) { + color = _defaultTextColor; + } + final EngineTextStyle cumulativeStyle = EngineTextStyle( color: color, decoration: decoration, @@ -1443,7 +1447,7 @@ class DomParagraphBuilder implements ui.ParagraphBuilder { paint = foreground; } else { paint = ui.Paint(); - paint.color = color; + paint.color = color!; } if (i >= _ops.length) { diff --git a/lib/web_ui/test/paragraph_builder_test.dart b/lib/web_ui/test/paragraph_builder_test.dart index fe3041bc1..68dc7e95a 100644 --- a/lib/web_ui/test/paragraph_builder_test.dart +++ b/lib/web_ui/test/paragraph_builder_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.6 +// @dart = 2.12 import 'package:test/bootstrap/browser.dart'; import 'package:test/test.dart'; import 'package:ui/src/engine.dart'; @@ -28,10 +28,20 @@ void testMain() { expect(paragraph.height, isNonZero); }); - test('PushStyle should not segfault after build()', () { + test('pushStyle should not segfault after build()', () { final ParagraphBuilder paragraphBuilder = ParagraphBuilder(ParagraphStyle()); paragraphBuilder.build(); paragraphBuilder.pushStyle(TextStyle()); }); + + test('the presence of foreground style should not throw', () { + final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle()); + builder.pushStyle(TextStyle( + foreground: Paint()..color = const Color(0xFFABCDEF), + )); + builder.addText('hi'); + + expect(() => builder.build(), returnsNormally); + }); } -- GitLab