From 121f1edce6c5d10317fb6888c1aa1f78f0144035 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Thu, 14 Jun 2018 22:11:05 +0100 Subject: [PATCH] ensure pen code path is tested --- .../Text/Processors/DrawTextProcessor.cs | 2 +- .../Drawing/Text/DrawTextOnImageTests.cs | 30 +++++++++++++++++++ tests/Images/External | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs b/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs index b029ff516a..8d51f4f442 100644 --- a/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Processing.Text.Processors { this.fillRegionProcessor = new FillRegionProcessor() { - Brush = this.Brush, + Brush = this.Pen.StrokeFill, Options = pathOptions }; } diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs index f90d5996e3..5440eb8db3 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs @@ -18,6 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text using System.Linq; using System.Text; using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes; + using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; [GroupOutput("Drawing/Text")] @@ -101,6 +102,35 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text false); } + [Theory] + [WithSolidFilledImages(200, 100, "White", PixelTypes.Rgba32, 50, 0, 0, "SixLaborsSampleAB.woff", AB)] + [WithSolidFilledImages(900, 100, "White", PixelTypes.Rgba32, 50, 0, 0, "OpenSans-Regular.ttf", TestText)] + [WithSolidFilledImages(400, 40, "White", PixelTypes.Rgba32, 20, 0, 0, "OpenSans-Regular.ttf", TestText)] + [WithSolidFilledImages(1100, 200, "White", PixelTypes.Rgba32, 50, 150, 100, "OpenSans-Regular.ttf", TestText)] + public void FontShapesAreRenderedCorrectlyWithAPen( + TestImageProvider provider, + int fontSize, + int x, + int y, + string fontName, + 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 color = NamedColors.Black; + + provider.VerifyOperation( + img => + { + img.Mutate(c => c.DrawText(text, new Font(font, fontSize),null, Pens.Solid(color, 1), new PointF(x, y))); + }, + $"pen_{fontName}-{fontSize}-{fnDisplayText}-({x},{y})", + appendPixelTypeToFileName: false, + appendSourceFileOrDescription: true); + } + private static string Repeat(string str, int times) => string.Concat(Enumerable.Repeat(str, times)); private static Font CreateFont(string fontName, int size) diff --git a/tests/Images/External b/tests/Images/External index 443db93ffd..07cdbcfca1 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 443db93ffdb175dd0ef67eb8f0c525cc9ad59083 +Subproject commit 07cdbcfca121081eae97d6a9cd0e230c653eeb39