From 241c50a79e2747f68c50801113c96e9bfdc026a7 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 11 Nov 2019 12:12:18 +1100 Subject: [PATCH] Drop Default, use DeepClone + tests --- .../Extensions/DrawImageExtensions.cs | 12 +-- .../DrawPathCollectionExtensions.cs | 2 +- .../Extensions/DrawPathExtensions.cs | 2 +- .../Extensions/DrawPolygonExtensions.cs | 2 +- .../Extensions/DrawRectangleExtensions.cs | 2 +- .../Extensions/DrawTextExtensions.cs | 8 +- .../Extensions/FillPathBuilderExtensions.cs | 2 +- .../FillPathCollectionExtensions.cs | 2 +- .../Extensions/FillPathExtensions.cs | 2 +- .../Extensions/FillRegionExtensions.cs | 4 +- .../Processing/TextGraphicsOptions.cs | 50 +++++------ src/ImageSharp/GraphicsOptions.cs | 36 ++++---- .../Extensions/BackgroundColorExtensions.cs | 8 +- .../Processing/Extensions/GlowExtensions.cs | 10 +-- .../Extensions/VignetteExtensions.cs | 10 +-- .../Processors/Overlays/GlowProcessor.cs | 2 +- .../Processors/Overlays/VignetteProcessor.cs | 2 +- .../Drawing/DrawImageTests.cs | 2 +- .../Drawing/Paths/DrawPathCollection.cs | 17 ++-- .../Drawing/Paths/FillPath.cs | 17 ++-- .../Drawing/Paths/FillPathCollection.cs | 17 ++-- .../Drawing/Paths/FillPolygon.cs | 17 ++-- .../Drawing/Paths/FillRectangle.cs | 24 +++--- .../Drawing/Text/TextGraphicsOptionsTests.cs | 85 +++++++++++++++---- .../ImageSharp.Tests/GraphicsOptionsTests.cs | 44 ++++++++-- .../Processing/Effects/BackgroundColorTest.cs | 24 +++--- .../Processing/Overlays/GlowTest.cs | 23 ++--- .../Processing/Overlays/VignetteTest.cs | 23 ++--- .../TestUtilities/GraphicsOptionsComparer.cs | 21 +++++ 29 files changed, 300 insertions(+), 170 deletions(-) create mode 100644 tests/ImageSharp.Tests/TestUtilities/GraphicsOptionsComparer.cs diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs index 981cf1bef4..6c694ab73b 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs @@ -27,8 +27,8 @@ namespace SixLabors.ImageSharp.Processing new DrawImageProcessor( image, Point.Empty, - GraphicsOptions.Default.ColorBlendingMode, - GraphicsOptions.Default.AlphaCompositionMode, + new GraphicsOptions().ColorBlendingMode, + new GraphicsOptions().AlphaCompositionMode, opacity)); /// @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing image, Point.Empty, colorBlending, - GraphicsOptions.Default.AlphaCompositionMode, + new GraphicsOptions().AlphaCompositionMode, opacity)); /// @@ -105,8 +105,8 @@ namespace SixLabors.ImageSharp.Processing new DrawImageProcessor( image, location, - GraphicsOptions.Default.ColorBlendingMode, - GraphicsOptions.Default.AlphaCompositionMode, + new GraphicsOptions().ColorBlendingMode, + new GraphicsOptions().AlphaCompositionMode, opacity)); /// @@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Processing image, location, colorBlending, - GraphicsOptions.Default.AlphaCompositionMode, + new GraphicsOptions().AlphaCompositionMode, opacity)); /// diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs index a68b69a444..90b8c68ac2 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) => - source.Draw(GraphicsOptions.Default, pen, paths); + source.Draw(new GraphicsOptions(), pen, paths); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs index dfe30f6a3c..822375ca97 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing /// The path. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) => - source.Draw(GraphicsOptions.Default, pen, path); + source.Draw(new GraphicsOptions(), pen, path); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs index 86d8e9e2e2..d51e586452 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, IPen pen, params PointF[] points) => - source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points))); + source.Draw(new GraphicsOptions(), pen, new Polygon(new LinearLineSegment(points))); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs index da78ab2ecc..b3b5dd76a5 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing /// The shape. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) => - source.Draw(GraphicsOptions.Default, pen, shape); + source.Draw(new GraphicsOptions(), pen, shape); /// /// Draws the outline of the rectangle with the provided brush at the provided thickness. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs index 05cd3a1ae6..82dbb8d97e 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Processing Font font, Color color, PointF location) => - source.DrawText(TextGraphicsOptions.Default, text, font, color, location); + source.DrawText(new TextGraphicsOptions(), text, font, color, location); /// /// Draws the text onto the the image filled via the brush. @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing Font font, IBrush brush, PointF location) => - source.DrawText(TextGraphicsOptions.Default, text, font, brush, location); + source.DrawText(new TextGraphicsOptions(), text, font, brush, location); /// /// Draws the text onto the the image filled via the brush. @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Processing Font font, IPen pen, PointF location) => - source.DrawText(TextGraphicsOptions.Default, text, font, pen, location); + source.DrawText(new TextGraphicsOptions(), text, font, pen, location); /// /// Draws the text onto the the image outlined via the pen. @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Processing IBrush brush, IPen pen, PointF location) => - source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location); + source.DrawText(new TextGraphicsOptions(), text, font, brush, pen, location); /// /// Draws the text using the default resolution of 72dpi onto the the image filled via the brush then outlined via the pen. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs index 5de9c6d4ed..030fe6ff1f 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, IBrush brush, Action path) => - source.Fill(GraphicsOptions.Default, brush, path); + source.Fill(new GraphicsOptions(), brush, path); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs index 776e1f7e4e..5d8aaf3071 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, IBrush brush, IPathCollection paths) => - source.Fill(GraphicsOptions.Default, brush, paths); + source.Fill(new GraphicsOptions(), brush, paths); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs index 718016a9e6..4d262aa5fb 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing /// The path. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) => - source.Fill(GraphicsOptions.Default, brush, new ShapeRegion(path)); + source.Fill(new GraphicsOptions(), brush, new ShapeRegion(path)); /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs index 294e575140..f5dd76318c 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Processing /// The details how to fill the region of interest. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) => - source.Fill(GraphicsOptions.Default, brush); + source.Fill(new GraphicsOptions(), brush); /// /// Flood fills the image with the specified color. @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing /// The region. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) => - source.Fill(GraphicsOptions.Default, brush, region); + source.Fill(new GraphicsOptions(), brush, region); /// /// Flood fills the image with in the region with the specified color. diff --git a/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs index 60a48a31fa..185fa1f74c 100644 --- a/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs +++ b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; @@ -10,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing /// /// Options for influencing the drawing functions. /// - public class TextGraphicsOptions + public class TextGraphicsOptions : IDeepCloneable { private int antialiasSubpixelDepth = 16; private float blendPercentage = 1F; @@ -18,6 +17,29 @@ namespace SixLabors.ImageSharp.Processing private float dpiX = 72F; private float dpiY = 72F; + /// + /// Initializes a new instance of the class. + /// + public TextGraphicsOptions() + { + } + + private TextGraphicsOptions(TextGraphicsOptions source) + { + this.AlphaCompositionMode = source.AlphaCompositionMode; + this.Antialias = source.Antialias; + this.AntialiasSubpixelDepth = source.AntialiasSubpixelDepth; + this.ApplyKerning = source.ApplyKerning; + this.BlendPercentage = source.BlendPercentage; + this.ColorBlendingMode = source.ColorBlendingMode; + this.DpiX = source.DpiX; + this.DpiY = source.DpiY; + this.HorizontalAlignment = source.HorizontalAlignment; + this.TabWidth = source.TabWidth; + this.WrapTextWidth = source.WrapTextWidth; + this.VerticalAlignment = source.VerticalAlignment; + } + /// /// Gets the default instance. /// @@ -194,27 +216,7 @@ namespace SixLabors.ImageSharp.Processing }; } - /// - /// Creates a shallow copy of the . - /// - /// A new options instance. - public TextGraphicsOptions Clone() - { - return new TextGraphicsOptions - { - AlphaCompositionMode = this.AlphaCompositionMode, - Antialias = this.Antialias, - AntialiasSubpixelDepth = this.AntialiasSubpixelDepth, - ApplyKerning = this.ApplyKerning, - BlendPercentage = this.BlendPercentage, - ColorBlendingMode = this.ColorBlendingMode, - DpiX = this.DpiX, - DpiY = this.DpiY, - HorizontalAlignment = this.HorizontalAlignment, - TabWidth = this.TabWidth, - WrapTextWidth = this.WrapTextWidth, - VerticalAlignment = this.VerticalAlignment - }; - } + /// + public TextGraphicsOptions DeepClone() => new TextGraphicsOptions(this); } } diff --git a/src/ImageSharp/GraphicsOptions.cs b/src/ImageSharp/GraphicsOptions.cs index 1673057b86..9c62d23371 100644 --- a/src/ImageSharp/GraphicsOptions.cs +++ b/src/ImageSharp/GraphicsOptions.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp @@ -9,11 +8,27 @@ namespace SixLabors.ImageSharp /// /// Options for influencing the drawing functions. /// - public class GraphicsOptions + public class GraphicsOptions : IDeepCloneable { private int antialiasSubpixelDepth = 16; private float blendPercentage = 1F; + /// + /// Initializes a new instance of the class. + /// + public GraphicsOptions() + { + } + + private GraphicsOptions(GraphicsOptions source) + { + this.AlphaCompositionMode = source.AlphaCompositionMode; + this.Antialias = source.Antialias; + this.AntialiasSubpixelDepth = source.AntialiasSubpixelDepth; + this.BlendPercentage = source.BlendPercentage; + this.ColorBlendingMode = source.ColorBlendingMode; + } + /// /// Gets the default instance. /// @@ -73,20 +88,7 @@ namespace SixLabors.ImageSharp /// public PixelAlphaCompositionMode AlphaCompositionMode { get; set; } = PixelAlphaCompositionMode.SrcOver; - /// - /// Creates a shallow copy of the . - /// - /// A new options instance. - public GraphicsOptions Clone() - { - return new GraphicsOptions - { - AlphaCompositionMode = this.AlphaCompositionMode, - Antialias = this.Antialias, - AntialiasSubpixelDepth = this.AntialiasSubpixelDepth, - BlendPercentage = this.BlendPercentage, - ColorBlendingMode = this.ColorBlendingMode - }; - } + /// + public GraphicsOptions DeepClone() => new GraphicsOptions(this); } } diff --git a/src/ImageSharp/Processing/Extensions/BackgroundColorExtensions.cs b/src/ImageSharp/Processing/Extensions/BackgroundColorExtensions.cs index dd1cc1ed24..cc2fb25120 100644 --- a/src/ImageSharp/Processing/Extensions/BackgroundColorExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/BackgroundColorExtensions.cs @@ -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 SixLabors.ImageSharp.Processing.Processors.Overlays; @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing /// The color to set as the background. /// The to allow chaining of operations. public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, Color color) => - BackgroundColor(source, GraphicsOptions.Default, color); + BackgroundColor(source, new GraphicsOptions(), color); /// /// Replaces the background color of image with the given one. @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, Color color, Rectangle rectangle) => - BackgroundColor(source, GraphicsOptions.Default, color, rectangle); + BackgroundColor(source, new GraphicsOptions(), color, rectangle); /// /// Replaces the background color of image with the given one. @@ -66,4 +66,4 @@ namespace SixLabors.ImageSharp.Processing Rectangle rectangle) => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Processing/Extensions/GlowExtensions.cs b/src/ImageSharp/Processing/Extensions/GlowExtensions.cs index 39734882b0..90b73794ba 100644 --- a/src/ImageSharp/Processing/Extensions/GlowExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/GlowExtensions.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source) => - Glow(source, GraphicsOptions.Default); + Glow(source, new GraphicsOptions()); /// /// Applies a radial glow effect to an image. @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Processing /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source, Color color) { - return Glow(source, GraphicsOptions.Default, color); + return Glow(source, new GraphicsOptions(), color); } /// @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing /// The the radius. /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) => - Glow(source, GraphicsOptions.Default, radius); + Glow(source, new GraphicsOptions(), radius); /// /// Applies a radial glow effect to an image. @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The to allow chaining of operations. public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) => - source.Glow(GraphicsOptions.Default, rectangle); + source.Glow(new GraphicsOptions(), rectangle); /// /// Applies a radial glow effect to an image. @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing Color color, float radius, Rectangle rectangle) => - source.Glow(GraphicsOptions.Default, color, ValueSize.Absolute(radius), rectangle); + source.Glow(new GraphicsOptions(), color, ValueSize.Absolute(radius), rectangle); /// /// Applies a radial glow effect to an image. diff --git a/src/ImageSharp/Processing/Extensions/VignetteExtensions.cs b/src/ImageSharp/Processing/Extensions/VignetteExtensions.cs index 74a59d3e13..ffab8e2bf9 100644 --- a/src/ImageSharp/Processing/Extensions/VignetteExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/VignetteExtensions.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The to allow chaining of operations. public static IImageProcessingContext Vignette(this IImageProcessingContext source) => - Vignette(source, GraphicsOptions.Default); + Vignette(source, new GraphicsOptions()); /// /// Applies a radial vignette effect to an image. @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing /// The color to set as the vignette. /// The to allow chaining of operations. public static IImageProcessingContext Vignette(this IImageProcessingContext source, Color color) => - Vignette(source, GraphicsOptions.Default, color); + Vignette(source, new GraphicsOptions(), color); /// /// Applies a radial vignette effect to an image. @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing this IImageProcessingContext source, float radiusX, float radiusY) => - Vignette(source, GraphicsOptions.Default, radiusX, radiusY); + Vignette(source, new GraphicsOptions(), radiusX, radiusY); /// /// Applies a radial vignette effect to an image. @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The to allow chaining of operations. public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) => - Vignette(source, GraphicsOptions.Default, rectangle); + Vignette(source, new GraphicsOptions(), rectangle); /// /// Applies a radial vignette effect to an image. @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing float radiusX, float radiusY, Rectangle rectangle) => - source.Vignette(GraphicsOptions.Default, color, radiusX, radiusY, rectangle); + source.Vignette(new GraphicsOptions(), color, radiusX, radiusY, rectangle); /// /// Applies a radial vignette effect to an image. diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 0958e3aa9e..1a60b79aca 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays /// The color or the glow. /// The radius of the glow. internal GlowProcessor(Color color, ValueSize radius) - : this(color, radius, GraphicsOptions.Default) + : this(color, radius, new GraphicsOptions()) { } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 2365318f3d..e1c836ff56 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays /// /// The color of the vignette. public VignetteProcessor(Color color) - : this(color, GraphicsOptions.Default) + : this(color, new GraphicsOptions()) { } diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs index 86c1c28504..61b45729d3 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTests.cs @@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing void Test() { - background.Mutate(context => context.DrawImage(overlay, new Point(x, y), GraphicsOptions.Default)); + background.Mutate(context => context.DrawImage(overlay, new Point(x, y), new GraphicsOptions())); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs index f6d9c7fe5c..36c11035c6 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Tests.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Shapes; using Xunit; @@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class DrawPathCollection : BaseImageOperationsExtensionTest { - GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + + GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; Color color = Color.HotPink; Pen pen = Pens.Solid(Rgba32.HotPink, 1); IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { @@ -46,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapePath region = Assert.IsType(processor.Region); @@ -60,13 +63,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Draw(this.noneDefault, this.pen, this.pathCollection); + this.operations.Draw(this.nonDefault, this.pen, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapePath region = Assert.IsType(processor.Region); Assert.IsType(region.Shape); @@ -84,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapePath region = Assert.IsType(processor.Region); Assert.IsType(region.Shape); @@ -97,13 +100,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Draw(this.noneDefault, this.color, 1, this.pathCollection); + this.operations.Draw(this.nonDefault, this.color, 1, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapePath region = Assert.IsType(processor.Region); Assert.IsType(region.Shape); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index fa1949e673..cea59e15e5 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Tests.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Shapes; using Xunit; @@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class FillPath : BaseImageOperationsExtensionTest { - GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + + GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; Color color = Color.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); IPath path = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { @@ -30,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths this.operations.Fill(this.brush, this.path); var processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); @@ -44,10 +47,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Fill(this.noneDefault, this.brush, this.path); + this.operations.Fill(this.nonDefault, this.brush, this.path); var processor = this.Verify(); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -62,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths this.operations.Fill(this.color, this.path); var processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -75,10 +78,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Fill(this.noneDefault, this.color, this.path); + this.operations.Fill(this.nonDefault, this.color, this.path); var processor = this.Verify(); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index 39e2fc2f97..2a9c04a89f 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Tests.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Shapes; using Xunit; @@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class FillPathCollection : BaseImageOperationsExtensionTest { - GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + + GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; Color color = Color.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { @@ -46,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); @@ -61,13 +64,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Fill(this.noneDefault, this.brush, this.pathCollection); + this.operations.Fill(this.nonDefault, this.brush, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -86,7 +89,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -100,13 +103,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Fill(this.noneDefault, this.color, this.pathCollection); + this.operations.Fill(this.nonDefault, this.color, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index 03a827a6a9..8dacd1e7f6 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Tests.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Shapes; using Xunit; @@ -14,7 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class FillPolygon : BaseImageOperationsExtensionTest { - GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + + GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; Color color = Color.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); SixLabors.Primitives.PointF[] path = { @@ -32,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths FillRegionProcessor processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -44,10 +47,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathAndOptions() { - this.operations.FillPolygon(this.noneDefault, this.brush, this.path); + this.operations.FillPolygon(this.nonDefault, this.brush, this.path); FillRegionProcessor processor = this.Verify(); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -63,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths FillRegionProcessor processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); @@ -76,10 +79,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.FillPolygon(this.noneDefault, this.color, this.path); + this.operations.FillPolygon(this.nonDefault, this.color, this.path); FillRegionProcessor processor = this.Verify(); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index cc108fb54e..6b08323b68 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -6,17 +6,19 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Tests.Processing; - +using SixLabors.ImageSharp.Tests.TestUtilities; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class FillRectangle : BaseImageOperationsExtensionTest { - GraphicsOptions noneDefault = new GraphicsOptions { Antialias = false }; - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76); + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + + private GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; + private Color color = Color.HotPink; + private SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + private SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76); [Fact] public void CorrectlySetsBrushAndRectangle() @@ -24,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths this.operations.Fill(this.brush, this.rectangle); FillRegionProcessor processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Shapes.RectangularPolygon rect = Assert.IsType(region.Shape); @@ -39,10 +41,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushRectangleAndOptions() { - this.operations.Fill(this.noneDefault, this.brush, this.rectangle); + this.operations.Fill(this.nonDefault, this.brush, this.rectangle); FillRegionProcessor processor = this.Verify(); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Shapes.RectangularPolygon rect = Assert.IsType(region.Shape); @@ -60,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths this.operations.Fill(this.color, this.rectangle); FillRegionProcessor processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.Options); + Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Shapes.RectangularPolygon rect = Assert.IsType(region.Shape); @@ -76,10 +78,10 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorRectangleAndOptions() { - this.operations.Fill(this.noneDefault, this.color, this.rectangle); + this.operations.Fill(this.nonDefault, this.color, this.rectangle); FillRegionProcessor processor = this.Verify(); - Assert.Equal(this.noneDefault, processor.Options); + Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Shapes.RectangularPolygon rect = Assert.IsType(region.Shape); diff --git a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs index d15b717bb6..a59afb271d 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs @@ -12,17 +12,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public class TextGraphicsOptionsTests { private readonly TextGraphicsOptions newTextGraphicsOptions = new TextGraphicsOptions(); - private readonly TextGraphicsOptions defaultTextGraphicsOptions = TextGraphicsOptions.Default; - private readonly TextGraphicsOptions cloneTextGraphicsOptions = TextGraphicsOptions.Default.Clone(); + private readonly TextGraphicsOptions cloneTextGraphicsOptions = new TextGraphicsOptions().DeepClone(); [Fact] - public void DefaultTextGraphicsOptionsIsNotNull() => Assert.True(this.defaultTextGraphicsOptions != null); + public void CloneTextGraphicsOptionsIsNotNull() => Assert.True(this.cloneTextGraphicsOptions != null); [Fact] public void DefaultTextGraphicsOptionsAntialias() { Assert.True(this.newTextGraphicsOptions.Antialias); - Assert.True(this.defaultTextGraphicsOptions.Antialias); Assert.True(this.cloneTextGraphicsOptions.Antialias); } @@ -31,7 +29,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const int Expected = 16; Assert.Equal(Expected, this.newTextGraphicsOptions.AntialiasSubpixelDepth); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.AntialiasSubpixelDepth); Assert.Equal(Expected, this.cloneTextGraphicsOptions.AntialiasSubpixelDepth); } @@ -40,7 +37,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const float Expected = 1F; Assert.Equal(Expected, this.newTextGraphicsOptions.BlendPercentage); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.BlendPercentage); Assert.Equal(Expected, this.cloneTextGraphicsOptions.BlendPercentage); } @@ -49,7 +45,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal; Assert.Equal(Expected, this.newTextGraphicsOptions.ColorBlendingMode); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.ColorBlendingMode); Assert.Equal(Expected, this.cloneTextGraphicsOptions.ColorBlendingMode); } @@ -58,7 +53,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver; Assert.Equal(Expected, this.newTextGraphicsOptions.AlphaCompositionMode); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.AlphaCompositionMode); Assert.Equal(Expected, this.cloneTextGraphicsOptions.AlphaCompositionMode); } @@ -67,7 +61,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const bool Expected = true; Assert.Equal(Expected, this.newTextGraphicsOptions.ApplyKerning); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.ApplyKerning); Assert.Equal(Expected, this.cloneTextGraphicsOptions.ApplyKerning); } @@ -76,7 +69,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const HorizontalAlignment Expected = HorizontalAlignment.Left; Assert.Equal(Expected, this.newTextGraphicsOptions.HorizontalAlignment); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.HorizontalAlignment); Assert.Equal(Expected, this.cloneTextGraphicsOptions.HorizontalAlignment); } @@ -85,7 +77,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const VerticalAlignment Expected = VerticalAlignment.Top; Assert.Equal(Expected, this.newTextGraphicsOptions.VerticalAlignment); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.VerticalAlignment); Assert.Equal(Expected, this.cloneTextGraphicsOptions.VerticalAlignment); } @@ -94,7 +85,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const float Expected = 72F; Assert.Equal(Expected, this.newTextGraphicsOptions.DpiX); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.DpiX); Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiX); } @@ -103,7 +93,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const float Expected = 72F; Assert.Equal(Expected, this.newTextGraphicsOptions.DpiY); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.DpiY); Assert.Equal(Expected, this.cloneTextGraphicsOptions.DpiY); } @@ -112,7 +101,6 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const float Expected = 4F; Assert.Equal(Expected, this.newTextGraphicsOptions.TabWidth); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.TabWidth); Assert.Equal(Expected, this.cloneTextGraphicsOptions.TabWidth); } @@ -121,10 +109,77 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text { const float Expected = 0F; Assert.Equal(Expected, this.newTextGraphicsOptions.WrapTextWidth); - Assert.Equal(Expected, this.defaultTextGraphicsOptions.WrapTextWidth); Assert.Equal(Expected, this.cloneTextGraphicsOptions.WrapTextWidth); } + [Fact] + public void NonDefaultClone() + { + var expected = new TextGraphicsOptions + { + AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop, + Antialias = false, + AntialiasSubpixelDepth = 23, + ApplyKerning = false, + BlendPercentage = .25F, + ColorBlendingMode = PixelColorBlendingMode.HardLight, + DpiX = 46F, + DpiY = 52F, + HorizontalAlignment = HorizontalAlignment.Center, + TabWidth = 3F, + VerticalAlignment = VerticalAlignment.Bottom, + WrapTextWidth = 42F + }; + + TextGraphicsOptions actual = expected.DeepClone(); + + Assert.Equal(expected.AlphaCompositionMode, actual.AlphaCompositionMode); + Assert.Equal(expected.Antialias, actual.Antialias); + Assert.Equal(expected.AntialiasSubpixelDepth, actual.AntialiasSubpixelDepth); + Assert.Equal(expected.ApplyKerning, actual.ApplyKerning); + Assert.Equal(expected.BlendPercentage, actual.BlendPercentage); + Assert.Equal(expected.ColorBlendingMode, actual.ColorBlendingMode); + Assert.Equal(expected.DpiX, actual.DpiX); + Assert.Equal(expected.DpiY, actual.DpiY); + Assert.Equal(expected.HorizontalAlignment, actual.HorizontalAlignment); + Assert.Equal(expected.TabWidth, actual.TabWidth); + Assert.Equal(expected.VerticalAlignment, actual.VerticalAlignment); + Assert.Equal(expected.WrapTextWidth, actual.WrapTextWidth); + } + + [Fact] + public void CloneIsDeep() + { + var expected = new TextGraphicsOptions(); + TextGraphicsOptions actual = expected.DeepClone(); + + actual.AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop; + actual.Antialias = false; + actual.AntialiasSubpixelDepth = 23; + actual.ApplyKerning = false; + actual.BlendPercentage = .25F; + actual.ColorBlendingMode = PixelColorBlendingMode.HardLight; + actual.DpiX = 46F; + actual.DpiY = 52F; + actual.HorizontalAlignment = HorizontalAlignment.Center; + actual.TabWidth = 3F; + actual.VerticalAlignment = VerticalAlignment.Bottom; + actual.WrapTextWidth = 42F; + + Assert.NotEqual(expected.AlphaCompositionMode, actual.AlphaCompositionMode); + Assert.NotEqual(expected.Antialias, actual.Antialias); + Assert.NotEqual(expected.AntialiasSubpixelDepth, actual.AntialiasSubpixelDepth); + Assert.NotEqual(expected.ApplyKerning, actual.ApplyKerning); + Assert.NotEqual(expected.BlendPercentage, actual.BlendPercentage); + Assert.NotEqual(expected.ColorBlendingMode, actual.ColorBlendingMode); + Assert.NotEqual(expected.DpiX, actual.DpiX); + Assert.NotEqual(expected.DpiY, actual.DpiY); + Assert.NotEqual(expected.HorizontalAlignment, actual.HorizontalAlignment); + Assert.NotEqual(expected.TabWidth, actual.TabWidth); + Assert.NotEqual(expected.VerticalAlignment, actual.VerticalAlignment); + Assert.NotEqual(expected.WrapTextWidth, actual.WrapTextWidth); + } + [Fact] public void ExplicitCastOfGraphicsOptions() { diff --git a/tests/ImageSharp.Tests/GraphicsOptionsTests.cs b/tests/ImageSharp.Tests/GraphicsOptionsTests.cs index 4e23b17663..69f904f1cb 100644 --- a/tests/ImageSharp.Tests/GraphicsOptionsTests.cs +++ b/tests/ImageSharp.Tests/GraphicsOptionsTests.cs @@ -2,24 +2,24 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities; using Xunit; namespace SixLabors.ImageSharp.Tests { public class GraphicsOptionsTests { + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); private readonly GraphicsOptions newGraphicsOptions = new GraphicsOptions(); - private readonly GraphicsOptions defaultGraphicsOptions = GraphicsOptions.Default; - private readonly GraphicsOptions cloneGraphicsOptions = GraphicsOptions.Default.Clone(); + private readonly GraphicsOptions cloneGraphicsOptions = new GraphicsOptions().DeepClone(); [Fact] - public void DefaultGraphicsOptionsIsNotNull() => Assert.True(this.defaultGraphicsOptions != null); + public void CloneGraphicsOptionsIsNotNull() => Assert.True(this.cloneGraphicsOptions != null); [Fact] public void DefaultGraphicsOptionsAntialias() { Assert.True(this.newGraphicsOptions.Antialias); - Assert.True(this.defaultGraphicsOptions.Antialias); Assert.True(this.cloneGraphicsOptions.Antialias); } @@ -28,7 +28,6 @@ namespace SixLabors.ImageSharp.Tests { const int Expected = 16; Assert.Equal(Expected, this.newGraphicsOptions.AntialiasSubpixelDepth); - Assert.Equal(Expected, this.defaultGraphicsOptions.AntialiasSubpixelDepth); Assert.Equal(Expected, this.cloneGraphicsOptions.AntialiasSubpixelDepth); } @@ -37,7 +36,6 @@ namespace SixLabors.ImageSharp.Tests { const float Expected = 1F; Assert.Equal(Expected, this.newGraphicsOptions.BlendPercentage); - Assert.Equal(Expected, this.defaultGraphicsOptions.BlendPercentage); Assert.Equal(Expected, this.cloneGraphicsOptions.BlendPercentage); } @@ -46,7 +44,6 @@ namespace SixLabors.ImageSharp.Tests { const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal; Assert.Equal(Expected, this.newGraphicsOptions.ColorBlendingMode); - Assert.Equal(Expected, this.defaultGraphicsOptions.ColorBlendingMode); Assert.Equal(Expected, this.cloneGraphicsOptions.ColorBlendingMode); } @@ -55,10 +52,41 @@ namespace SixLabors.ImageSharp.Tests { const PixelAlphaCompositionMode Expected = PixelAlphaCompositionMode.SrcOver; Assert.Equal(Expected, this.newGraphicsOptions.AlphaCompositionMode); - Assert.Equal(Expected, this.defaultGraphicsOptions.AlphaCompositionMode); Assert.Equal(Expected, this.cloneGraphicsOptions.AlphaCompositionMode); } + [Fact] + public void NonDefaultClone() + { + var expected = new GraphicsOptions + { + AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop, + Antialias = false, + AntialiasSubpixelDepth = 23, + BlendPercentage = .25F, + ColorBlendingMode = PixelColorBlendingMode.HardLight, + }; + + GraphicsOptions actual = expected.DeepClone(); + + Assert.Equal(expected, actual, graphicsOptionsComparer); + } + + [Fact] + public void CloneIsDeep() + { + var expected = new GraphicsOptions(); + GraphicsOptions actual = expected.DeepClone(); + + actual.AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop; + actual.Antialias = false; + actual.AntialiasSubpixelDepth = 23; + actual.BlendPercentage = .25F; + actual.ColorBlendingMode = PixelColorBlendingMode.HardLight; + + Assert.NotEqual(expected, actual, graphicsOptionsComparer); + } + [Fact] public void IsOpaqueColor() { diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index 1b5bd656dc..a137a9f438 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -1,22 +1,24 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Overlays; - +using SixLabors.ImageSharp.Tests.TestUtilities; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { public class BackgroundColorTest : BaseImageOperationsExtensionTest { + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + [Fact] public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet() { this.operations.BackgroundColor(Color.BlanchedAlmond); - var processor = this.Verify(); + BackgroundColorProcessor processor = this.Verify(); - Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), processor.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.BlanchedAlmond, processor.Color); } @@ -24,9 +26,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects public void BackgroundColor_amount_rect_BackgroundColorProcessorDefaultsSet() { this.operations.BackgroundColor(Color.BlanchedAlmond, this.rect); - var processor = this.Verify(this.rect); + BackgroundColorProcessor processor = this.Verify(this.rect); - Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), processor.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.BlanchedAlmond, processor.Color); } @@ -34,9 +36,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet() { this.operations.BackgroundColor(this.options, Color.BlanchedAlmond); - var processor = this.Verify(); + BackgroundColorProcessor processor = this.Verify(); - Assert.Equal(this.options, processor.GraphicsOptions); + Assert.Equal(this.options, processor.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.BlanchedAlmond, processor.Color); } @@ -44,10 +46,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet() { this.operations.BackgroundColor(this.options, Color.BlanchedAlmond, this.rect); - var processor = this.Verify(this.rect); + BackgroundColorProcessor processor = this.Verify(this.rect); - Assert.Equal(this.options, processor.GraphicsOptions); + Assert.Equal(this.options, processor.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.BlanchedAlmond, processor.Color); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index 978fd416bc..32c4c6fe74 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs @@ -1,10 +1,11 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Overlays; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Primitives; using Xunit; @@ -12,13 +13,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays { public class GlowTest : BaseImageOperationsExtensionTest { + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + [Fact] public void Glow_GlowProcessorWithDefaultValues() { this.operations.Glow(); - var p = this.Verify(); + GlowProcessor p = this.Verify(); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Black, p.GlowColor); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); } @@ -27,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays public void Glow_Color_GlowProcessorWithDefaultValues() { this.operations.Glow(Rgba32.Aquamarine); - var p = this.Verify(); + GlowProcessor p = this.Verify(); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Aquamarine, p.GlowColor); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); } @@ -38,9 +41,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays public void Glow_Radux_GlowProcessorWithDefaultValues() { this.operations.Glow(3.5f); - var p = this.Verify(); + GlowProcessor p = this.Verify(); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Black, p.GlowColor); Assert.Equal(ValueSize.Absolute(3.5f), p.Radius); } @@ -50,11 +53,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays { var rect = new Rectangle(12, 123, 43, 65); this.operations.Glow(rect); - var p = this.Verify(rect); + GlowProcessor p = this.Verify(rect); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Black, p.GlowColor); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index 2484cf0cb8..ebf4fee317 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs @@ -1,9 +1,10 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Overlays; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Primitives; using Xunit; @@ -11,13 +12,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays { public class VignetteTest : BaseImageOperationsExtensionTest { + private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); + [Fact] public void Vignette_VignetteProcessorWithDefaultValues() { this.operations.Vignette(); - var p = this.Verify(); + VignetteProcessor p = this.Verify(); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Black, p.VignetteColor); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); @@ -27,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays public void Vignette_Color_VignetteProcessorWithDefaultValues() { this.operations.Vignette(Color.Aquamarine); - var p = this.Verify(); + VignetteProcessor p = this.Verify(); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Aquamarine, p.VignetteColor); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); @@ -39,9 +42,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays public void Vignette_Radux_VignetteProcessorWithDefaultValues() { this.operations.Vignette(3.5f, 12123f); - var p = this.Verify(); + VignetteProcessor p = this.Verify(); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Black, p.VignetteColor); Assert.Equal(ValueSize.Absolute(3.5f), p.RadiusX); Assert.Equal(ValueSize.Absolute(12123f), p.RadiusY); @@ -52,12 +55,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays { var rect = new Rectangle(12, 123, 43, 65); this.operations.Vignette(rect); - var p = this.Verify(rect); + VignetteProcessor p = this.Verify(rect); - Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions); + Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, graphicsOptionsComparer); Assert.Equal(Color.Black, p.VignetteColor); Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX); Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/TestUtilities/GraphicsOptionsComparer.cs b/tests/ImageSharp.Tests/TestUtilities/GraphicsOptionsComparer.cs new file mode 100644 index 0000000000..248755ea36 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/GraphicsOptionsComparer.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Collections.Generic; + +namespace SixLabors.ImageSharp.Tests.TestUtilities +{ + public class GraphicsOptionsComparer : IEqualityComparer + { + public bool Equals(GraphicsOptions x, GraphicsOptions y) + { + return x.AlphaCompositionMode == y.AlphaCompositionMode + && x.Antialias == y.Antialias + && x.AntialiasSubpixelDepth == y.AntialiasSubpixelDepth + && x.BlendPercentage == y.BlendPercentage + && x.ColorBlendingMode == y.ColorBlendingMode; + } + + public int GetHashCode(GraphicsOptions obj) => obj.GetHashCode(); + } +}