Skip to content

Commit 46234fc

Browse files
committed
Render decorators
- Split pattened and solid pens - Add pen aware apis for text decorations - Add abbility fro pen to have no width and inherit a default value while generating outline
1 parent 31ccd1d commit 46234fc

46 files changed

Lines changed: 694 additions & 166 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static IImageProcessingContext DrawBeziers(
5353
IBrush brush,
5454
float thickness,
5555
params PointF[] points) =>
56-
source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
56+
source.Draw(options, new SolidPen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
5757

5858
/// <summary>
5959
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
@@ -68,7 +68,7 @@ public static IImageProcessingContext DrawBeziers(
6868
IBrush brush,
6969
float thickness,
7070
params PointF[] points) =>
71-
source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
71+
source.Draw(new SolidPen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
7272

7373
/// <summary>
7474
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush

src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static IImageProcessingContext DrawLines(
2525
IBrush brush,
2626
float thickness,
2727
params PointF[] points) =>
28-
source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
28+
source.Draw(options, new SolidPen(brush, thickness), new Path(new LinearLineSegment(points)));
2929

3030
/// <summary>
3131
/// Draws the provided points as an open linear path at the provided thickness with the supplied brush.
@@ -40,7 +40,7 @@ public static IImageProcessingContext DrawLines(
4040
IBrush brush,
4141
float thickness,
4242
params PointF[] points) =>
43-
source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
43+
source.Draw(new SolidPen(brush, thickness), new Path(new LinearLineSegment(points)));
4444

4545
/// <summary>
4646
/// Draws the provided points as an open linear path at the provided thickness with the supplied brush.

src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static IImageProcessingContext Draw(
5858
IBrush brush,
5959
float thickness,
6060
IPathCollection paths) =>
61-
source.Draw(options, new Pen(brush, thickness), paths);
61+
source.Draw(options, new SolidPen(brush, thickness), paths);
6262

6363
/// <summary>
6464
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@@ -73,7 +73,7 @@ public static IImageProcessingContext Draw(
7373
IBrush brush,
7474
float thickness,
7575
IPathCollection paths) =>
76-
source.Draw(new Pen(brush, thickness), paths);
76+
source.Draw(new SolidPen(brush, thickness), paths);
7777

7878
/// <summary>
7979
/// Draws the outline of the polygon with the provided brush at the provided thickness.

src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static IImageProcessingContext Draw(
5151
IBrush brush,
5252
float thickness,
5353
IPath path) =>
54-
source.Draw(options, new Pen(brush, thickness), path);
54+
source.Draw(options, new SolidPen(brush, thickness), path);
5555

5656
/// <summary>
5757
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@@ -66,7 +66,7 @@ public static IImageProcessingContext Draw(
6666
IBrush brush,
6767
float thickness,
6868
IPath path) =>
69-
source.Draw(new Pen(brush, thickness), path);
69+
source.Draw(new SolidPen(brush, thickness), path);
7070

7171
/// <summary>
7272
/// Draws the outline of the polygon with the provided brush at the provided thickness.

src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static IImageProcessingContext DrawPolygon(
5353
IBrush brush,
5454
float thickness,
5555
params PointF[] points) =>
56-
source.DrawPolygon(options, new Pen(brush, thickness), points);
56+
source.DrawPolygon(options, new SolidPen(brush, thickness), points);
5757

5858
/// <summary>
5959
/// Draws the provided points as a closed linear polygon with the provided brush at the provided thickness.
@@ -68,7 +68,7 @@ public static IImageProcessingContext DrawPolygon(
6868
IBrush brush,
6969
float thickness,
7070
params PointF[] points) =>
71-
source.DrawPolygon(new Pen(brush, thickness), points);
71+
source.DrawPolygon(new SolidPen(brush, thickness), points);
7272

7373
/// <summary>
7474
/// Draws the provided points as a closed linear polygon with the provided brush at the provided thickness.

src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static IImageProcessingContext Draw(
5050
IBrush brush,
5151
float thickness,
5252
RectangleF shape) =>
53-
source.Draw(options, new Pen(brush, thickness), shape);
53+
source.Draw(options, new SolidPen(brush, thickness), shape);
5454

5555
/// <summary>
5656
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
@@ -65,7 +65,7 @@ public static IImageProcessingContext Draw(
6565
IBrush brush,
6666
float thickness,
6767
RectangleF shape) =>
68-
source.Draw(new Pen(brush, thickness), shape);
68+
source.Draw(new SolidPen(brush, thickness), shape);
6969

7070
/// <summary>
7171
/// Draws the outline of the rectangle with the provided brush at the provided thickness.

src/ImageSharp.Drawing/Processing/GradientBrush.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5+
using System.Linq;
56
using System.Numerics;
67
using SixLabors.ImageSharp.Drawing.Utilities;
78
using SixLabors.ImageSharp.Memory;
@@ -33,6 +34,18 @@ protected GradientBrush(GradientRepetitionMode repetitionMode, params ColorStop[
3334
/// </summary>
3435
protected ColorStop[] ColorStops { get; }
3536

37+
/// <inheritdoc />
38+
public bool Equals(IBrush other)
39+
{
40+
if (other is GradientBrush sb)
41+
{
42+
return sb.RepetitionMode == this.RepetitionMode &&
43+
Enumerable.SequenceEqual(sb.ColorStops, this.ColorStops);
44+
}
45+
46+
return false;
47+
}
48+
3649
/// <inheritdoc />
3750
public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
3851
Configuration configuration,

src/ImageSharp.Drawing/Processing/IBrush.cs

Lines changed: 2 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;
45
using SixLabors.ImageSharp.PixelFormats;
56

67
namespace SixLabors.ImageSharp.Drawing.Processing
@@ -12,7 +13,7 @@ namespace SixLabors.ImageSharp.Drawing.Processing
1213
/// A brush is a simple class that will return an <see cref="BrushApplicator{TPixel}" /> that will perform the
1314
/// logic for retrieving pixel values for specific locations.
1415
/// </remarks>
15-
public interface IBrush
16+
public interface IBrush : IEquatable<IBrush>
1617
{
1718
/// <summary>
1819
/// Creates the applicator for this brush.

src/ImageSharp.Drawing/Processing/IPen.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,40 @@ namespace SixLabors.ImageSharp.Drawing.Processing
88
/// <summary>
99
/// Interface representing the pattern and size of the stroke to apply with a Pen.
1010
/// </summary>
11-
public interface IPen
11+
public interface IPen : IEquatable<IPen>
1212
{
1313
/// <summary>
1414
/// Gets the stroke fill.
1515
/// </summary>
1616
IBrush StrokeFill { get; }
1717

18-
/// <summary>
19-
/// Gets the width to apply to the stroke
20-
/// </summary>
21-
float StrokeWidth { get; }
18+
///// <summary>
19+
///// Gets the width to apply to the stroke
20+
///// </summary>
21+
//float StrokeWidth { get; }
2222

23-
/// <summary>
24-
/// Gets the stoke pattern.
25-
/// </summary>
26-
ReadOnlySpan<float> StrokePattern { get; }
23+
///// <summary>
24+
///// Gets the stoke pattern.
25+
///// </summary>
26+
//ReadOnlySpan<float> StrokePattern { get; }
2727

28-
/// <summary>
29-
/// Gets or sets the stroke joint style
30-
/// </summary>
31-
public JointStyle JointStyle { get; set; }
28+
///// <summary>
29+
///// Gets or sets the stroke joint style
30+
///// </summary>
31+
//public JointStyle JointStyle { get; set; }
32+
33+
///// <summary>
34+
///// Gets or sets the stroke endcap style
35+
///// </summary>
36+
//public EndCapStyle EndCapStyle { get; set; }
3237

3338
/// <summary>
34-
/// Gets or sets the stroke endcap style
39+
/// Applies the styleing from the pen to a path and generate a new path with the final vector.
3540
/// </summary>
36-
public EndCapStyle EndCapStyle { get; set; }
41+
/// <param name="path">the source path</param>
42+
/// <param name="defaultWidth">the default width to apply if the pen does not have one.</param>
43+
/// <returns>the path withthe pen styleing applied</returns>
44+
public IPath GeneratePath(IPath path, float? defaultWidth = null);
45+
3746
}
3847
}

src/ImageSharp.Drawing/Processing/ImageBrush.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ internal ImageBrush(Image image, RectangleF region)
4646
this.region = region;
4747
}
4848

49+
/// <inheritdoc />
50+
public bool Equals(IBrush other)
51+
{
52+
if (other is ImageBrush sb)
53+
{
54+
return sb.image == this.image && sb.region == this.region;
55+
}
56+
57+
return false;
58+
}
59+
4960
/// <inheritdoc />
5061
public BrushApplicator<TPixel> CreateApplicator<TPixel>(
5162
Configuration configuration,

0 commit comments

Comments
 (0)