diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs index a1a9b0222..6922213f2 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs @@ -150,8 +150,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text where TPixel : struct, IPixel { Font font = CreateFont(fontName, fontSize); - string fnDisplayText = text.Replace("\n", ""); - fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4)); TPixel color = NamedColors.Black; provider.VerifyOperation( @@ -160,15 +158,14 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { img.Mutate(c => c.DrawText(text, new Font(font, fontSize), null, Pens.DashDot(color, 3), new PointF(x, y))); }, - $"pen_{fontName}-{fontSize}-{fnDisplayText}-({x},{y})", + $"pen_{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})", appendPixelTypeToFileName: false, appendSourceFileOrDescription: true); } - [Theory] [WithSolidFilledImages(200, 100, "White", PixelTypes.Rgba32, 50, "SixLaborsSampleAB.woff", AB)] - [WithSolidFilledImages(900, 100, "White", PixelTypes.Rgba32, 50, "OpenSans-Regular.ttf", TestText)] + [WithSolidFilledImages(900, 100, "White", PixelTypes.Rgba32, 50, "OpenSans-Regular.ttf", TestText)] public void FontShapesAreRenderedCorrectlyAlongAPath( TestImageProvider provider, int fontSize, @@ -176,36 +173,88 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text string text) where TPixel : struct, IPixel { - Font font = CreateFont(fontName, fontSize); - string fnDisplayText = text.Replace("\n", ""); - fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4)); - TPixel colorOutline = NamedColors.Black; TPixel colorFill = NamedColors.Gray; + TPixel colorOutline = NamedColors.Black; + IBrush fillBrush = Brushes.Solid(colorFill); + IPen outlinePen = Pens.DashDot(colorOutline, 3); + provider.VerifyOperation( + ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), + img => + { + IPath path = new Path(new LinearLineSegment(new Point(0, img.Height), new Point(img.Width, 0))); + img.Mutate( + c => + { + c.DrawText( + new TextGraphicsOptions + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Top + }, + text, + new Font(font, fontSize), + fillBrush, + outlinePen, + path); + }); + }, + $"pen_{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}", + appendPixelTypeToFileName: false, + appendSourceFileOrDescription: true); + } + + [Theory] + [WithSolidFilledImages(600, 600, "White", PixelTypes.Rgba32, 50, "OpenSans-Regular.ttf", TestText)] + public void FontShapesAreRenderedCorrectlyAlongACirclePath( + TestImageProvider provider, + int fontSize, + string fontName, + string text) + where TPixel : struct, IPixel + { + + Font font = CreateFont(fontName, fontSize); + TPixel colorFill = NamedColors.Black; + IBrush fillBrush = Brushes.Solid(colorFill); + provider.VerifyOperation( ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), img => { + int w = (int)(img.Width * 0.6); + int h = (int)(img.Height * 0.6); + IPath path = new EllipsePolygon(img.Width/2, img.Height/2, w, h); - IPath path = new Path(new LinearLineSegment(new Point(0, img.Height), new Point(img.Width, 0))); - img.Mutate(c => c.DrawText( - new TextGraphicsOptions { - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Top - } , - text, new Font(font, fontSize), - Brushes.Solid(colorFill) - , Pens.DashDot(colorOutline, 3), - path)); + img.Mutate(c => + { + c.DrawText( + new TextGraphicsOptions + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Top + }, + text, + new Font(font, fontSize), + fillBrush, + path); + }); }, - $"pen_{fontName}-{fontSize}-{fnDisplayText}", + $"pen_{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}", appendPixelTypeToFileName: false, appendSourceFileOrDescription: true); } private static string Repeat(string str, int times) => string.Concat(Enumerable.Repeat(str, times)); + private static string ToTestOutputDisplayText(string text) + { + string fnDisplayText = text.Replace("\n", ""); + fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4)); + return fnDisplayText; + } + private static Font CreateFont(string fontName, int size) { var fontCollection = new FontCollection();