Skip to content

Commit 934ccdf

Browse files
Add regression test
1 parent 31fdceb commit 934ccdf

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,51 @@ public void FontShapesAreRenderedCorrectly_LargeText<TPixel>(
201201
comparer,
202202
img => img.Mutate(c => c.DrawText(textOptions, sb.ToString(), font, color, new PointF(10, 1))),
203203
false,
204+
true);
205+
}
206+
207+
[Theory]
208+
[WithSolidFilledImages(400, 600, "White", PixelTypes.Rgba32, 1, 5)]
209+
[WithSolidFilledImages(400, 600, "White", PixelTypes.Rgba32, 1.5, 3)]
210+
[WithSolidFilledImages(400, 600, "White", PixelTypes.Rgba32, 2, 2)]
211+
public void FontShapesAreRenderedCorrectly_WithLineSpacing<TPixel>(
212+
TestImageProvider<TPixel> provider,
213+
float lineSpacing,
214+
int lineCount)
215+
where TPixel : unmanaged, IPixel<TPixel>
216+
{
217+
Font font = CreateFont("OpenSans-Regular.ttf", 16);
218+
219+
var sb = new StringBuilder();
220+
string str = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.";
221+
222+
for (int i = 0; i < lineCount; i++)
223+
{
224+
sb.AppendLine(str);
225+
}
226+
227+
var textOptions = new TextGraphicsOptions
228+
{
229+
TextOptions =
230+
{
231+
ApplyKerning = true,
232+
VerticalAlignment = VerticalAlignment.Top,
233+
HorizontalAlignment = HorizontalAlignment.Left,
234+
LineSpacing = lineSpacing,
235+
WrapTextWidth = 300
236+
}
237+
};
238+
239+
Color color = Color.Black;
240+
241+
// Strict comparer, because the image is sparse:
242+
var comparer = ImageComparer.TolerantPercentage(1e-6f);
243+
244+
provider.VerifyOperation(
245+
comparer,
246+
img => img.Mutate(c => c.DrawText(textOptions, sb.ToString(), font, color, new PointF(10, 1))),
247+
$"linespacing_{lineSpacing}_linecount_{lineCount}",
248+
false,
204249
false);
205250
}
206251

Loading
Loading
Loading

0 commit comments

Comments
 (0)