Skip to content

Commit 852ea38

Browse files
Cleanup and update tests
1 parent e2e1efb commit 852ea38

57 files changed

Lines changed: 156 additions & 183 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageSharp.Drawing/Processing/Brushes.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,130 +93,131 @@ public static class Brushes
9393
/// </summary>
9494
/// <param name="color">The color.</param>
9595
/// <returns>A New <see cref="PatternBrush"/></returns>
96-
public static SolidBrush Solid(Color color) => new SolidBrush(color);
96+
public static SolidBrush Solid(Color color) => new(color);
9797

9898
/// <summary>
9999
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
100100
/// </summary>
101101
/// <param name="foreColor">Color of the foreground.</param>
102102
/// <returns>A New <see cref="PatternBrush"/></returns>
103-
public static PatternBrush Percent10(Color foreColor) =>
104-
new PatternBrush(foreColor, Color.Transparent, Percent10Pattern);
103+
public static PatternBrush Percent10(Color foreColor)
104+
=> new(foreColor, Color.Transparent, Percent10Pattern);
105105

106106
/// <summary>
107107
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
108108
/// </summary>
109109
/// <param name="foreColor">Color of the foreground.</param>
110110
/// <param name="backColor">Color of the background.</param>
111111
/// <returns>A New <see cref="PatternBrush"/></returns>
112-
public static PatternBrush Percent10(Color foreColor, Color backColor) =>
113-
new PatternBrush(foreColor, backColor, Percent10Pattern);
112+
public static PatternBrush Percent10(Color foreColor, Color backColor)
113+
=> new(foreColor, backColor, Percent10Pattern);
114114

115115
/// <summary>
116116
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a
117117
/// transparent background.
118118
/// </summary>
119119
/// <param name="foreColor">Color of the foreground.</param>
120120
/// <returns>A New <see cref="PatternBrush"/></returns>
121-
public static PatternBrush Percent20(Color foreColor) =>
122-
new PatternBrush(foreColor, Color.Transparent, Percent20Pattern);
121+
public static PatternBrush Percent20(Color foreColor)
122+
=> new(foreColor, Color.Transparent, Percent20Pattern);
123123

124124
/// <summary>
125125
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors
126126
/// </summary>
127127
/// <param name="foreColor">Color of the foreground.</param>
128128
/// <param name="backColor">Color of the background.</param>
129129
/// <returns>A New <see cref="PatternBrush"/></returns>
130-
public static PatternBrush Percent20(Color foreColor, Color backColor) =>
131-
new PatternBrush(foreColor, backColor, Percent20Pattern);
130+
public static PatternBrush Percent20(Color foreColor, Color backColor)
131+
=> new(foreColor, backColor, Percent20Pattern);
132132

133133
/// <summary>
134134
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a
135135
/// transparent background.
136136
/// </summary>
137137
/// <param name="foreColor">Color of the foreground.</param>
138138
/// <returns>A New <see cref="PatternBrush"/></returns>
139-
public static PatternBrush Horizontal(Color foreColor) =>
140-
new PatternBrush(foreColor, Color.Transparent, HorizontalPattern);
139+
public static PatternBrush Horizontal(Color foreColor)
140+
=> new(foreColor, Color.Transparent, HorizontalPattern);
141141

142142
/// <summary>
143143
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors
144144
/// </summary>
145145
/// <param name="foreColor">Color of the foreground.</param>
146146
/// <param name="backColor">Color of the background.</param>
147147
/// <returns>A New <see cref="PatternBrush"/></returns>
148-
public static PatternBrush Horizontal(Color foreColor, Color backColor) =>
149-
new PatternBrush(foreColor, backColor, HorizontalPattern);
148+
public static PatternBrush Horizontal(Color foreColor, Color backColor)
149+
=> new(foreColor, backColor, HorizontalPattern);
150150

151151
/// <summary>
152152
/// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a
153153
/// transparent background.
154154
/// </summary>
155155
/// <param name="foreColor">Color of the foreground.</param>
156156
/// <returns>A New <see cref="PatternBrush"/></returns>
157-
public static PatternBrush Min(Color foreColor) => new PatternBrush(foreColor, Color.Transparent, MinPattern);
157+
public static PatternBrush Min(Color foreColor)
158+
=> new(foreColor, Color.Transparent, MinPattern);
158159

159160
/// <summary>
160161
/// Create as brush that will paint a Min Hatch Pattern with the specified colors
161162
/// </summary>
162163
/// <param name="foreColor">Color of the foreground.</param>
163164
/// <param name="backColor">Color of the background.</param>
164165
/// <returns>A New <see cref="PatternBrush"/></returns>
165-
public static PatternBrush Min(Color foreColor, Color backColor) =>
166-
new PatternBrush(foreColor, backColor, MinPattern);
166+
public static PatternBrush Min(Color foreColor, Color backColor)
167+
=> new(foreColor, backColor, MinPattern);
167168

168169
/// <summary>
169170
/// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a
170171
/// transparent background.
171172
/// </summary>
172173
/// <param name="foreColor">Color of the foreground.</param>
173174
/// <returns>A New <see cref="PatternBrush"/></returns>
174-
public static PatternBrush Vertical(Color foreColor) =>
175-
new PatternBrush(foreColor, Color.Transparent, VerticalPattern);
175+
public static PatternBrush Vertical(Color foreColor)
176+
=> new(foreColor, Color.Transparent, VerticalPattern);
176177

177178
/// <summary>
178179
/// Create as brush that will paint a Vertical Hatch Pattern with the specified colors
179180
/// </summary>
180181
/// <param name="foreColor">Color of the foreground.</param>
181182
/// <param name="backColor">Color of the background.</param>
182183
/// <returns>A New <see cref="PatternBrush"/></returns>
183-
public static PatternBrush Vertical(Color foreColor, Color backColor) =>
184-
new PatternBrush(foreColor, backColor, VerticalPattern);
184+
public static PatternBrush Vertical(Color foreColor, Color backColor)
185+
=> new(foreColor, backColor, VerticalPattern);
185186

186187
/// <summary>
187188
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a
188189
/// transparent background.
189190
/// </summary>
190191
/// <param name="foreColor">Color of the foreground.</param>
191192
/// <returns>A New <see cref="PatternBrush"/></returns>
192-
public static PatternBrush ForwardDiagonal(Color foreColor) =>
193-
new PatternBrush(foreColor, Color.Transparent, ForwardDiagonalPattern);
193+
public static PatternBrush ForwardDiagonal(Color foreColor)
194+
=> new(foreColor, Color.Transparent, ForwardDiagonalPattern);
194195

195196
/// <summary>
196197
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors
197198
/// </summary>
198199
/// <param name="foreColor">Color of the foreground.</param>
199200
/// <param name="backColor">Color of the background.</param>
200201
/// <returns>A New <see cref="PatternBrush"/></returns>
201-
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) =>
202-
new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
202+
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor)
203+
=> new(foreColor, backColor, ForwardDiagonalPattern);
203204

204205
/// <summary>
205206
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a
206207
/// transparent background.
207208
/// </summary>
208209
/// <param name="foreColor">Color of the foreground.</param>
209210
/// <returns>A New <see cref="PatternBrush"/></returns>
210-
public static PatternBrush BackwardDiagonal(Color foreColor) =>
211-
new PatternBrush(foreColor, Color.Transparent, BackwardDiagonalPattern);
211+
public static PatternBrush BackwardDiagonal(Color foreColor)
212+
=> new(foreColor, Color.Transparent, BackwardDiagonalPattern);
212213

213214
/// <summary>
214215
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors
215216
/// </summary>
216217
/// <param name="foreColor">Color of the foreground.</param>
217218
/// <param name="backColor">Color of the background.</param>
218219
/// <returns>A New <see cref="PatternBrush"/></returns>
219-
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) =>
220-
new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
220+
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor)
221+
=> new(foreColor, backColor, BackwardDiagonalPattern);
221222
}
222223
}

src/ImageSharp.Drawing/Processing/PatternPen.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ namespace SixLabors.ImageSharp.Drawing.Processing
77
/// Defines a pen that can apply a pattern to a line with a set brush and thickness
88
/// </summary>
99
/// <remarks>
10-
/// The pattern will be in to the form of <code>new float[]{ 1f, 2f, 0.5f}</code> this will be
11-
/// converted into a pattern that is 3.5 times longer that the width with 3 sections.
10+
/// The pattern will be in to the form of
11+
/// <code>
12+
/// new float[]{ 1f, 2f, 0.5f}
13+
/// </code>
14+
/// this will be converted into a pattern that is 3.5 times longer that the width with 3 sections.
1215
/// <list type="bullet">
1316
/// <item>Section 1 will be width long (making a square) and will be filled by the brush.</item>
1417
/// <item>Section 2 will be width * 2 long and will be empty.</item>

src/ImageSharp.Drawing/Processing/Pen.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
namespace SixLabors.ImageSharp.Drawing.Processing
77
{
88
/// <summary>
9-
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
9+
/// The base class for pens that can apply a pattern to a line with a set brush and thickness
1010
/// </summary>
1111
/// <remarks>
12-
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
13-
/// converted into a pattern that is 3.5 times longer that the width with 3 sections
14-
/// section 1 will be width long (making a square) and will be filled by the brush
15-
/// section 2 will be width * 2 long and will be empty
16-
/// section 3 will be width/2 long and will be filled
17-
/// the pattern will immediately repeat without gap.
12+
/// The pattern will be in to the form of
13+
/// <code>
14+
/// new float[]{ 1f, 2f, 0.5f}
15+
/// </code>
16+
/// this will be converted into a pattern that is 3.5 times longer that the width with 3 sections.
17+
/// <list type="bullet">
18+
/// <item>Section 1 will be width long (making a square) and will be filled by the brush.</item>
19+
/// <item>Section 2 will be width * 2 long and will be empty.</item>
20+
/// <item>ection 3 will be width/2 long and will be filled.</item>
21+
/// </list>
22+
/// The pattern will immediately repeat without gap.
1823
/// </remarks>
1924
public abstract class Pen : IEquatable<Pen>
2025
{

src/ImageSharp.Drawing/Processing/Processors/Text/ImageProcessorExtensions.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/ImageSharp.Drawing.Tests/Shapes/Scan/RasterizerExtensionsTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5-
using System.Collections.Generic;
6-
using System.Text;
75
using SixLabors.Fonts;
86
using SixLabors.ImageSharp.Drawing.Processing;
97
using SixLabors.ImageSharp.Drawing.Shapes.Rasterization;
108
using SixLabors.ImageSharp.Drawing.Tests.TestUtilities.ImageComparison;
119
using SixLabors.ImageSharp.Memory;
1210
using SixLabors.ImageSharp.PixelFormats;
13-
using SixLabors.ImageSharp.Processing;
1411
using Xunit;
1512

1613
namespace SixLabors.ImageSharp.Drawing.Tests.Shapes.Scan

tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Numerics;
55
using SixLabors.Fonts;
6-
using SixLabors.ImageSharp.Drawing.Processing;
76
using Xunit;
87

98
namespace SixLabors.ImageSharp.Drawing.Tests.Shapes
@@ -14,12 +13,12 @@ public class TextBuilderTests
1413
public void TextBuilder_Bounds_AreCorrect()
1514
{
1615
Vector2 position = new(5, 5);
17-
var options = new RichTextOptions(TestFontUtilities.GetFont(TestFonts.OpenSans, 16))
16+
var options = new TextOptions(TestFontUtilities.GetFont(TestFonts.OpenSans, 16))
1817
{
1918
Origin = position
2019
};
2120

22-
const string text = "Hello World";
21+
const string text = "The quick brown fox jumps over the lazy fox";
2322

2423
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, options);
2524

@@ -30,7 +29,11 @@ public void TextBuilder_Bounds_AreCorrect()
3029
Assert.Equal(measuredBounds.X, builderBounds.X);
3130
Assert.Equal(measuredBounds.Y, builderBounds.Y);
3231
Assert.Equal(measuredBounds.Width, builderBounds.Width);
33-
Assert.Equal(measuredBounds.Height, builderBounds.Height);
32+
33+
// TextMeasurer will measure the full lineheight of the string.
34+
// TextBuilder does not include line gaps following the descender since there
35+
// is no path to include.
36+
Assert.True(measuredBounds.Height >= builderBounds.Height);
3437
}
3538
}
3639
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)