Skip to content

Commit 806d0ab

Browse files
Minor cleanup and comments
1 parent 6942030 commit 806d0ab

9 files changed

Lines changed: 67 additions & 41 deletions

File tree

samples/DrawShapesWithImageSharp/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ private static void OutputStars()
5555

5656
DrawText(
5757
"Hello World Hello World Hello World Hello World Hello World Hello World Hello World",
58-
new EllipsePolygon(PointF.Empty, 100));
59-
// new RectangularPolygon(PointF.Empty, new SizeF(100, 100)));
58+
new EllipsePolygon(PointF.Empty, 100));
6059
}
6160

6261
private static void DrawText(string text)

src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs

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

44
using System;
5-
using SixLabors.Fonts;
65
using SixLabors.ImageSharp.PixelFormats;
76
using SixLabors.ImageSharp.Processing.Processors;
87

@@ -47,7 +46,7 @@ public DrawTextProcessor(DrawingOptions drawingOptions, TextDrawingOptions textO
4746
public DrawingOptions DrawingOptions { get; }
4847

4948
/// <summary>
50-
/// Gets the <see cref="Fonts.TextDrawingOptions"/> defining text-specific drawing settings.
49+
/// Gets the <see cref="Processing.TextDrawingOptions"/> defining text-specific drawing settings.
5150
/// </summary>
5251
public TextDrawingOptions TextOptions { get; }
5352

src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ private struct TextDecorationDetails
152152
public float Thickness { get; internal set; }
153153
}
154154

155+
// TODO: Why doesn't this inherit BaseGlyphBuilder?
156+
// Ideally we should look to making text drawing capable of rendering rich text along a path.
155157
private class CachingGlyphRenderer : IColorGlyphRenderer, IGlyphDecorationRenderer, IDisposable
156158
{
157-
158-
159159
// just enough accuracy to allow for 1/8 pixel differences which
160160
// later are accumulated while rendering, but do not grow into full pixel offsets
161161
// The value 8 is benchmarked to:
@@ -273,7 +273,7 @@ public void SetDecoration(TextDecorations textDecorations, Vector2 start, Vector
273273
}
274274

275275
// TODO:Isn't this already handled in font via GetEnds?
276-
//fix up the thickness/Y position so that the line render nicly
276+
// fix up the thickness/Y position so that the line render nicly
277277
var thicknessOffset = new Vector2(0, thickness * .5f);
278278
var tl = start - thicknessOffset;
279279
var bl = start + thicknessOffset;
@@ -613,8 +613,6 @@ public void QuadraticBezierTo(Vector2 secondControlPoint, Vector2 point)
613613
this.currentPoint = point;
614614
}
615615

616-
617-
618616
private struct GlyphRenderData : IDisposable
619617
{
620618
public Color? Color;

src/ImageSharp.Drawing/Processing/SolidPen.cs

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

4-
using System.Diagnostics.CodeAnalysis;
5-
64
namespace SixLabors.ImageSharp.Drawing.Processing
75
{
86
/// <summary>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Collections.Generic;
5+
using SixLabors.Fonts;
6+
7+
namespace SixLabors.ImageSharp.Drawing.Processing
8+
{
9+
/// <summary>
10+
/// Provides configuration options for rendering and shaping of drawable text.
11+
/// </summary>
12+
public class TextDrawingOptions : TextOptions
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="TextDrawingOptions" /> class.
16+
/// </summary>
17+
/// <param name="font">The font.</param>
18+
public TextDrawingOptions(Font font)
19+
: base(font)
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="TextDrawingOptions" /> class from properties
25+
/// copied from the given instance.
26+
/// </summary>
27+
/// <param name="options">The options whose properties are copied into this instance.</param>
28+
public TextDrawingOptions(TextDrawingOptions options)
29+
: base(options)
30+
{
31+
}
32+
33+
/// <summary>
34+
/// Gets or sets an optional collection of text runs to apply to the body of text.
35+
/// </summary>
36+
public new IReadOnlyList<TextDrawingRun> TextRuns
37+
{
38+
get => (IReadOnlyList<TextDrawingRun>)base.TextRuns;
39+
set => base.TextRuns = value;
40+
}
41+
}
42+
}
Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,38 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Text;
74
using SixLabors.Fonts;
8-
using SixLabors.ImageSharp.Drawing.Processing;
95

10-
namespace SixLabors.Fonts
6+
namespace SixLabors.ImageSharp.Drawing.Processing
117
{
12-
public class TextDrawingOptions : TextOptions
13-
{
14-
public TextDrawingOptions(Font font)
15-
: base(font)
16-
{
17-
}
18-
19-
public TextDrawingOptions(TextDrawingOptions options)
20-
: base(options)
21-
{
22-
}
23-
24-
public new IReadOnlyList<TextDrawingRun> TextRuns
25-
{
26-
get => (IReadOnlyList<TextDrawingRun>)base.TextRuns;
27-
set => base.TextRuns = value;
28-
}
29-
}
30-
8+
/// <summary>
9+
/// Represents a run of drawable text spanning a series of graphemes within a string.
10+
/// </summary>
3111
public class TextDrawingRun : TextRun
3212
{
13+
/// <summary>
14+
/// Gets or sets the brush used for filling this run.
15+
/// </summary>
3316
public IBrush Brush { get; set; }
3417

18+
/// <summary>
19+
/// Gets or sets the pen used for outlining this run.
20+
/// </summary>
3521
public IPen Pen { get; set; }
3622

23+
/// <summary>
24+
/// Gets or sets the pen used for drawing strikeout features for this run.
25+
/// </summary>
3726
public IPen StrikeoutPen { get; set; }
3827

28+
/// <summary>
29+
/// Gets or sets the pen used for drawing underline features for this run.
30+
/// </summary>
3931
public IPen UnderlinePen { get; set; }
4032

33+
/// <summary>
34+
/// Gets or sets the pen used for drawing overline features for this run.
35+
/// </summary>
4136
public IPen OverlinePen { get; set; }
42-
43-
public TextDrawingRun()
44-
{
45-
}
4637
}
4738
}

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

Lines changed: 1 addition & 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 SixLabors.Fonts;
5+
using SixLabors.ImageSharp.Drawing.Processing;
56
using SixLabors.ImageSharp.Drawing.Text;
67

78
namespace SixLabors.ImageSharp.Drawing

tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawText.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Drawing.Drawing2D;
66
using System.Linq;
77
using BenchmarkDotNet.Attributes;
8-
using SixLabors.Fonts;
98
using SixLabors.ImageSharp.Drawing.Processing;
109
using SixLabors.ImageSharp.PixelFormats;
1110
using SixLabors.ImageSharp.Processing;

tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawTextOutline.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Drawing.Drawing2D;
66
using System.Linq;
77
using BenchmarkDotNet.Attributes;
8-
using SixLabors.Fonts;
98
using SixLabors.ImageSharp.Drawing.Processing;
109
using SixLabors.ImageSharp.PixelFormats;
1110
using SixLabors.ImageSharp.Processing;

0 commit comments

Comments
 (0)