Skip to content

Commit 832e0f5

Browse files
Cleanup
1 parent 92b641b commit 832e0f5

4 files changed

Lines changed: 30 additions & 32 deletions

File tree

src/ImageSharp.Drawing/Shapes/PathBuilder.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Drawing
1313
/// </summary>
1414
public class PathBuilder
1515
{
16-
private readonly List<Figure> figures = new List<Figure>();
16+
private readonly List<Figure> figures = new();
1717
private readonly Matrix3x2 defaultTransform;
1818
private Figure currentFigure = null;
1919
private Matrix3x2 currentTransform;
@@ -57,7 +57,7 @@ public PathBuilder SetTransform(Matrix3x2 translation)
5757
/// <returns>The <see cref="PathBuilder"/></returns>
5858
public PathBuilder SetOrigin(PointF origin)
5959
{
60-
// the new origin should be transofrmed based on the default transform
60+
// The new origin should be transformed based on the default transform
6161
this.setTransform.Translation = origin;
6262
this.currentTransform = this.setTransform * this.defaultTransform;
6363

@@ -207,7 +207,8 @@ public PathBuilder AddBezier(PointF startPoint, PointF controlPoint1, PointF con
207207
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
208208
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
209209
/// <returns>The <see cref="PathBuilder"/></returns>
210-
public PathBuilder AddEllipticalArc(RectangleF rect, float rotation, float startAngle, float sweepAngle) => this.AddEllipticalArc((rect.Right + rect.Left) / 2, (rect.Bottom + rect.Top) / 2, rect.Width / 2, rect.Height / 2, rotation, startAngle, sweepAngle);
210+
public PathBuilder AddEllipticalArc(RectangleF rect, float rotation, float startAngle, float sweepAngle)
211+
=> this.AddEllipticalArc((rect.Right + rect.Left) / 2, (rect.Bottom + rect.Top) / 2, rect.Width / 2, rect.Height / 2, rotation, startAngle, sweepAngle);
211212

212213
/// <summary>
213214
/// Adds an elliptical arc to the current figure
@@ -217,7 +218,8 @@ public PathBuilder AddBezier(PointF startPoint, PointF controlPoint1, PointF con
217218
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
218219
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
219220
/// <returns>The <see cref="PathBuilder"/></returns>
220-
public PathBuilder AddEllipticalArc(Rectangle rect, int rotation, int startAngle, int sweepAngle) => this.AddEllipticalArc((float)(rect.Right + rect.Left) / 2, (float)(rect.Bottom + rect.Top) / 2, (float)rect.Width / 2, (float)rect.Height / 2, rotation, startAngle, sweepAngle);
221+
public PathBuilder AddEllipticalArc(Rectangle rect, int rotation, int startAngle, int sweepAngle)
222+
=> this.AddEllipticalArc((float)(rect.Right + rect.Left) / 2, (float)(rect.Bottom + rect.Top) / 2, (float)rect.Width / 2, (float)rect.Height / 2, rotation, startAngle, sweepAngle);
221223

222224
/// <summary>
223225
/// Adds an elliptical arc to the current figure
@@ -229,7 +231,8 @@ public PathBuilder AddBezier(PointF startPoint, PointF controlPoint1, PointF con
229231
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
230232
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
231233
/// <returns>The <see cref="PathBuilder"/></returns>
232-
public PathBuilder AddEllipticalArc(PointF center, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle) => this.AddEllipticalArc(center.X, center.Y, radiusX, radiusY, rotation, startAngle, sweepAngle);
234+
public PathBuilder AddEllipticalArc(PointF center, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle)
235+
=> this.AddEllipticalArc(center.X, center.Y, radiusX, radiusY, rotation, startAngle, sweepAngle);
233236

234237
/// <summary>
235238
/// Adds an elliptical arc to the current figure
@@ -241,7 +244,8 @@ public PathBuilder AddBezier(PointF startPoint, PointF controlPoint1, PointF con
241244
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
242245
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
243246
/// <returns>The <see cref="PathBuilder"/></returns>
244-
public PathBuilder AddEllipticalArc(Point center, int radiusX, int radiusY, int rotation, int startAngle, int sweepAngle) => this.AddEllipticalArc(center.X, center.Y, radiusX, radiusY, rotation, startAngle, sweepAngle);
247+
public PathBuilder AddEllipticalArc(Point center, int radiusX, int radiusY, int rotation, int startAngle, int sweepAngle)
248+
=> this.AddEllipticalArc(center.X, center.Y, radiusX, radiusY, rotation, startAngle, sweepAngle);
245249

246250
/// <summary>
247251
/// Adds an elliptical arc to the current figure

src/ImageSharp.Drawing/Shapes/Text/BaseGlyphBuilder.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,24 @@ namespace SixLabors.ImageSharp.Drawing.Text
1212
/// </summary>
1313
internal class BaseGlyphBuilder : IGlyphRenderer
1414
{
15-
#pragma warning disable SA1401 // Fields should be private
16-
/// <summary>
17-
/// The builder. TODO: Should this be a property?
18-
/// </summary>
19-
// ReSharper disable once InconsistentNaming
20-
protected readonly PathBuilder builder;
21-
#pragma warning restore SA1401 // Fields should be private
2215
private readonly List<IPath> paths = new();
23-
private Vector2 currentPoint = default;
16+
private Vector2 currentPoint;
2417

2518
/// <summary>
2619
/// Initializes a new instance of the <see cref="BaseGlyphBuilder"/> class.
2720
/// </summary>
28-
public BaseGlyphBuilder() => this.builder = new PathBuilder();
21+
public BaseGlyphBuilder() => this.Builder = new PathBuilder();
2922

3023
/// <summary>
31-
/// Gets the paths that have been rendered by this.
24+
/// Gets the paths that have been rendered by the current instance.
3225
/// </summary>
3326
public IPathCollection Paths => new PathCollection(this.paths);
3427

28+
/// <summary>
29+
/// Gets the path builder for the current instance.
30+
/// </summary>
31+
protected PathBuilder Builder { get; }
32+
3533
/// <inheritdoc/>
3634
void IGlyphRenderer.EndText()
3735
{
@@ -43,15 +41,15 @@ void IGlyphRenderer.EndText()
4341
/// <inheritdoc/>
4442
bool IGlyphRenderer.BeginGlyph(FontRectangle bounds, GlyphRendererParameters paramaters)
4543
{
46-
this.builder.Clear();
44+
this.Builder.Clear();
4745
this.BeginGlyph(bounds);
4846
return true;
4947
}
5048

5149
/// <summary>
5250
/// Begins the figure.
5351
/// </summary>
54-
void IGlyphRenderer.BeginFigure() => this.builder.StartFigure();
52+
void IGlyphRenderer.BeginFigure() => this.Builder.StartFigure();
5553

5654
/// <summary>
5755
/// Draws a cubic bezier from the current point to the <paramref name="point"/>
@@ -61,27 +59,27 @@ bool IGlyphRenderer.BeginGlyph(FontRectangle bounds, GlyphRendererParameters par
6159
/// <param name="point">The point.</param>
6260
void IGlyphRenderer.CubicBezierTo(Vector2 secondControlPoint, Vector2 thirdControlPoint, Vector2 point)
6361
{
64-
this.builder.AddBezier(this.currentPoint, secondControlPoint, thirdControlPoint, point);
62+
this.Builder.AddBezier(this.currentPoint, secondControlPoint, thirdControlPoint, point);
6563
this.currentPoint = point;
6664
}
6765

6866
/// <summary>
6967
/// Ends the glyph.
7068
/// </summary>
71-
void IGlyphRenderer.EndGlyph() => this.paths.Add(this.builder.Build());
69+
void IGlyphRenderer.EndGlyph() => this.paths.Add(this.Builder.Build());
7270

7371
/// <summary>
7472
/// Ends the figure.
7573
/// </summary>
76-
void IGlyphRenderer.EndFigure() => this.builder.CloseFigure();
74+
void IGlyphRenderer.EndFigure() => this.Builder.CloseFigure();
7775

7876
/// <summary>
7977
/// Draws a line from the current point to the <paramref name="point"/>.
8078
/// </summary>
8179
/// <param name="point">The point.</param>
8280
void IGlyphRenderer.LineTo(Vector2 point)
8381
{
84-
this.builder.AddLine(this.currentPoint, point);
82+
this.Builder.AddLine(this.currentPoint, point);
8583
this.currentPoint = point;
8684
}
8785

@@ -91,7 +89,7 @@ void IGlyphRenderer.LineTo(Vector2 point)
9189
/// <param name="point">The point.</param>
9290
void IGlyphRenderer.MoveTo(Vector2 point)
9391
{
94-
this.builder.StartFigure();
92+
this.Builder.StartFigure();
9593
this.currentPoint = point;
9694
}
9795

@@ -102,7 +100,7 @@ void IGlyphRenderer.MoveTo(Vector2 point)
102100
/// <param name="point">The point.</param>
103101
void IGlyphRenderer.QuadraticBezierTo(Vector2 secondControlPoint, Vector2 point)
104102
{
105-
this.builder.AddBezier(this.currentPoint, secondControlPoint, point);
103+
this.Builder.AddBezier(this.currentPoint, secondControlPoint, point);
106104
this.currentPoint = point;
107105
}
108106

src/ImageSharp.Drawing/Shapes/Text/GlyphBuilder.cs

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

44
using System.Numerics;
@@ -22,10 +22,6 @@ public GlyphBuilder()
2222
/// Initializes a new instance of the <see cref="GlyphBuilder"/> class.
2323
/// </summary>
2424
/// <param name="origin">The origin.</param>
25-
public GlyphBuilder(Vector2 origin)
26-
: base()
27-
{
28-
this.builder.SetOrigin(origin);
29-
}
25+
public GlyphBuilder(Vector2 origin) => this.Builder.SetOrigin(origin);
3026
}
3127
}

src/ImageSharp.Drawing/Shapes/Text/PathGlyphBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override void BeginText(FontRectangle bounds)
4747
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4848
private void TransformGlyph(FontRectangle bounds)
4949
{
50-
// Find the intersection point. This should be offset to ensure we rotate at the center of the glyph.
50+
// Find the intersection point. This should be offset to ensure we rotate at the bottom-center of the glyph.
5151
float halfWidth = (bounds.Right - bounds.Left) * .5F;
5252
Vector2 intersectPoint = new(bounds.Left + halfWidth, bounds.Top);
5353

@@ -60,7 +60,7 @@ private void TransformGlyph(FontRectangle bounds)
6060
// Due to how matrix combining works you have to combine this in the reverse order of operation.
6161
// First rotate the glyph then move it.
6262
Matrix3x2 matrix = Matrix3x2.CreateTranslation(targetPoint - bounds.Location) * Matrix3x2.CreateRotation(pathPoint.Angle - Pi, pathPoint.Point);
63-
this.builder.SetTransform(matrix);
63+
this.Builder.SetTransform(matrix);
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)