51 lines
1.9 KiB
C#
51 lines
1.9 KiB
C#
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using MaddoShared.ImageSharpTests.Helpers;
|
|
using Shouldly;
|
|
|
|
namespace MaddoShared.ImageSharpTests.Tests
|
|
{
|
|
[TestClass]
|
|
public class TextPositioningTests
|
|
{
|
|
[TestMethod]
|
|
public async Task TextAtBottom_IncreasesNonBackgroundPixelCountInBottomBand()
|
|
{
|
|
using var ws = new TempWorkspace();
|
|
|
|
// create white background input
|
|
var inputPath = TestImageFactory.CreateSolidJpeg(ws.SourceDir.FullName, "input.jpg", 800, 600, new Rgba32(255, 255, 255, 255));
|
|
|
|
var pic = CreatorFactory.CreateDefaultPicSettings();
|
|
pic.Posizione = "BASSO";
|
|
pic.DimStandard = 48; // big text
|
|
pic.TestoFirmaStart = "SAMPLE TEXT";
|
|
pic.CreaMiniature = false;
|
|
|
|
var svc = CreatorFactory.CreateImageCreator(pic);
|
|
|
|
var state = new MaddoShared.ImageState
|
|
{
|
|
WorkFile = new FileInfo(inputPath),
|
|
DestDir = ws.DestDir,
|
|
SourceDir = ws.SourceDir
|
|
};
|
|
|
|
await svc.CreateImageAsync(state, null);
|
|
|
|
var outPath = Path.Combine(ws.DestDir.FullName, state.NomeFileBig);
|
|
|
|
// bottom band (lower 25% of image)
|
|
var bottomY = (int)(600 * 0.75);
|
|
var bottomCount = PixelInspector.CountNonBackgroundPixels(outPath, 0, bottomY, 800, 600 - bottomY, new Rgba32(255, 255, 255, 255), tolerance: 10);
|
|
|
|
// top band (upper 25%)
|
|
var topCount = PixelInspector.CountNonBackgroundPixels(outPath, 0, 0, 800, (int)(600 * 0.25), new Rgba32(255, 255, 255, 255), tolerance: 10);
|
|
|
|
(bottomCount > 50).ShouldBeTrue($"Expected text pixels in bottom band, found {bottomCount}");
|
|
(bottomCount > topCount).ShouldBeTrue("Expected more non-background pixels at bottom than top");
|
|
}
|
|
}
|
|
}
|