@ -11,6 +11,8 @@ using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives ;
using Xunit ;
using Xunit.Abstractions ;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Drawing.Text
@ -25,6 +27,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
public static ImageComparer TextDrawingComparer = ImageComparer . TolerantPercentage ( 1e-5f ) ;
public static ImageComparer OutlinedTextDrawingComparer = ImageComparer . TolerantPercentage ( 1e-4f ) ;
public DrawTextOnImageTests ( ITestOutputHelper output )
{
this . Output = output ;
}
private ITestOutputHelper Output { get ; }
[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)]
@ -87,8 +96,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
TPixel color = NamedColors < TPixel > . Black ;
// Based on the reported 0.0270% difference with AccuracyMultiple = 8
// We should avoid quality regressions leading to higher difference!
var comparer = ImageComparer . TolerantPercentage ( 0.03f ) ;
provider . VerifyOperation (
TextDrawingComparer ,
c omparer,
img = >
{
img . Mutate ( c = > c . DrawText ( textOptions , sb . ToString ( ) , font , color , new PointF ( 1 0 , 5 ) ) ) ;
@ -152,8 +165,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
}
[Theory]
[WithSolidFilledImages(1000, 1500, "White", PixelTypes.Rgba32)]
public static void TextPositioningIsRobust < TPixel > ( TestImageProvider < TPixel > provider )
[WithSolidFilledImages(1000, 1500, "White", PixelTypes.Rgba32, "Baskerville Old Face")]
[WithSolidFilledImages(1000, 1500, "White", PixelTypes.Rgba32, "Arial")]
public void TextPositioningIsRobust < TPixel > ( TestImageProvider < TPixel > provider , string fontName )
where TPixel : struct , IPixel < TPixel >
{
if ( ! TestEnvironment . IsWindows )
@ -162,14 +176,24 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
return ;
}
Font font = SystemFonts . CreateFont ( "Baskerville Old Face" , 3 0 , FontStyle . Regular ) ;
Font font = SystemFonts . CreateFont ( fontName , 3 0 , FontStyle . Regular ) ;
string text = Repeat ( "Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!\n" ,
2 0 ) ;
var textOptions = new TextGraphicsOptions ( true ) { WrapTextWidth = 1 0 0 0 } ;
string details = fontName . Replace ( " " , "" ) ;
// Based on the reported 0.1755% difference with AccuracyMultiple = 8
// We should avoid quality regressions leading to higher difference!
var comparer = ImageComparer . TolerantPercentage ( 0.2f ) ;
provider . RunValidatingProcessorTest (
x = > x . DrawText ( textOptions , text , font , NamedColors < TPixel > . Black , new PointF ( 1 0 , 5 0 ) ) , appendPixelTypeToFileName : false , appendSourceFileOrDescription : false ) ;
x = > x . DrawText ( textOptions , text , font , NamedColors < TPixel > . Black , new PointF ( 1 0 , 5 0 ) ) ,
details ,
comparer ,
appendPixelTypeToFileName : false ,
appendSourceFileOrDescription : false ) ;
}
private static string Repeat ( string str , int times ) = > string . Concat ( Enumerable . Repeat ( str , times ) ) ;