| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System.Net;
- using System.Threading.Tasks;
- using Avalonia.Controls;
- using Avalonia.Controls.Documents;
- using Avalonia.Layout;
- using Avalonia.Media;
- using Xunit;
- #if AVALONIA_SKIA
- namespace Avalonia.Skia.RenderTests
- #else
- namespace Avalonia.Direct2D1.RenderTests.Controls
- #endif
- {
- public class TextBlockTests : TestBase
- {
- public TextBlockTests()
- : base(@"Controls\TextBlock")
- {
- }
- [Win32Fact("Has text")]
- public async Task Should_Draw_TextDecorations()
- {
- Border target = new Border
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 30,
- Background = Brushes.White,
- Child = new TextBlock
- {
- FontFamily = TestFontFamily,
- FontSize = 12,
- Foreground = Brushes.Black,
- Text = "Neque porro quisquam est qui dolorem",
- VerticalAlignment = VerticalAlignment.Top,
- TextWrapping = TextWrapping.NoWrap,
- TextDecorations = new TextDecorationCollection
- {
- new TextDecoration
- {
- Location = TextDecorationLocation.Overline,
- StrokeThickness= 1.5,
- StrokeThicknessUnit = TextDecorationUnit.Pixel,
- Stroke = new SolidColorBrush(Colors.Red)
- },
- new TextDecoration
- {
- Location = TextDecorationLocation.Baseline,
- StrokeThickness= 1.5,
- StrokeThicknessUnit = TextDecorationUnit.Pixel,
- Stroke = new SolidColorBrush(Colors.Green)
- },
- new TextDecoration
- {
- Location = TextDecorationLocation.Underline,
- StrokeThickness= 1.5,
- StrokeThicknessUnit = TextDecorationUnit.Pixel,
- Stroke = new SolidColorBrush(Colors.Blue),
- StrokeOffset = 2,
- StrokeOffsetUnit = TextDecorationUnit.Pixel
- }
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Win32Fact("Has text")]
- public async Task Wrapping_NoWrap()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new TextBlock
- {
- FontFamily = new FontFamily("Courier New"),
- Background = Brushes.Red,
- FontSize = 12,
- Foreground = Brushes.Black,
- Text = "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit",
- VerticalAlignment = VerticalAlignment.Top,
- TextWrapping = TextWrapping.NoWrap,
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Win32Fact("Has text")]
- public async Task RestrictedHeight_VerticalAlign()
- {
- Control text(VerticalAlignment verticalAlignment, bool clip = true, bool restrictHeight = true)
- {
- return new Border()
- {
- BorderBrush = Brushes.Blue,
- BorderThickness = new Thickness(1),
- VerticalAlignment = VerticalAlignment.Center,
- HorizontalAlignment = HorizontalAlignment.Center,
- Height = restrictHeight ? 20 : double.NaN,
- Margin = new Thickness(1),
- Child = new TextBlock
- {
- FontFamily = new FontFamily("Courier New"),
- Background = Brushes.Red,
- FontSize = 24,
- Foreground = Brushes.Black,
- Text = "L",
- VerticalAlignment = verticalAlignment,
- ClipToBounds = clip
- }
- };
- }
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 190,
- Height = 80,
- Child = new StackPanel()
- {
- Orientation = Orientation.Horizontal,
- Children =
- {
- text(VerticalAlignment.Stretch, restrictHeight: false),
- text(VerticalAlignment.Center),
- text(VerticalAlignment.Stretch),
- text(VerticalAlignment.Top),
- text(VerticalAlignment.Bottom),
- text(VerticalAlignment.Center, clip:false),
- text(VerticalAlignment.Stretch, clip:false),
- text(VerticalAlignment.Top, clip:false),
- text(VerticalAlignment.Bottom, clip:false),
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Win32Fact("Has text")]
- public async Task Should_Draw_Run_With_Background()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 50,
- Child = new TextBlock
- {
- FontFamily = new FontFamily("Courier New"),
- FontSize = 12,
- Foreground = Brushes.Black,
- VerticalAlignment = VerticalAlignment.Top,
- TextWrapping = TextWrapping.NoWrap,
- Inlines = new InlineCollection
- {
- new Run
- {
- Text = "Neque porro quisquam",
- Background = Brushes.Red
- }
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- }
- }
|