Browse Source

Merge branch 'master' into dl/remove-duplicate

af/merge-core
Anton Firsov 7 years ago
committed by GitHub
parent
commit
50db9deb7b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs
  2. 2
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  3. 35
      tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs
  4. 2
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj

12
src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs

@ -89,7 +89,17 @@ namespace SixLabors.ImageSharp.Processing
/// <inheritdoc />
internal override void Apply(Span<float> scanline, int x, int y)
{
Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x);
// constrain the spans to eachother
if (destinationRow.Length > scanline.Length)
{
destinationRow = destinationRow.Slice(0, scanline.Length);
}
else
{
scanline = scanline.Slice(0, destinationRow.Length);
}
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
Configuration configuration = this.Target.Configuration;

2
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -19,7 +19,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="BitMiracle.LibJpeg.NET" Version="1.4.280" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.5.0" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.9.0.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="Moq" Version="4.8.3" />
<!--<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />-->

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

@ -25,6 +25,41 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
public static ImageComparer TextDrawingComparer = ImageComparer.TolerantPercentage(0.01f);
public static ImageComparer OutlinedTextDrawingComparer = ImageComparer.TolerantPercentage(0.5f, 3);
[Theory]
[WithSolidFilledImages(276, 336, "White", PixelTypes.Rgba32)]
public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
Font font = CreateFont("OpenSans-Regular.ttf", 36);
TPixel color = NamedColors<TPixel>.Black;
float padding = 5;
var text = "A short piece of text";
using (var img = provider.GetImage())
{
float targetWidth = img.Width - (padding * 2);
float targetHeight = img.Height - (padding * 2);
// measure the text size
SizeF size = TextMeasurer.Measure(text, new RendererOptions(font));
//find out how much we need to scale the text to fill the space (up or down)
float scalingFactor = Math.Min(img.Width / size.Width, img.Height / size.Height);
//create a new font
Font scaledFont = new Font(font, scalingFactor * font.Size);
var center = new PointF(img.Width / 2, img.Height / 2);
var textGraphicOptions = new TextGraphicsOptions(true)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
img.Mutate(i => i.DrawText(textGraphicOptions, text, scaledFont, color, center));
}
}
[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)]

2
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -27,7 +27,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.5.0" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.9.0.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />

Loading…
Cancel
Save