From 7dce8b88251e47aed6de2a3f114ef453e4b4a6a2 Mon Sep 17 00:00:00 2001 From: Yegor Date: Tue, 2 Jan 2024 12:41:08 -0800 Subject: [PATCH] [web] make TextStyle implementations consistent (flutter/engine#49465) Make TextStyle implementations consistent across web renderers and consistent with the mobile implementation. This will allow us to unskip `test/painting/text_style_test.dart` on the framework side. --- .../web_ui/lib/src/engine/canvaskit/text.dart | 97 ++++++++ .../web_ui/lib/src/engine/html/renderer.dart | 1 + .../engine/skwasm/skwasm_impl/paragraph.dart | 98 +++++++- .../lib/src/engine/text/canvas_paragraph.dart | 8 + .../web_ui/lib/src/engine/text/paragraph.dart | 144 +++++------- .../html/text/layout_fragmenter_test.dart | 50 ++++ .../lib/web_ui/test/ui/text_style_test.dart | 215 ++++++++++++++++++ 7 files changed, 525 insertions(+), 88 deletions(-) create mode 100644 engine/src/flutter/lib/web_ui/test/ui/text_style_test.dart diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart index cc52f41d33..25c6193869 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart @@ -226,6 +226,11 @@ class CkTextStyle implements ui.TextStyle { List? fontFeatures, List? fontVariations, }) { + assert( + color == null || foreground == null, + 'Cannot provide both a color and a foreground\n' + 'The color argument is just a shorthand for "foreground: Paint()..color = color".', + ); return CkTextStyle._( color, decoration, @@ -471,6 +476,98 @@ class CkTextStyle implements ui.TextStyle { return canvasKit.TextStyle(properties); }(); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is CkTextStyle + && other.color == color + && other.decoration == decoration + && other.decorationColor == decorationColor + && other.decorationStyle == decorationStyle + && other.fontWeight == fontWeight + && other.fontStyle == fontStyle + && other.textBaseline == textBaseline + && other.leadingDistribution == leadingDistribution + && other.fontFamily == fontFamily + && other.fontSize == fontSize + && other.letterSpacing == letterSpacing + && other.wordSpacing == wordSpacing + && other.height == height + && other.decorationThickness == decorationThickness + && other.locale == locale + && other.background == background + && other.foreground == foreground + && listEquals(other.shadows, shadows) + && listEquals(other.fontFamilyFallback, fontFamilyFallback) + && listEquals(other.fontFeatures, fontFeatures) + && listEquals(other.fontVariations, fontVariations); + } + + @override + int get hashCode { + final List? shadows = this.shadows; + final List? fontFeatures = this.fontFeatures; + final List? fontVariations = this.fontVariations; + final List? fontFamilyFallback = this.fontFamilyFallback; + return Object.hash( + color, + decoration, + decorationColor, + decorationStyle, + fontWeight, + fontStyle, + textBaseline, + leadingDistribution, + fontFamily, + fontFamilyFallback == null ? null : Object.hashAll(fontFamilyFallback), + fontSize, + letterSpacing, + wordSpacing, + height, + locale, + background, + foreground, + shadows == null ? null : Object.hashAll(shadows), + decorationThickness, + // Object.hash goes up to 20 arguments, but we have 21 + Object.hash( + fontFeatures == null ? null : Object.hashAll(fontFeatures), + fontVariations == null ? null : Object.hashAll(fontVariations), + ) + ); + } + + @override + String toString() { + final List? fontFamilyFallback = this.fontFamilyFallback; + final String? fontFamily = this.fontFamily; + return 'TextStyle(' + 'color: ${color ?? "unspecified"}, ' + 'decoration: ${decoration ?? "unspecified"}, ' + 'decorationColor: ${decorationColor ?? "unspecified"}, ' + 'decorationStyle: ${decorationStyle ?? "unspecified"}, ' + 'decorationThickness: ${decorationThickness ?? "unspecified"}, ' + 'fontWeight: ${fontWeight ?? "unspecified"}, ' + 'fontStyle: ${fontStyle ?? "unspecified"}, ' + 'textBaseline: ${textBaseline ?? "unspecified"}, ' + 'fontFamily: ${fontFamily != null && fontFamily.isNotEmpty ? fontFamily : "unspecified"}, ' + 'fontFamilyFallback: ${fontFamilyFallback != null && fontFamilyFallback.isNotEmpty ? fontFamilyFallback : "unspecified"}, ' + 'fontSize: ${fontSize ?? "unspecified"}, ' + 'letterSpacing: ${letterSpacing != null ? "${letterSpacing}x" : "unspecified"}, ' + 'wordSpacing: ${wordSpacing != null ? "${wordSpacing}x" : "unspecified"}, ' + 'height: ${height != null ? "${height}x" : "unspecified"}, ' + 'leadingDistribution: ${leadingDistribution ?? "unspecified"}, ' + 'locale: ${locale ?? "unspecified"}, ' + 'background: ${background ?? "unspecified"}, ' + 'foreground: ${foreground ?? "unspecified"}, ' + 'shadows: ${shadows ?? "unspecified"}, ' + 'fontFeatures: ${fontFeatures ?? "unspecified"}, ' + 'fontVariations: ${fontVariations ?? "unspecified"}' + ')'; + } } class CkStrutStyle implements ui.StrutStyle { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/html/renderer.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/html/renderer.dart index 0cf11314f8..98e797e753 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/html/renderer.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/html/renderer.dart @@ -258,6 +258,7 @@ class HtmlRenderer implements Renderer { letterSpacing: letterSpacing, wordSpacing: wordSpacing, height: height, + leadingDistribution: leadingDistribution, locale: locale, background: background, foreground: foreground, diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart index 02dc5cc274..fe7f0f85cd 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart @@ -317,7 +317,11 @@ class SkwasmTextStyle implements ui.TextStyle { this.shadows, this.fontFeatures, this.fontVariations, - }); + }) : assert( + color == null || foreground == null, + 'Cannot provide both a color and a foreground\n' + 'The color argument is just a shorthand for "foreground: Paint()..color = color".', + ); void applyToNative(SkwasmNativeTextStyle style) { final TextStyleHandle handle = style.handle; @@ -451,6 +455,98 @@ class SkwasmTextStyle implements ui.TextStyle { final List? shadows; final List? fontFeatures; final List? fontVariations; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is SkwasmTextStyle + && other.color == color + && other.decoration == decoration + && other.decorationColor == decorationColor + && other.decorationStyle == decorationStyle + && other.fontWeight == fontWeight + && other.fontStyle == fontStyle + && other.textBaseline == textBaseline + && other.leadingDistribution == leadingDistribution + && other.fontFamily == fontFamily + && other.fontSize == fontSize + && other.letterSpacing == letterSpacing + && other.wordSpacing == wordSpacing + && other.height == height + && other.decorationThickness == decorationThickness + && other.locale == locale + && other.background == background + && other.foreground == foreground + && listEquals(other.shadows, shadows) + && listEquals(other.fontFamilyFallback, fontFamilyFallback) + && listEquals(other.fontFeatures, fontFeatures) + && listEquals(other.fontVariations, fontVariations); + } + + @override + int get hashCode { + final List? shadows = this.shadows; + final List? fontFeatures = this.fontFeatures; + final List? fontVariations = this.fontVariations; + final List? fontFamilyFallback = this.fontFamilyFallback; + return Object.hash( + color, + decoration, + decorationColor, + decorationStyle, + fontWeight, + fontStyle, + textBaseline, + leadingDistribution, + fontFamily, + fontFamilyFallback == null ? null : Object.hashAll(fontFamilyFallback), + fontSize, + letterSpacing, + wordSpacing, + height, + locale, + background, + foreground, + shadows == null ? null : Object.hashAll(shadows), + decorationThickness, + // Object.hash goes up to 20 arguments, but we have 21 + Object.hash( + fontFeatures == null ? null : Object.hashAll(fontFeatures), + fontVariations == null ? null : Object.hashAll(fontVariations), + ) + ); + } + + @override + String toString() { + final List? fontFamilyFallback = this.fontFamilyFallback; + final String? fontFamily = this.fontFamily; + return 'TextStyle(' + 'color: ${color ?? "unspecified"}, ' + 'decoration: ${decoration ?? "unspecified"}, ' + 'decorationColor: ${decorationColor ?? "unspecified"}, ' + 'decorationStyle: ${decorationStyle ?? "unspecified"}, ' + 'decorationThickness: ${decorationThickness ?? "unspecified"}, ' + 'fontWeight: ${fontWeight ?? "unspecified"}, ' + 'fontStyle: ${fontStyle ?? "unspecified"}, ' + 'textBaseline: ${textBaseline ?? "unspecified"}, ' + 'fontFamily: ${fontFamily != null && fontFamily.isNotEmpty ? fontFamily : "unspecified"}, ' + 'fontFamilyFallback: ${fontFamilyFallback != null && fontFamilyFallback.isNotEmpty ? fontFamilyFallback : "unspecified"}, ' + 'fontSize: ${fontSize ?? "unspecified"}, ' + 'letterSpacing: ${letterSpacing != null ? "${letterSpacing}x" : "unspecified"}, ' + 'wordSpacing: ${wordSpacing != null ? "${wordSpacing}x" : "unspecified"}, ' + 'height: ${height != null ? "${height}x" : "unspecified"}, ' + 'leadingDistribution: ${leadingDistribution ?? "unspecified"}, ' + 'locale: ${locale ?? "unspecified"}, ' + 'background: ${background ?? "unspecified"}, ' + 'foreground: ${foreground ?? "unspecified"}, ' + 'shadows: ${shadows ?? "unspecified"}, ' + 'fontFeatures: ${fontFeatures ?? "unspecified"}, ' + 'fontVariations: ${fontVariations ?? "unspecified"}' + ')'; + } } class SkwasmStrutStyle extends SkwasmObjectWrapper implements ui.StrutStyle { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart index 2fdc94b2d1..a692a3698b 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart @@ -431,6 +431,7 @@ abstract class StyleNode { letterSpacing: _letterSpacing, wordSpacing: _wordSpacing, height: _height, + leadingDistribution: _leadingDistribution, locale: _locale, background: _background, foreground: _foreground, @@ -456,6 +457,7 @@ abstract class StyleNode { double? get _letterSpacing; double? get _wordSpacing; double? get _height; + ui.TextLeadingDistribution? get _leadingDistribution; ui.Locale? get _locale; ui.Paint? get _background; ui.Paint? get _foreground; @@ -521,6 +523,9 @@ class ChildStyleNode extends StyleNode { @override double? get _height => style.height ?? parent._height; + @override + ui.TextLeadingDistribution? get _leadingDistribution => style.leadingDistribution ?? parent._leadingDistribution; + @override ui.Locale? get _locale => style.locale ?? parent._locale; @@ -598,6 +603,9 @@ class RootStyleNode extends StyleNode { @override double? get _height => paragraphStyle.height; + @override + ui.TextLeadingDistribution? get _leadingDistribution => null; + @override ui.Locale? get _locale => paragraphStyle.locale; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart index 49a34f14c4..27ea726c9c 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -568,6 +568,7 @@ class EngineTextStyle implements ui.TextStyle { required double? letterSpacing, required double? wordSpacing, required double? height, + required ui.TextLeadingDistribution? leadingDistribution, required ui.Locale? locale, required ui.Paint? background, required ui.Paint? foreground, @@ -595,6 +596,7 @@ class EngineTextStyle implements ui.TextStyle { this.letterSpacing, this.wordSpacing, this.height, + this.leadingDistribution, this.locale, this.background, this.foreground, @@ -640,6 +642,7 @@ class EngineTextStyle implements ui.TextStyle { final double? letterSpacing; final double? wordSpacing; final double? height; + final ui.TextLeadingDistribution? leadingDistribution; final ui.Locale? locale; final ui.Paint? background; final ui.Paint? foreground; @@ -688,101 +691,68 @@ class EngineTextStyle implements ui.TextStyle { ); } - EngineTextStyle copyWith({ - ui.Color? color, - ui.TextDecoration? decoration, - ui.Color? decorationColor, - ui.TextDecorationStyle? decorationStyle, - double? decorationThickness, - ui.FontWeight? fontWeight, - ui.FontStyle? fontStyle, - ui.TextBaseline? textBaseline, - String? fontFamily, - List? fontFamilyFallback, - double? fontSize, - double? letterSpacing, - double? wordSpacing, - double? height, - ui.Locale? locale, - ui.Paint? background, - ui.Paint? foreground, - List? shadows, - List? fontFeatures, - List? fontVariations, - }) { - return EngineTextStyle( - color: color ?? this.color, - decoration: decoration ?? this.decoration, - decorationColor: decorationColor ?? this.decorationColor, - decorationStyle: decorationStyle ?? this.decorationStyle, - decorationThickness: decorationThickness ?? this.decorationThickness, - fontWeight: fontWeight ?? this.fontWeight, - fontStyle: fontStyle ?? this.fontStyle, - textBaseline: textBaseline ?? this.textBaseline, - fontFamily: fontFamily ?? this.fontFamily, - fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback, - fontSize: fontSize ?? this.fontSize, - letterSpacing: letterSpacing ?? this.letterSpacing, - wordSpacing: wordSpacing ?? this.wordSpacing, - height: height ?? this.height, - locale: locale ?? this.locale, - background: background ?? this.background, - foreground: foreground ?? this.foreground, - shadows: shadows ?? this.shadows, - fontFeatures: fontFeatures ?? this.fontFeatures, - fontVariations: fontVariations ?? this.fontVariations, - ); - } - @override bool operator ==(Object other) { if (identical(this, other)) { return true; } - if (other.runtimeType != runtimeType) { - return false; - } - return other is EngineTextStyle && - other.color == color && - other.decoration == decoration && - other.decorationColor == decorationColor && - other.decorationStyle == decorationStyle && - other.fontWeight == fontWeight && - other.fontStyle == fontStyle && - other.textBaseline == textBaseline && - other.fontFamily == fontFamily && - other.fontSize == fontSize && - other.letterSpacing == letterSpacing && - other.wordSpacing == wordSpacing && - other.height == height && - other.locale == locale && - other.background == background && - other.foreground == foreground && - listEquals(other.shadows, shadows) && - listEquals(other.fontFamilyFallback, fontFamilyFallback); + return other is EngineTextStyle + && other.color == color + && other.decoration == decoration + && other.decorationColor == decorationColor + && other.decorationStyle == decorationStyle + && other.fontWeight == fontWeight + && other.fontStyle == fontStyle + && other.textBaseline == textBaseline + && other.leadingDistribution == leadingDistribution + && other.fontFamily == fontFamily + && other.fontSize == fontSize + && other.letterSpacing == letterSpacing + && other.wordSpacing == wordSpacing + && other.height == height + && other.decorationThickness == decorationThickness + && other.locale == locale + && other.background == background + && other.foreground == foreground + && listEquals(other.shadows, shadows) + && listEquals(other.fontFamilyFallback, fontFamilyFallback) + && listEquals(other.fontFeatures, fontFeatures) + && listEquals(other.fontVariations, fontVariations); } @override - int get hashCode => Object.hash( - color, - decoration, - decorationColor, - decorationStyle, - decorationThickness, - fontWeight, - fontStyle, - textBaseline, - fontFamily, - fontFamilyFallback, - fontSize, - letterSpacing, - wordSpacing, - height, - locale, - background, - foreground, - shadows, - ); + int get hashCode { + final List? shadows = this.shadows; + final List? fontFeatures = this.fontFeatures; + final List? fontVariations = this.fontVariations; + final List? fontFamilyFallback = this.fontFamilyFallback; + return Object.hash( + color, + decoration, + decorationColor, + decorationStyle, + fontWeight, + fontStyle, + textBaseline, + leadingDistribution, + fontFamily, + fontFamilyFallback == null ? null : Object.hashAll(fontFamilyFallback), + fontSize, + letterSpacing, + wordSpacing, + height, + locale, + background, + foreground, + shadows == null ? null : Object.hashAll(shadows), + decorationThickness, + // Object.hash goes up to 20 arguments, but we have 21 + Object.hash( + fontFeatures == null ? null : Object.hashAll(fontFeatures), + fontVariations == null ? null : Object.hashAll(fontVariations), + ) + ); + } @override String toString() { diff --git a/engine/src/flutter/lib/web_ui/test/html/text/layout_fragmenter_test.dart b/engine/src/flutter/lib/web_ui/test/html/text/layout_fragmenter_test.dart index 8870288cfb..056c52c859 100644 --- a/engine/src/flutter/lib/web_ui/test/html/text/layout_fragmenter_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/text/layout_fragmenter_test.dart @@ -287,3 +287,53 @@ List<_Fragment> split(CanvasParagraph paragraph) { List computeLayoutFragments(CanvasParagraph paragraph) { return LayoutFragmenter(paragraph.plainText, paragraph.spans).fragment(); } + +extension _EngineTextStyle on EngineTextStyle { + EngineTextStyle copyWith({ + Color? color, + TextDecoration? decoration, + Color? decorationColor, + TextDecorationStyle? decorationStyle, + double? decorationThickness, + FontWeight? fontWeight, + FontStyle? fontStyle, + TextBaseline? textBaseline, + String? fontFamily, + List? fontFamilyFallback, + double? fontSize, + double? letterSpacing, + double? wordSpacing, + double? height, + TextLeadingDistribution? leadingDistribution, + Locale? locale, + Paint? background, + Paint? foreground, + List? shadows, + List? fontFeatures, + List? fontVariations, + }) { + return EngineTextStyle( + color: color ?? this.color, + decoration: decoration ?? this.decoration, + decorationColor: decorationColor ?? this.decorationColor, + decorationStyle: decorationStyle ?? this.decorationStyle, + decorationThickness: decorationThickness ?? this.decorationThickness, + fontWeight: fontWeight ?? this.fontWeight, + fontStyle: fontStyle ?? this.fontStyle, + textBaseline: textBaseline ?? this.textBaseline, + fontFamily: fontFamily ?? this.fontFamily, + fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback, + fontSize: fontSize ?? this.fontSize, + letterSpacing: letterSpacing ?? this.letterSpacing, + wordSpacing: wordSpacing ?? this.wordSpacing, + height: height ?? this.height, + leadingDistribution: leadingDistribution, + locale: locale ?? this.locale, + background: background ?? this.background, + foreground: foreground ?? this.foreground, + shadows: shadows ?? this.shadows, + fontFeatures: fontFeatures ?? this.fontFeatures, + fontVariations: fontVariations ?? this.fontVariations, + ); + } +} diff --git a/engine/src/flutter/lib/web_ui/test/ui/text_style_test.dart b/engine/src/flutter/lib/web_ui/test/ui/text_style_test.dart new file mode 100644 index 0000000000..60e33994c6 --- /dev/null +++ b/engine/src/flutter/lib/web_ui/test/ui/text_style_test.dart @@ -0,0 +1,215 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:test/bootstrap/browser.dart'; +import 'package:test/test.dart'; +import 'package:ui/ui.dart' as ui; + +import '../common/test_initialization.dart'; + +void main() { + internalBootstrapBrowserTest(() => testMain); +} + +Future testMain() async { + setUpUnitTests( + emulateTesterEnvironment: false, + setUpTestViewDimensions: false, + ); + + test('blanks are equal to each other', () { + final ui.TextStyle a = ui.TextStyle(); + final ui.TextStyle b = ui.TextStyle(); + expect(a, b); + expect(a.hashCode, b.hashCode); + }); + + test('each property individually equal', () { + for (final String property in _populatorsA.keys) { + final _TextStylePropertyPopulator populator = _populatorsA[property]!; + + final _TestTextStyleBuilder aBuilder = _TestTextStyleBuilder(); + populator(aBuilder); + final ui.TextStyle a = aBuilder.build(); + + final _TestTextStyleBuilder bBuilder = _TestTextStyleBuilder(); + populator(bBuilder); + final ui.TextStyle b = bBuilder.build(); + + expect(reason: '$property property is equal', a, b); + expect(reason: '$property hashCode is equal', a.hashCode, b.hashCode); + } + }); + + test('each property individually not equal', () { + for (final String property in _populatorsA.keys) { + final _TextStylePropertyPopulator populatorA = _populatorsA[property]!; + + final _TestTextStyleBuilder aBuilder = _TestTextStyleBuilder(); + populatorA(aBuilder); + final ui.TextStyle a = aBuilder.build(); + + final _TextStylePropertyPopulator populatorB = _populatorsB[property]!; + final _TestTextStyleBuilder bBuilder = _TestTextStyleBuilder(); + populatorB(bBuilder); + final ui.TextStyle b = bBuilder.build(); + + expect(reason: '$property property is not equal', a, isNot(b)); + expect(reason: '$property hashCode is not equal', a.hashCode, isNot(b.hashCode)); + } + }); + + // `color` and `foreground` cannot be used at the same time, so each test skips + // one or the other to be able to test all variations. + for (final String skipProperty in const ['color', 'foreground']) { + test('all properties (except $skipProperty) altogether equal', () { + final _TestTextStyleBuilder aBuilder = _TestTextStyleBuilder(); + final _TestTextStyleBuilder bBuilder = _TestTextStyleBuilder(); + + for (final String property in _populatorsA.keys) { + if (property == skipProperty) { + continue; + } + final _TextStylePropertyPopulator populator = _populatorsA[property]!; + populator(aBuilder); + populator(bBuilder); + } + + final ui.TextStyle a = aBuilder.build(); + final ui.TextStyle b = bBuilder.build(); + + expect(a, b); + expect(a.hashCode, b.hashCode); + }); + + test('all properties (except $skipProperty) altogether not equal', () { + final _TestTextStyleBuilder aBuilder = _TestTextStyleBuilder(); + final _TestTextStyleBuilder bBuilder = _TestTextStyleBuilder(); + + for (final String property in _populatorsA.keys) { + if (property == skipProperty) { + continue; + } + final _TextStylePropertyPopulator populatorA = _populatorsA[property]!; + populatorA(aBuilder); + + final _TextStylePropertyPopulator populatorB = _populatorsB[property]!; + populatorB(bBuilder); + } + + final ui.TextStyle a = aBuilder.build(); + final ui.TextStyle b = bBuilder.build(); + + expect(a, isNot(b)); + expect(a.hashCode, isNot(b.hashCode)); + }); + } +} + +typedef _TextStylePropertyPopulator = void Function(_TestTextStyleBuilder builder); + +// Paint equality is based on identity, so all the paints below are different, +// even though they express the same paint. +final ui.Paint _backgroundA = ui.Paint(); +final ui.Paint _foregroundA = ui.Paint(); +final ui.Paint _backgroundB = ui.Paint(); +final ui.Paint _foregroundB = ui.Paint(); + +final Map _populatorsA = { + 'color': (_TestTextStyleBuilder builder) { builder.color = const ui.Color(0xff000000); }, + 'decoration': (_TestTextStyleBuilder builder) { builder.decoration = ui.TextDecoration.none; }, + 'decorationColor': (_TestTextStyleBuilder builder) { builder.decorationColor = const ui.Color(0xffaa0000); }, + 'decorationStyle': (_TestTextStyleBuilder builder) { builder.decorationStyle = ui.TextDecorationStyle.solid; }, + 'decorationThickness': (_TestTextStyleBuilder builder) { builder.decorationThickness = 1.0; }, + 'fontWeight': (_TestTextStyleBuilder builder) { builder.fontWeight = ui.FontWeight.w400; }, + 'fontStyle': (_TestTextStyleBuilder builder) { builder.fontStyle = ui.FontStyle.normal; }, + 'textBaseline': (_TestTextStyleBuilder builder) { builder.textBaseline = ui.TextBaseline.alphabetic; }, + 'fontFamily': (_TestTextStyleBuilder builder) { builder.fontFamily = 'Arial'; }, + 'fontFamilyFallback': (_TestTextStyleBuilder builder) { builder.fontFamilyFallback = ['Roboto']; }, + 'fontSize': (_TestTextStyleBuilder builder) { builder.fontSize = 12; }, + 'letterSpacing': (_TestTextStyleBuilder builder) { builder.letterSpacing = 1.2; }, + 'wordSpacing': (_TestTextStyleBuilder builder) { builder.wordSpacing = 2.3; }, + 'height': (_TestTextStyleBuilder builder) { builder.height = 13; }, + 'leadingDistribution': (_TestTextStyleBuilder builder) { builder.leadingDistribution = ui.TextLeadingDistribution.proportional; }, + 'locale': (_TestTextStyleBuilder builder) { builder.locale = const ui.Locale('en', 'US'); }, + 'background': (_TestTextStyleBuilder builder) { builder.background = _backgroundA; }, + 'foreground': (_TestTextStyleBuilder builder) { builder.foreground = _foregroundA; }, + 'shadows': (_TestTextStyleBuilder builder) { builder.shadows = [const ui.Shadow()]; }, + 'fontFeatures': (_TestTextStyleBuilder builder) { builder.fontFeatures = [const ui.FontFeature.caseSensitiveForms()]; }, + 'fontVariations': (_TestTextStyleBuilder builder) { builder.fontVariations = [ const ui.FontVariation.italic(0.1)]; }, +}; + +final Map _populatorsB = { + 'color': (_TestTextStyleBuilder builder) { builder.color = const ui.Color(0xffbb0000); }, + 'decoration': (_TestTextStyleBuilder builder) { builder.decoration = ui.TextDecoration.lineThrough; }, + 'decorationColor': (_TestTextStyleBuilder builder) { builder.decorationColor = const ui.Color(0xffcc0000); }, + 'decorationStyle': (_TestTextStyleBuilder builder) { builder.decorationStyle = ui.TextDecorationStyle.dotted; }, + 'decorationThickness': (_TestTextStyleBuilder builder) { builder.decorationThickness = 1.4; }, + 'fontWeight': (_TestTextStyleBuilder builder) { builder.fontWeight = ui.FontWeight.w600; }, + 'fontStyle': (_TestTextStyleBuilder builder) { builder.fontStyle = ui.FontStyle.italic; }, + 'textBaseline': (_TestTextStyleBuilder builder) { builder.textBaseline = ui.TextBaseline.ideographic; }, + 'fontFamily': (_TestTextStyleBuilder builder) { builder.fontFamily = 'Noto'; }, + 'fontFamilyFallback': (_TestTextStyleBuilder builder) { builder.fontFamilyFallback = ['Verdana']; }, + 'fontSize': (_TestTextStyleBuilder builder) { builder.fontSize = 12.1; }, + 'letterSpacing': (_TestTextStyleBuilder builder) { builder.letterSpacing = 1.25; }, + 'wordSpacing': (_TestTextStyleBuilder builder) { builder.wordSpacing = 2.35; }, + 'height': (_TestTextStyleBuilder builder) { builder.height = 13.1; }, + 'leadingDistribution': (_TestTextStyleBuilder builder) { builder.leadingDistribution = ui.TextLeadingDistribution.even; }, + 'locale': (_TestTextStyleBuilder builder) { builder.locale = const ui.Locale('fr', 'CA'); }, + 'background': (_TestTextStyleBuilder builder) { builder.background = _backgroundB; }, + 'foreground': (_TestTextStyleBuilder builder) { builder.foreground = _foregroundB; }, + 'shadows': (_TestTextStyleBuilder builder) { builder.shadows = [const ui.Shadow(blurRadius: 5)]; }, + 'fontFeatures': (_TestTextStyleBuilder builder) { builder.fontFeatures = [const ui.FontFeature.alternative(2)]; }, + 'fontVariations': (_TestTextStyleBuilder builder) { builder.fontVariations = [ const ui.FontVariation.italic(0.4)]; }, +}; + +class _TestTextStyleBuilder { + ui.Color? color; + ui.TextDecoration? decoration; + ui.Color? decorationColor; + ui.TextDecorationStyle? decorationStyle; + double? decorationThickness; + ui.FontWeight? fontWeight; + ui.FontStyle? fontStyle; + ui.TextBaseline? textBaseline; + String? fontFamily; + List? fontFamilyFallback; + double? fontSize; + double? letterSpacing; + double? wordSpacing; + double? height; + ui.TextLeadingDistribution? leadingDistribution; + ui.Locale? locale; + ui.Paint? background; + ui.Paint? foreground; + List? shadows; + List? fontFeatures; + List? fontVariations; + + ui.TextStyle build() { + return ui.TextStyle( + color: color, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + decorationThickness: decorationThickness, + fontWeight: fontWeight, + fontStyle: fontStyle, + textBaseline: textBaseline, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSize: fontSize, + letterSpacing: letterSpacing, + wordSpacing: wordSpacing, + height: height, + leadingDistribution: leadingDistribution, + locale: locale, + background: background, + foreground: foreground, + shadows: shadows, + fontFeatures: fontFeatures, + fontVariations: fontVariations, + ); + } +}