PathTests.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Perspex.Controls;
  4. using Perspex.Controls.Shapes;
  5. using Perspex.Layout;
  6. using Perspex.Media;
  7. using Xunit;
  8. #if PERSPEX_CAIRO
  9. namespace Perspex.Cairo.RenderTests.Shapes
  10. #elif PERSPEX_SKIA
  11. namespace Perspex.Skia.RenderTests
  12. #else
  13. namespace Perspex.Direct2D1.RenderTests.Shapes
  14. #endif
  15. {
  16. using Perspex.Collections;
  17. public class PathTests : TestBase
  18. {
  19. public PathTests()
  20. : base(@"Shapes\Path")
  21. {
  22. }
  23. [Fact]
  24. public void Path_100px_Triangle_Centered()
  25. {
  26. Decorator target = new Decorator
  27. {
  28. Width = 200,
  29. Height = 200,
  30. Child = new Path
  31. {
  32. Fill = Brushes.Gray,
  33. Stroke = Brushes.Red,
  34. StrokeThickness = 2,
  35. HorizontalAlignment = HorizontalAlignment.Center,
  36. VerticalAlignment = VerticalAlignment.Center,
  37. Data = StreamGeometry.Parse("M 0,100 L 100,100 50,0 Z"),
  38. }
  39. };
  40. RenderToFile(target);
  41. CompareImages();
  42. }
  43. [Fact]
  44. public void Path_Tick_Scaled()
  45. {
  46. Decorator target = new Decorator
  47. {
  48. Width = 200,
  49. Height = 200,
  50. Child = new Path
  51. {
  52. Fill = Brushes.Gray,
  53. Stroke = Brushes.Red,
  54. StrokeThickness = 2,
  55. Stretch = Stretch.Uniform,
  56. HorizontalAlignment = HorizontalAlignment.Center,
  57. VerticalAlignment = VerticalAlignment.Center,
  58. 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"),
  59. }
  60. };
  61. RenderToFile(target);
  62. CompareImages();
  63. }
  64. [Fact]
  65. public void Path_Tick_Scaled_Stroke_8px()
  66. {
  67. Decorator target = new Decorator
  68. {
  69. Width = 200,
  70. Height = 200,
  71. Child = new Path
  72. {
  73. Fill = Brushes.Gray,
  74. Stroke = Brushes.Red,
  75. StrokeThickness = 8,
  76. Stretch = Stretch.Uniform,
  77. HorizontalAlignment = HorizontalAlignment.Center,
  78. VerticalAlignment = VerticalAlignment.Center,
  79. 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"),
  80. }
  81. };
  82. RenderToFile(target);
  83. CompareImages();
  84. }
  85. [Fact]
  86. public void Path_Expander_With_Border()
  87. {
  88. Decorator target = new Decorator
  89. {
  90. Width = 200,
  91. Height = 200,
  92. Child = new Border
  93. {
  94. BorderBrush = Brushes.Red,
  95. BorderThickness = 1,
  96. HorizontalAlignment = HorizontalAlignment.Center,
  97. VerticalAlignment = VerticalAlignment.Center,
  98. Child = new Path
  99. {
  100. Fill = Brushes.Black,
  101. Stroke = Brushes.Black,
  102. StrokeThickness = 1,
  103. Stretch = Stretch.Uniform,
  104. Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
  105. }
  106. }
  107. };
  108. RenderToFile(target);
  109. CompareImages();
  110. }
  111. #if PERSPEX_CAIRO
  112. [Fact(Skip = "Path with StrokeDashCap, StrokeStartLineCap, StrokeEndLineCap rendering is not implemented in Cairo yet")]
  113. #elif PERSPEX_SKIA
  114. [Fact(Skip = "FIXME")]
  115. #else
  116. [Fact]
  117. #endif
  118. public void Path_With_PenLineCap()
  119. {
  120. Decorator target = new Decorator
  121. {
  122. Width = 200,
  123. Height = 200,
  124. Child = new Path
  125. {
  126. Stroke = Brushes.Black,
  127. StrokeThickness = 10,
  128. HorizontalAlignment = HorizontalAlignment.Center,
  129. VerticalAlignment = VerticalAlignment.Center,
  130. StrokeDashCap = PenLineCap.Triangle,
  131. StrokeDashArray = new PerspexList<double>(3, 1),
  132. StrokeStartLineCap = PenLineCap.Round,
  133. StrokeEndLineCap = PenLineCap.Square,
  134. Data = StreamGeometry.Parse("M 20,20 L 180,180"),
  135. }
  136. };
  137. RenderToFile(target);
  138. CompareImages();
  139. }
  140. }
  141. }