Browse Source

update submodule, fine-tune test tolerance

pull/614/head
Anton Firszov 8 years ago
parent
commit
1babb6a8b2
  1. 23
      tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs
  2. 2
      tests/Images/External

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

@ -34,6 +34,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
private const string TestText2 = private const string TestText2 =
"THISISTESTWORDS "; "THISISTESTWORDS ";
public static ImageComparer TextDrawingComparer = ImageComparer.TolerantPercentage(0.01f);
[Theory] [Theory]
[WithSolidFilledImages(200, 100, "White", PixelTypes.Rgba32, 50, 0, 0, "SixLaborsSampleAB.woff", AB)] [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(900, 100, "White", PixelTypes.Rgba32, 50, 0, 0, "OpenSans-Regular.ttf", TestText)]
@ -49,17 +51,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
Font font = CreateFont(fontName, fontSize); Font font = CreateFont(fontName, fontSize);
string fnDisplayText = text.Replace("\n", "");
fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4));
TPixel color = NamedColors<TPixel>.Black; TPixel color = NamedColors<TPixel>.Black;
provider.VerifyOperation( provider.VerifyOperation(
ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), TextDrawingComparer,
img => img =>
{ {
img.Mutate(c => c.DrawText(text, new Font(font, fontSize), color, new PointF(x, y))); img.Mutate(c => c.DrawText(text, new Font(font, fontSize), color, new PointF(x, y)));
}, },
$"{fontName}-{fontSize}-{fnDisplayText}-({x},{y})", $"{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})",
appendPixelTypeToFileName: false, appendPixelTypeToFileName: false,
appendSourceFileOrDescription: true); appendSourceFileOrDescription: true);
} }
@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
TPixel color = NamedColors<TPixel>.Black; TPixel color = NamedColors<TPixel>.Black;
provider.VerifyOperation( provider.VerifyOperation(
ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), TextDrawingComparer,
img => img =>
{ {
img.Mutate(c => c.DrawText(textOptions, sb.ToString(), font, color, new PointF(10, 5))); img.Mutate(c => c.DrawText(textOptions, sb.ToString(), font, color, new PointF(10, 5)));
@ -121,17 +121,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
Font font = CreateFont(fontName, fontSize); Font font = CreateFont(fontName, fontSize);
string fnDisplayText = text.Replace("\n", "");
fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4));
TPixel color = NamedColors<TPixel>.Black; TPixel color = NamedColors<TPixel>.Black;
provider.VerifyOperation( provider.VerifyOperation(
ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), TextDrawingComparer,
img => img =>
{ {
img.Mutate(c => c.DrawText(text, new Font(font, fontSize), null, Pens.Solid(color, 1), new PointF(x, y))); 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})", $"pen_{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})",
appendPixelTypeToFileName: false, appendPixelTypeToFileName: false,
appendSourceFileOrDescription: true); appendSourceFileOrDescription: true);
} }
@ -153,7 +151,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
TPixel color = NamedColors<TPixel>.Black; TPixel color = NamedColors<TPixel>.Black;
provider.VerifyOperation( provider.VerifyOperation(
ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), TextDrawingComparer,
img => img =>
{ {
img.Mutate(c => c.DrawText(text, new Font(font, fontSize), null, Pens.DashDot(color, 3), new PointF(x, y))); img.Mutate(c => c.DrawText(text, new Font(font, fontSize), null, Pens.DashDot(color, 3), new PointF(x, y)));
@ -180,7 +178,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
IPen<TPixel> outlinePen = Pens.DashDot(colorOutline, 3); IPen<TPixel> outlinePen = Pens.DashDot(colorOutline, 3);
provider.VerifyOperation( provider.VerifyOperation(
ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), TextDrawingComparer,
img => img =>
{ {
IPath path = new Path(new LinearLineSegment(new Point(0, img.Height), new Point(img.Width, 0))); IPath path = new Path(new LinearLineSegment(new Point(0, img.Height), new Point(img.Width, 0)));
@ -214,13 +212,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
string text) string text)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
Font font = CreateFont(fontName, fontSize); Font font = CreateFont(fontName, fontSize);
TPixel colorFill = NamedColors<TPixel>.Black; TPixel colorFill = NamedColors<TPixel>.Black;
IBrush<TPixel> fillBrush = Brushes.Solid(colorFill); IBrush<TPixel> fillBrush = Brushes.Solid(colorFill);
provider.VerifyOperation( provider.VerifyOperation(
ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20), TextDrawingComparer,
img => img =>
{ {
int w = (int)(img.Width * 0.6); int w = (int)(img.Width * 0.6);

2
tests/Images/External

@ -1 +1 @@
Subproject commit 83f6cbab9a08b550c84bf931c95188341140516a Subproject commit 0e6407be7081341526f815a4d70e7912db276a98
Loading…
Cancel
Save