| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- // Copyright (c) The Avalonia Project. All rights reserved.
- // Licensed under the MIT license. See licence.md file in the project root for full license information.
- using Avalonia.Controls;
- using Avalonia.Controls.Shapes;
- using Avalonia.Layout;
- using Avalonia.Media;
- using Xunit;
- #if AVALONIA_SKIA
- namespace Avalonia.Skia.RenderTests
- #else
- namespace Avalonia.Direct2D1.RenderTests.Shapes
- #endif
- {
- using System.Threading.Tasks;
- using Avalonia.Collections;
- public class PathTests : TestBase
- {
- public PathTests()
- : base(@"Shapes\Path")
- {
- }
- [Fact]
- public async Task Line_Absolute()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M 10,190 L 190,10 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task Line_Relative()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M10,190 l190,-190 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task HorizontalLine_Absolute()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M190,100 H10 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task HorizontalLine_Relative()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M190,100 h-180 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task VerticalLine_Absolute()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M100,190 V10 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task VerticalLine_Relative()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M100,190 V-180 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task CubicBezier_Absolute()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M190,0 C10,10 190,190 10,190 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task CubicBezier_Relative()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M190,0 c-180,10 0,190 -180,190 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task Arc_Absolute()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M190,100 A90,90 0 1,0 10,100 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task Arc_Relative()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M190,100 a90,90 0 1,0 -180,0 M0,0M200,200"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task Path_100px_Triangle_Centered()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 2,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M 0,100 L 100,100 50,0 Z"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task Path_Tick_Scaled()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 2,
- Stretch = Stretch.Uniform,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M 1145.607177734375,430 C1145.607177734375,430 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1138,434.5538330078125 1138,434.5538330078125 1138,434.5538330078125 1141.482177734375,438 1141.482177734375,438 1141.482177734375,438 1141.96875,437.9375 1141.96875,437.9375 1141.96875,437.9375 1147,431.34619140625 1147,431.34619140625 1147,431.34619140625 1145.607177734375,430 1145.607177734375,430 z"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task Path_Tick_Scaled_Stroke_8px()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Fill = Brushes.Gray,
- Stroke = Brushes.Red,
- StrokeThickness = 8,
- Stretch = Stretch.Uniform,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Data = StreamGeometry.Parse("M 1145.607177734375,430 C1145.607177734375,430 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1138,434.5538330078125 1138,434.5538330078125 1138,434.5538330078125 1141.482177734375,438 1141.482177734375,438 1141.482177734375,438 1141.96875,437.9375 1141.96875,437.9375 1141.96875,437.9375 1147,431.34619140625 1147,431.34619140625 1147,431.34619140625 1145.607177734375,430 1145.607177734375,430 z"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task Path_Expander_With_Border()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Border
- {
- BorderBrush = Brushes.Red,
- BorderThickness = new Thickness(1),
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Child = new Path
- {
- Fill = Brushes.Black,
- Stroke = Brushes.Black,
- StrokeThickness = 1,
- Stretch = Stretch.Uniform,
- Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task Path_With_PenLineCap()
- {
- Decorator target = new Decorator
- {
- Width = 200,
- Height = 200,
- Child = new Path
- {
- Stroke = Brushes.Black,
- StrokeThickness = 10,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- StrokeDashCap = PenLineCap.Triangle,
- StrokeDashArray = new AvaloniaList<double>(3, 1),
- StrokeStartLineCap = PenLineCap.Round,
- StrokeEndLineCap = PenLineCap.Square,
- Data = StreamGeometry.Parse("M 20,20 L 180,180"),
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task Path_With_Rotated_Geometry()
- {
- var target = new Border
- {
- Width = 200,
- Height = 200,
- Background = Brushes.White,
- Child = new Path
- {
- Fill = Brushes.Red,
- Data = new RectangleGeometry
- {
- Rect = new Rect(50, 50, 100, 100),
- Transform = new RotateTransform(45),
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- }
- }
|