Skip to content

Commit

Permalink
Merge branch 'master' into fix-indexoutofrangeexception-in-fillregion…
Browse files Browse the repository at this point in the history
…processor
  • Loading branch information
JimBobSquarePants committed Aug 11, 2019
2 parents eda97a9 + 1891d9c commit 0e7172e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 42 deletions.
10 changes: 5 additions & 5 deletions tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Numerics;
Expand Down Expand Up @@ -50,7 +50,7 @@ public void CorrectlySetsBrushAndPath()
ShapePath region = Assert.IsType<ShapePath>(processor.Region);

// path is converted to a polygon before filling
ComplexPolygon polygon = Assert.IsType<ComplexPolygon>(region.Shape);
Assert.IsType<ComplexPolygon>(region.Shape);

Assert.Equal(this.pen.StrokeFill, processor.Brush);
}
Expand All @@ -68,7 +68,7 @@ public void CorrectlySetsBrushPathOptions()
Assert.Equal(this.noneDefault, processor.Options);

ShapePath region = Assert.IsType<ShapePath>(processor.Region);
ComplexPolygon polygon = Assert.IsType<ComplexPolygon>(region.Shape);
Assert.IsType<ComplexPolygon>(region.Shape);

Assert.Equal(this.pen.StrokeFill, processor.Brush);
}
Expand All @@ -86,7 +86,7 @@ public void CorrectlySetsColorAndPath()
Assert.Equal(GraphicsOptions.Default, processor.Options);

ShapePath region = Assert.IsType<ShapePath>(processor.Region);
ComplexPolygon polygon = Assert.IsType<ComplexPolygon>(region.Shape);
Assert.IsType<ComplexPolygon>(region.Shape);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand All @@ -105,7 +105,7 @@ public void CorrectlySetsColorPathAndOptions()
Assert.Equal(this.noneDefault, processor.Options);

ShapePath region = Assert.IsType<ShapePath>(processor.Region);
ComplexPolygon polygon = Assert.IsType<ComplexPolygon>(region.Shape);
Assert.IsType<ComplexPolygon>(region.Shape);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand Down
10 changes: 5 additions & 5 deletions tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Numerics;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void CorrectlySetsBrushAndPath()

// path is converted to a polygon before filling
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

Assert.Equal(this.brush, processor.Brush);
}
Expand All @@ -50,7 +50,7 @@ public void CorrectlySetsBrushPathOptions()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

Assert.Equal(this.brush, processor.Brush);
}
Expand All @@ -65,7 +65,7 @@ public void CorrectlySetsColorAndPath()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand All @@ -81,7 +81,7 @@ public void CorrectlySetsColorPathAndOptions()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand Down
10 changes: 5 additions & 5 deletions tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Numerics;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void CorrectlySetsBrushAndPath()

// path is converted to a polygon before filling
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

Assert.Equal(this.brush, processor.Brush);
}
Expand All @@ -70,7 +70,7 @@ public void CorrectlySetsBrushPathOptions()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

Assert.Equal(this.brush, processor.Brush);
}
Expand All @@ -89,7 +89,7 @@ public void CorrectlySetsColorAndPath()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand All @@ -109,7 +109,7 @@ public void CorrectlySetsColorPathAndOptions()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand Down
10 changes: 5 additions & 5 deletions tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Numerics;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void CorrectlySetsBrushAndPath()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

Assert.Equal(this.brush, processor.Brush);
}
Expand All @@ -50,7 +50,7 @@ public void CorrectlySetsBrushPathAndOptions()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

Assert.Equal(this.brush, processor.Brush);
}
Expand All @@ -66,7 +66,7 @@ public void CorrectlySetsColorAndPath()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand All @@ -82,7 +82,7 @@ public void CorrectlySetsColorPathAndOptions()

ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

SolidBrush brush = Assert.IsType<SolidBrush>(processor.Brush);
Assert.Equal(this.color, brush.Color);
Expand Down
16 changes: 4 additions & 12 deletions tests/ImageSharp.Tests/Drawing/Text/DrawText.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Numerics;
Expand All @@ -14,14 +14,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
{
public class DrawText : BaseImageOperationsExtensionTest
{
Rgba32 color = Color.HotPink;

SolidBrush brush = Brushes.Solid(Color.HotPink);

IPath path = new SixLabors.Shapes.Path(
new LinearLineSegment(
new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), }));

private readonly FontCollection FontCollection;

private readonly Font Font;
Expand Down Expand Up @@ -103,23 +95,23 @@ public void DrawForEachACharacterWhenPenSetAndNotBrush()
Pens.Dash(Color.Red, 1),
Vector2.Zero);

var processor = this.Verify<DrawTextProcessor>(0);
this.Verify<DrawTextProcessor>(0);
}

[Fact]
public void DrawForEachACharacterWhenPenSetAndNotBrushDefaultOptions()
{
this.operations.DrawText("123", this.Font, null, Pens.Dash(Color.Red, 1), Vector2.Zero);

var processor = this.Verify<DrawTextProcessor>(0);
this.Verify<DrawTextProcessor>(0);
}

[Fact]
public void DrawForEachACharacterWhenPenSet()
{
this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero);

var processor = this.Verify<DrawTextProcessor>(0);
this.Verify<DrawTextProcessor>(0);
}

[Fact]
Expand Down
12 changes: 4 additions & 8 deletions tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -41,21 +41,17 @@ public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688<TPixel>(TestIm
{
Font font = CreateFont("OpenSans-Regular.ttf", 36);
Color color = Color.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
//create a new font
Font scaledFont = new Font(font, scalingFactor * font.Size);

var center = new PointF(img.Width / 2, img.Height / 2);
Expand All @@ -64,7 +60,7 @@ public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688<TPixel>(TestIm
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

img.Mutate(i => i.DrawText(textGraphicOptions, text, scaledFont, color, center));
}
}
Expand Down Expand Up @@ -241,6 +237,6 @@ private static Font CreateFont(string fontName, int size)
return font;
}


}
}
4 changes: 2 additions & 2 deletions tests/ImageSharp.Tests/ImageOperationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void CloneCallsImageOperationsProvider_ListOfProcessors_WithDuplicateImag
[Fact]
public void CloneCallsImageOperationsProvider_Func_NotOnOriginal()
{
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processorDefinition));
this.image.Clone(x => x.ApplyProcessor(this.processorDefinition));
Assert.False(this.provider.HasCreated(this.image));
Assert.DoesNotContain(
this.processorDefinition,
Expand All @@ -93,7 +93,7 @@ public void CloneCallsImageOperationsProvider_Func_NotOnOriginal()
[Fact]
public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOriginal()
{
Image<Rgba32> returned = this.image.Clone(this.processorDefinition);
this.image.Clone(this.processorDefinition);
Assert.False(this.provider.HasCreated(this.image));
Assert.DoesNotContain(
this.processorDefinition,
Expand Down

0 comments on commit 0e7172e

Please sign in to comment.