Unverified Commit a18f5e84 authored by Dan Field's avatar Dan Field Committed by GitHub

Expose Text foreground from engine (#18347)

* update tests for TextStyle changes in engine

* roll engine, support Foreground on TextStyle

* roll to TextStyle.foreground

* add tests, update docs, fixes from tests

* add golden tests

* stroke + gradient

* update goldens hash

* Use centered widget

* fix typo

* Disable golden tests until Linux generated files are available

* update goldens
parent c35e484c
......@@ -452,6 +452,7 @@ class _TextStyleProxy implements TextStyle {
@override FontWeight get fontWeight => _delegate.fontWeight;
@override double get height => _delegate.height;
@override Locale get locale => _delegate.locale;
@override ui.Paint get foreground => _delegate.foreground;
@override ui.Paint get background => _delegate.background;
@override bool get inherit => _delegate.inherit;
@override double get letterSpacing => _delegate.letterSpacing;
......@@ -479,7 +480,7 @@ class _TextStyleProxy implements TextStyle {
}
@override
TextStyle copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, Locale locale, ui.Paint background, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel}) {
TextStyle copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, Locale locale, ui.Paint foreground, ui.Paint background, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel}) {
throw new UnimplementedError();
}
......
......@@ -216,4 +216,45 @@ void main() {
expect(TextStyle.lerp(foo, bar, 0.5).debugLabel, 'lerp(foo ⎯0.5→ bar)');
expect(TextStyle.lerp(foo.merge(bar), baz, 0.51).copyWith().debugLabel, '(lerp((foo).merge(bar) ⎯0.5→ baz)).copyWith');
});
test('TextStyle foreground and color combos', () {
const Color red = const Color.fromARGB(255, 255, 0, 0);
const Color blue = const Color.fromARGB(255, 0, 0, 255);
const TextStyle redTextStyle = const TextStyle(color: red);
const TextStyle blueTextStyle = const TextStyle(color: blue);
final TextStyle redPaintTextStyle = new TextStyle(foreground: new Paint()..color = red);
final TextStyle bluePaintTextStyle = new TextStyle(foreground: new Paint()..color = blue);
// merge/copyWith
final TextStyle redBlueBothForegroundMerged = redTextStyle.merge(blueTextStyle);
expect(redBlueBothForegroundMerged.color, blue);
expect(redBlueBothForegroundMerged.foreground, isNull);
final TextStyle redBlueBothPaintMerged = redPaintTextStyle.merge(bluePaintTextStyle);
expect(redBlueBothPaintMerged.color, null);
expect(redBlueBothPaintMerged.foreground, bluePaintTextStyle.foreground);
final TextStyle redPaintBlueColorMerged = redPaintTextStyle.merge(blueTextStyle);
expect(redPaintBlueColorMerged.color, null);
expect(redPaintBlueColorMerged.foreground, redPaintTextStyle.foreground);
final TextStyle blueColorRedPaintMerged = blueTextStyle.merge(redPaintTextStyle);
expect(blueColorRedPaintMerged.color, null);
expect(blueColorRedPaintMerged.foreground, redPaintTextStyle.foreground);
// apply
expect(redPaintTextStyle.apply(color: blue).color, isNull);
expect(redPaintTextStyle.apply(color: blue).foreground.color, red);
expect(redTextStyle.apply(color: blue).color, blue);
// lerp
expect(TextStyle.lerp(redTextStyle, blueTextStyle, .25).color, Color.lerp(red, blue, .25));
expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).color, isNull);
expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).foreground.color, red);
expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .75).foreground.color, blue);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).color, isNull);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).foreground.color, red);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75).foreground.color, blue);
});
}
......@@ -59,4 +59,84 @@ void main() {
skip: !Platform.isLinux,
);
});
testWidgets('Text Foreground', (WidgetTester tester) async {
const Color black = const Color(0xFF000000);
const Color red = const Color(0xFFFF0000);
const Color blue = const Color(0xFF0000FF);
final Shader linearGradient = const LinearGradient(colors: <Color>[red, blue]).createShader(new Rect.fromLTWH(0.0, 0.0, 50.0, 20.0));
await tester.pumpWidget(
new RepaintBoundary(
child: new Center(
child: new Text('Hello',
textDirection: TextDirection.ltr,
style: new TextStyle(
foreground: new Paint()
..color = black
..shader = linearGradient
),
),
),
),
);
await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile('text_golden.Foreground.gradient.png'),
// this was generated on MacOS and will fail on Linux
// change to !Platform.isLinux once they're properly generated
skip: true, // !Platform.isLinux,
);
await tester.pumpWidget(
new RepaintBoundary(
child: new Center(
child: new Text('Hello',
textDirection: TextDirection.ltr,
style: new TextStyle(
foreground: new Paint()
..color = black
..style = PaintingStyle.stroke
..strokeWidth = 2.0
),
),
),
),
);
await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile('text_golden.Foreground.stroke.png'),
// this was generated on MacOS and will fail on Linux
// change to !Platform.isLinux once they're properly generated
skip: true, // !Platform.isLinux,
);
await tester.pumpWidget(
new RepaintBoundary(
child: new Center(
child: new Text('Hello',
textDirection: TextDirection.ltr,
style: new TextStyle(
foreground: new Paint()
..color = black
..style = PaintingStyle.stroke
..strokeWidth = 2.0
..shader = linearGradient
),
),
),
),
);
await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile('text_golden.Foreground.stroke_and_gradient.png'),
// this was generated on MacOS and will fail on Linux
// change to !Platform.isLinux once they're properly generated
skip: true, // !Platform.isLinux,
);
});
}
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