|
@@ -1,3 +1,5 @@
|
|
|
|
+using System;
|
|
|
|
+using System.IO;
|
|
using System.Net;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls;
|
|
@@ -5,7 +7,6 @@ using Avalonia.Controls.Documents;
|
|
using Avalonia.Layout;
|
|
using Avalonia.Layout;
|
|
using Avalonia.Media;
|
|
using Avalonia.Media;
|
|
using Xunit;
|
|
using Xunit;
|
|
-using static System.Net.Mime.MediaTypeNames;
|
|
|
|
|
|
|
|
#if AVALONIA_SKIA
|
|
#if AVALONIA_SKIA
|
|
namespace Avalonia.Skia.RenderTests
|
|
namespace Avalonia.Skia.RenderTests
|
|
@@ -217,60 +218,60 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
|
|
TextWrapping = textWrapping
|
|
TextWrapping = textWrapping
|
|
});
|
|
});
|
|
|
|
|
|
- target.Children.Add(new TextBlock
|
|
|
|
|
|
+ target.Children.Add(new TextBlock
|
|
{
|
|
{
|
|
Text = text,
|
|
Text = text,
|
|
Background = Brushes.Red,
|
|
Background = Brushes.Red,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
- TextAlignment = TextAlignment.Left,
|
|
|
|
- Width = width,
|
|
|
|
|
|
+ TextAlignment = TextAlignment.Left,
|
|
|
|
+ Width = width,
|
|
TextWrapping = textWrapping
|
|
TextWrapping = textWrapping
|
|
});
|
|
});
|
|
- target.Children.Add(new TextBlock
|
|
|
|
- {
|
|
|
|
- Text = text,
|
|
|
|
- Background = Brushes.Red,
|
|
|
|
- HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
- TextAlignment = TextAlignment.Center,
|
|
|
|
|
|
+ target.Children.Add(new TextBlock
|
|
|
|
+ {
|
|
|
|
+ Text = text,
|
|
|
|
+ Background = Brushes.Red,
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ TextAlignment = TextAlignment.Center,
|
|
Width = width,
|
|
Width = width,
|
|
TextWrapping = textWrapping
|
|
TextWrapping = textWrapping
|
|
});
|
|
});
|
|
- target.Children.Add(new TextBlock
|
|
|
|
- {
|
|
|
|
|
|
+ target.Children.Add(new TextBlock
|
|
|
|
+ {
|
|
Text = text,
|
|
Text = text,
|
|
Background = Brushes.Red,
|
|
Background = Brushes.Red,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
- TextAlignment = TextAlignment.Right,
|
|
|
|
|
|
+ TextAlignment = TextAlignment.Right,
|
|
Width = width,
|
|
Width = width,
|
|
- TextWrapping = textWrapping
|
|
|
|
|
|
+ TextWrapping = textWrapping
|
|
});
|
|
});
|
|
|
|
|
|
- target.Children.Add(new TextBlock
|
|
|
|
- {
|
|
|
|
|
|
+ target.Children.Add(new TextBlock
|
|
|
|
+ {
|
|
Text = text,
|
|
Text = text,
|
|
- Background = Brushes.Red,
|
|
|
|
|
|
+ Background = Brushes.Red,
|
|
HorizontalAlignment = HorizontalAlignment.Right,
|
|
HorizontalAlignment = HorizontalAlignment.Right,
|
|
- TextAlignment = TextAlignment.Left,
|
|
|
|
- Width = width,
|
|
|
|
|
|
+ TextAlignment = TextAlignment.Left,
|
|
|
|
+ Width = width,
|
|
TextWrapping = textWrapping
|
|
TextWrapping = textWrapping
|
|
});
|
|
});
|
|
- target.Children.Add(new TextBlock
|
|
|
|
- {
|
|
|
|
- Text = text,
|
|
|
|
- Background = Brushes.Red,
|
|
|
|
- HorizontalAlignment = HorizontalAlignment.Right,
|
|
|
|
- TextAlignment = TextAlignment.Center,
|
|
|
|
- Width = width,
|
|
|
|
- TextWrapping = textWrapping
|
|
|
|
|
|
+ target.Children.Add(new TextBlock
|
|
|
|
+ {
|
|
|
|
+ Text = text,
|
|
|
|
+ Background = Brushes.Red,
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Right,
|
|
|
|
+ TextAlignment = TextAlignment.Center,
|
|
|
|
+ Width = width,
|
|
|
|
+ TextWrapping = textWrapping
|
|
});
|
|
});
|
|
- target.Children.Add(new TextBlock
|
|
|
|
- {
|
|
|
|
- Text = text,
|
|
|
|
- Background = Brushes.Red,
|
|
|
|
- HorizontalAlignment = HorizontalAlignment.Right,
|
|
|
|
- TextAlignment = TextAlignment.Right,
|
|
|
|
- Width = width,
|
|
|
|
- TextWrapping = textWrapping
|
|
|
|
|
|
+ target.Children.Add(new TextBlock
|
|
|
|
+ {
|
|
|
|
+ Text = text,
|
|
|
|
+ Background = Brushes.Red,
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Right,
|
|
|
|
+ TextAlignment = TextAlignment.Right,
|
|
|
|
+ Width = width,
|
|
|
|
+ TextWrapping = textWrapping
|
|
});
|
|
});
|
|
|
|
|
|
var testName = $"Should_Measure_Arrange_TextBlock_{width}_{textWrapping}";
|
|
var testName = $"Should_Measure_Arrange_TextBlock_{width}_{textWrapping}";
|
|
@@ -278,5 +279,124 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
|
|
await RenderToFile(target, testName);
|
|
await RenderToFile(target, testName);
|
|
CompareImages(testName);
|
|
CompareImages(testName);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [Win32Fact("Has text")]
|
|
|
|
+ public async Task Should_Keep_TrailingWhiteSpace()
|
|
|
|
+ {
|
|
|
|
+ // <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
|
|
|
+ // <TextBlock Margin="0 10 0 0" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Magenta" FontSize="44" Text="aaaa" FontFamily="Courier New"/>
|
|
|
|
+ // <TextBlock Margin="0 10 0 0" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Magenta" FontSize="44" Text="a a " FontFamily="Courier New"/>
|
|
|
|
+ // <TextBlock Margin="0 10 0 0" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Magenta" FontSize="44" Text=" " FontFamily="Courier New"/>
|
|
|
|
+ // <TextBlock Margin="0 10 0 0" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Magenta" FontSize="44" Text="LLLL" FontFamily="Courier New"/>
|
|
|
|
+ // </StackPanel>
|
|
|
|
+
|
|
|
|
+ var target = new StackPanel
|
|
|
|
+ {
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ Width = 300,
|
|
|
|
+ Height = 300,
|
|
|
|
+ };
|
|
|
|
+ target.Children.Add(CreateText("aaaa"));
|
|
|
|
+ target.Children.Add(CreateText("a a "));
|
|
|
|
+ target.Children.Add(CreateText(" ")); // This one does not render correctly on Direct2D1
|
|
|
|
+ target.Children.Add(CreateText("LLLL"));
|
|
|
|
+
|
|
|
|
+ var testName = $"Should_Keep_TrailingWhiteSpace";
|
|
|
|
+ await RenderToFile(target, testName);
|
|
|
|
+ CompareImages(testName);
|
|
|
|
+
|
|
|
|
+ static TextBlock CreateText(string text) => new TextBlock
|
|
|
|
+ {
|
|
|
|
+ Margin = new Thickness(0, 10, 0, 0),
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ Background = Brushes.Magenta,
|
|
|
|
+ FontSize = 44,
|
|
|
|
+ Text = text,
|
|
|
|
+ FontFamily = new FontFamily("Courier New")
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Win32Fact("Has text")]
|
|
|
|
+ public async Task Should_Account_For_Overhang_Leading_And_Trailing()
|
|
|
|
+ {
|
|
|
|
+ var target = new StackPanel
|
|
|
|
+ {
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ Width = 300,
|
|
|
|
+ Height = 600,
|
|
|
|
+ Background = new SolidColorBrush(Colors.White), // Required antialiasing to work for Overhang
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ target.Children.Add(CreateText("f"));
|
|
|
|
+ target.Children.Add(CreateText("y"));
|
|
|
|
+ target.Children.Add(CreateText("ff"));
|
|
|
|
+ target.Children.Add(CreateText("yy"));
|
|
|
|
+ target.Children.Add(CreateText("faaf"));
|
|
|
|
+ target.Children.Add(CreateText("yaay"));
|
|
|
|
+ target.Children.Add(CreateText("y y "));
|
|
|
|
+ target.Children.Add(CreateText("f f "));
|
|
|
|
+
|
|
|
|
+ var testName = $"Should_Account_For_Overhang_Leading_And_Trailing";
|
|
|
|
+ await RenderToFile(target, testName);
|
|
|
|
+ CompareImages(testName);
|
|
|
|
+
|
|
|
|
+#if AVALONIA_SKIA
|
|
|
|
+ const string symbolsFont = "resm:Avalonia.Skia.RenderTests.Assets?assembly=Avalonia.Skia.RenderTests#Source Serif 4 36pt";
|
|
|
|
+#else
|
|
|
|
+ const string symbolsFont = "resm:Avalonia.Direct2D1.RenderTests.Assets?assembly=Avalonia.Direct2D1.RenderTests#Source Serif 4 36pt";
|
|
|
|
+#endif
|
|
|
|
+ static TextBlock CreateText(string text) => new TextBlock
|
|
|
|
+ {
|
|
|
|
+ ClipToBounds = false,
|
|
|
|
+ Margin = new Thickness(4),
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ Background = Brushes.Magenta,
|
|
|
|
+ FontStyle = FontStyle.Italic,
|
|
|
|
+ FontSize = 44,
|
|
|
|
+ Text = text,
|
|
|
|
+ FontFamily = new FontFamily(symbolsFont)
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Win32Fact("Has text")]
|
|
|
|
+ public async Task Should_Draw_MultiLineText_WithOverHandLeadingTrailing()
|
|
|
|
+ {
|
|
|
|
+ var target = new StackPanel
|
|
|
|
+ {
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ Width = 600,
|
|
|
|
+ Height = 200,
|
|
|
|
+ Background = new SolidColorBrush(Colors.White), // Required antialiasing to work for Overhang
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ target.Children.Add(CreateText("fff Why this is a\nbig text yyy\nyyy with multiple lines fff"));
|
|
|
|
+
|
|
|
|
+ var testName = $"Should_Draw_MultiLineText_WithOverHandLeadingTrailing";
|
|
|
|
+ await RenderToFile(target, testName);
|
|
|
|
+ CompareImages(testName);
|
|
|
|
+
|
|
|
|
+#if AVALONIA_SKIA
|
|
|
|
+ const string symbolsFont = "resm:Avalonia.Skia.RenderTests.Assets?assembly=Avalonia.Skia.RenderTests#Source Serif 4 36pt";
|
|
|
|
+#else
|
|
|
|
+ const string symbolsFont = "resm:Avalonia.Direct2D1.RenderTests.Assets?assembly=Avalonia.Direct2D1.RenderTests#Source Serif 4 36pt";
|
|
|
|
+#endif
|
|
|
|
+ static TextBlock CreateText(string text) => new TextBlock
|
|
|
|
+ {
|
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ TextAlignment = TextAlignment.Center,
|
|
|
|
+ Background = Brushes.Magenta,
|
|
|
|
+ FontStyle = FontStyle.Italic,
|
|
|
|
+ FontSize = 44,
|
|
|
|
+ Text = text,
|
|
|
|
+ FontFamily = new FontFamily(symbolsFont)
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|