Skip to content

Commit 29b2be9

Browse files
committed
merge extensions classes
1 parent f2a2e35 commit 29b2be9

2 files changed

Lines changed: 60 additions & 71 deletions

File tree

src/ImageSharp.Drawing/Processing/DrawingOptionsDefaultsExtensions.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System.Numerics;
45
using SixLabors.ImageSharp.Processing;
56

67
namespace SixLabors.ImageSharp.Drawing.Processing
@@ -10,12 +11,70 @@ namespace SixLabors.ImageSharp.Drawing.Processing
1011
/// </summary>
1112
public static class DrawingOptionsDefaultsExtensions
1213
{
14+
private const string DrawingTransformMatrixKey = "DrawingTransformMatrix3x2";
15+
1316
/// <summary>
1417
/// Gets the default shape processing options against the image processing context.
1518
/// </summary>
1619
/// <param name="context">The image processing context to retrieve defaults from.</param>
17-
/// <returns>The globaly configured default options.</returns>
20+
/// <returns>The globally configured default options.</returns>
1821
public static DrawingOptions GetDrawingOptions(this IImageProcessingContext context)
1922
=> new DrawingOptions(context.GetGraphicsOptions(), context.GetShapeOptions(), context.GetTextOptions(), context.GetDrawingTransform());
23+
24+
/// <summary>
25+
/// Sets the 2D transformation matrix to be used during rasterization when drawing shapes or text.
26+
/// </summary>
27+
/// <param name="context">The image processing context to store default against.</param>
28+
/// <param name="matrix">The matrix to use.</param>
29+
/// <returns>The passed in <paramref name="context"/> to allow chaining.</returns>
30+
public static IImageProcessingContext SetDrawingTransform(this IImageProcessingContext context, Matrix3x2 matrix)
31+
{
32+
context.Properties[DrawingTransformMatrixKey] = matrix;
33+
return context;
34+
}
35+
36+
/// <summary>
37+
/// Sets the default 2D transformation matrix to be used during rasterization when drawing shapes or text.
38+
/// </summary>
39+
/// <param name="configuration">The configuration to store default against.</param>
40+
/// <param name="matrix">The default matrix to use.</param>
41+
public static void SetDrawingTransform(this Configuration configuration, Matrix3x2 matrix)
42+
{
43+
configuration.Properties[DrawingTransformMatrixKey] = matrix;
44+
}
45+
46+
/// <summary>
47+
/// Gets the default 2D transformation matrix to be used during rasterization when drawing shapes or text.
48+
/// </summary>
49+
/// <param name="context">The image processing context to retrieve defaults from.</param>
50+
/// <returns>The matrix.</returns>
51+
public static Matrix3x2 GetDrawingTransform(this IImageProcessingContext context)
52+
{
53+
if (context.Properties.TryGetValue(DrawingTransformMatrixKey, out var options) && options is Matrix3x2 go)
54+
{
55+
return go;
56+
}
57+
58+
var matrix = context.Configuration.GetDrawingTransform();
59+
60+
// do not cache the fall back to config into the processing context
61+
// in case someone want to change the value on the config and expects it re-flow thru.
62+
return matrix;
63+
}
64+
65+
/// <summary>
66+
/// Gets the default 2D transformation matrix to be used during rasterization when drawing shapes or text.
67+
/// </summary>
68+
/// <param name="configuration">The configuration to retrieve defaults from.</param>
69+
/// <returns>The globally configured default matrix.</returns>
70+
public static Matrix3x2 GetDrawingTransform(this Configuration configuration)
71+
{
72+
if (configuration.Properties.TryGetValue(DrawingTransformMatrixKey, out var options) && options is Matrix3x2 go)
73+
{
74+
return go;
75+
}
76+
77+
return Matrix3x2.Identity;
78+
}
2079
}
2180
}

src/ImageSharp.Drawing/Processing/DrawingTransformDefaultsExtensions.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)