Skip to content

Commit 7064b37

Browse files
Fix #270
1 parent 7677cfa commit 7064b37

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/ImageSharp.Drawing/Processing/ImageBrush.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public ImageBrushApplicator(
137137
get
138138
{
139139
int srcX = ((x - this.offsetX) % this.sourceRegion.Width) + this.sourceRegion.X;
140-
int srcY = ((y - this.offsetY) % this.sourceRegion.Width) + this.sourceRegion.Y;
140+
int srcY = ((y - this.offsetY) % this.sourceRegion.Height) + this.sourceRegion.Y;
141141
return this.sourceFrame[srcX, srcY];
142142
}
143143
}

src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void Draw(IEnumerable<DrawingOperation> operations)
7070
int startX = operation.RenderLocation.X;
7171
int offsetSpan = 0;
7272

73-
if (startX + buffer.Height < 0)
73+
if (startY + buffer.Height < 0)
7474
{
7575
continue;
7676
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Numerics;
5+
using SixLabors.Fonts;
6+
using SixLabors.ImageSharp.Drawing.Processing;
7+
using SixLabors.ImageSharp.PixelFormats;
8+
using SixLabors.ImageSharp.Processing;
9+
using Xunit;
10+
11+
namespace SixLabors.ImageSharp.Drawing.Tests.Issues
12+
{
13+
public class Issue_270
14+
{
15+
[Fact]
16+
public void DoesNotThrowArgumentOutOfRangeException()
17+
{
18+
const int sourceImageWidth = 256;
19+
const int sourceImageHeight = 256;
20+
const int targetImageWidth = 350;
21+
const int targetImageHeight = 350;
22+
const float minimumCrashingFontSize = 47;
23+
const string text = "Hello, World!";
24+
25+
Font font = SystemFonts.CreateFont("Arial", minimumCrashingFontSize);
26+
Pen pen = Pens.Solid(Color.Black, 1);
27+
28+
using Image<Rgba32> targetImage = new(targetImageWidth, targetImageHeight, Color.Wheat);
29+
using Image<Rgba32> imageBrushImage = new(sourceImageWidth, sourceImageHeight, Color.Black);
30+
ImageBrush imageBrush = new(imageBrushImage);
31+
32+
targetImage.Mutate(x => x.DrawText(CreateTextOptions(font, targetImageWidth), text, imageBrush, pen));
33+
}
34+
35+
private static RichTextOptions CreateTextOptions(Font font, int wrappingLength)
36+
=> new(font)
37+
{
38+
Origin = new Vector2(175, 175),
39+
TextAlignment = TextAlignment.Center,
40+
LayoutMode = LayoutMode.HorizontalTopBottom,
41+
WrappingLength = wrappingLength,
42+
WordBreaking = WordBreaking.Standard,
43+
HorizontalAlignment = HorizontalAlignment.Center,
44+
VerticalAlignment = VerticalAlignment.Center,
45+
KerningMode = KerningMode.None,
46+
};
47+
}
48+
}

0 commit comments

Comments
 (0)