Skip to content

Commit bb5904a

Browse files
Add/Update tests
1 parent aca4e24 commit bb5904a

13 files changed

Lines changed: 74 additions & 18 deletions

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,57 @@ public void CanDrawTextAlongPathVertical<TPixel>(TestImageProvider<TPixel> provi
734734
comparer: ImageComparer.TolerantPercentage(0.002f));
735735
}
736736

737+
[Theory]
738+
[WithSolidFilledImages(1000, 1000, "White", PixelTypes.Rgba32)]
739+
public void PathAndTextDrawingMatch<TPixel>(TestImageProvider<TPixel> provider)
740+
where TPixel : unmanaged, IPixel<TPixel>
741+
{
742+
// https://github.com/SixLabors/ImageSharp.Drawing/issues/234
743+
Font font = CreateFont(TestFonts.NettoOffc, 300);
744+
const string text = "all";
745+
746+
provider.VerifyOperation(
747+
TextDrawingComparer,
748+
img =>
749+
{
750+
foreach (HorizontalAlignment ha in (HorizontalAlignment[])Enum.GetValues(typeof(HorizontalAlignment)))
751+
{
752+
foreach (VerticalAlignment va in (VerticalAlignment[])Enum.GetValues(typeof(VerticalAlignment)))
753+
{
754+
TextOptions to = new(font)
755+
{
756+
HorizontalAlignment = ha,
757+
VerticalAlignment = va,
758+
};
759+
760+
FontRectangle bounds = TextMeasurer.MeasureBounds(text, to);
761+
float x = (img.Size().Width - bounds.Width) / 2;
762+
PointF[] pathLine = new[]
763+
{
764+
new PointF(x, 500),
765+
new PointF(x + bounds.Width, 500)
766+
};
767+
768+
IPath path = new PathBuilder().AddLine(pathLine[0], pathLine[1]).Build();
769+
770+
RichTextOptions rto = new(font)
771+
{
772+
Origin = pathLine[0],
773+
HorizontalAlignment = ha,
774+
VerticalAlignment = va,
775+
};
776+
777+
IPathCollection tb = TextBuilder.GenerateGlyphs(text, path, to);
778+
779+
img.Mutate(
780+
i => i.DrawLine(new SolidPen(Color.Red, 30), pathLine)
781+
.DrawText(rto, text, Color.Black)
782+
.Fill(Brushes.ForwardDiagonal(Color.HotPink), tb));
783+
}
784+
}
785+
});
786+
}
787+
737788
private static string Repeat(string str, int times) => string.Concat(Enumerable.Repeat(str, times));
738789

739790
private static string ToTestOutputDisplayText(string text)

tests/ImageSharp.Drawing.Tests/TestFonts.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ public static class TestFonts
2020
public const string WhitneyBook = "whitney-book.ttf";
2121

2222
public const string MeQuranVolyNewmet = "me_quran_volt_newmet.ttf";
23+
24+
public const string NettoOffc = "NettoOffc.ttf";
2325
}
2426
}
87.7 KB
Binary file not shown.

tests/ImageSharp.Drawing.Tests/TestUtilities/ImagingTestCaseUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public string SaveTestOutputFile(
176176

177177
encoder ??= TestEnvironment.GetReferenceEncoder(path);
178178

179-
using (FileStream stream = File.OpenWrite(path))
179+
using (FileStream stream = File.Open(path, FileMode.Create))
180180
{
181181
image.Save(stream, encoder);
182182
}
@@ -226,7 +226,7 @@ public string[] SaveTestOutputFileMultiFrame<TPixel>(
226226
using (Image<TPixel> frameImage = image.Frames.CloneFrame(i))
227227
{
228228
string filePath = files[i];
229-
using (FileStream stream = File.OpenWrite(filePath))
229+
using (FileStream stream = File.Open(filePath, FileMode.Create))
230230
{
231231
frameImage.Save(stream, encoder);
232232
}
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)