Skip to content

Commit 2b2f610

Browse files
Merge pull request #211 from SixLabors/sw/rich-text
Rich text rendering
2 parents dc7b553 + 5d116ce commit 2b2f610

116 files changed

Lines changed: 1750 additions & 698 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.

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/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
2121
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2222
</PropertyGroup>
23-
23+
2424
<ItemGroup>
2525
<!-- DynamicProxyGenAssembly2 is needed so Moq can use our internals -->
2626
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7" />

src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
<Description>An extension to ImageSharp that allows the drawing of images, paths, and text.</Description>
1414
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;net472</TargetFrameworks>
1515
</PropertyGroup>
16+
1617
<ItemGroup>
1718
<None Include="..\..\shared-infrastructure\branding\icons\imagesharp.drawing\sixlabors.imagesharp.drawing.128.png" Pack="true" PackagePath="" />
1819
</ItemGroup>
1920
<ItemGroup>
20-
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta18" />
21+
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19.10" />
2122
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
2223
</ItemGroup>
2324
<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />

src/ImageSharp.Drawing/Processing/Brush.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
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
78
{
89
/// <summary>
9-
/// Brush represents a logical configuration of a brush which can be used to source pixel colors
10+
/// Represents a logical configuration of a brush which can be used to source pixel colors.
1011
/// </summary>
1112
/// <remarks>
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 abstract class Brush
16+
public abstract class Brush : IEquatable<Brush>
1617
{
1718
/// <summary>
1819
/// Creates the applicator for this brush.
@@ -35,5 +36,8 @@ public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
3536
ImageFrame<TPixel> source,
3637
RectangleF region)
3738
where TPixel : unmanaged, IPixel<TPixel>;
39+
40+
/// <inheritdoc/>
41+
public abstract bool Equals(Brush other);
3842
}
3943
}

src/ImageSharp.Drawing/Processing/Brushes.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,130 +93,131 @@ public static class Brushes
9393
/// </summary>
9494
/// <param name="color">The color.</param>
9595
/// <returns>A New <see cref="PatternBrush"/></returns>
96-
public static SolidBrush Solid(Color color) => new SolidBrush(color);
96+
public static SolidBrush Solid(Color color) => new(color);
9797

9898
/// <summary>
9999
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
100100
/// </summary>
101101
/// <param name="foreColor">Color of the foreground.</param>
102102
/// <returns>A New <see cref="PatternBrush"/></returns>
103-
public static PatternBrush Percent10(Color foreColor) =>
104-
new PatternBrush(foreColor, Color.Transparent, Percent10Pattern);
103+
public static PatternBrush Percent10(Color foreColor)
104+
=> new(foreColor, Color.Transparent, Percent10Pattern);
105105

106106
/// <summary>
107107
/// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
108108
/// </summary>
109109
/// <param name="foreColor">Color of the foreground.</param>
110110
/// <param name="backColor">Color of the background.</param>
111111
/// <returns>A New <see cref="PatternBrush"/></returns>
112-
public static PatternBrush Percent10(Color foreColor, Color backColor) =>
113-
new PatternBrush(foreColor, backColor, Percent10Pattern);
112+
public static PatternBrush Percent10(Color foreColor, Color backColor)
113+
=> new(foreColor, backColor, Percent10Pattern);
114114

115115
/// <summary>
116116
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a
117117
/// transparent background.
118118
/// </summary>
119119
/// <param name="foreColor">Color of the foreground.</param>
120120
/// <returns>A New <see cref="PatternBrush"/></returns>
121-
public static PatternBrush Percent20(Color foreColor) =>
122-
new PatternBrush(foreColor, Color.Transparent, Percent20Pattern);
121+
public static PatternBrush Percent20(Color foreColor)
122+
=> new(foreColor, Color.Transparent, Percent20Pattern);
123123

124124
/// <summary>
125125
/// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors
126126
/// </summary>
127127
/// <param name="foreColor">Color of the foreground.</param>
128128
/// <param name="backColor">Color of the background.</param>
129129
/// <returns>A New <see cref="PatternBrush"/></returns>
130-
public static PatternBrush Percent20(Color foreColor, Color backColor) =>
131-
new PatternBrush(foreColor, backColor, Percent20Pattern);
130+
public static PatternBrush Percent20(Color foreColor, Color backColor)
131+
=> new(foreColor, backColor, Percent20Pattern);
132132

133133
/// <summary>
134134
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a
135135
/// transparent background.
136136
/// </summary>
137137
/// <param name="foreColor">Color of the foreground.</param>
138138
/// <returns>A New <see cref="PatternBrush"/></returns>
139-
public static PatternBrush Horizontal(Color foreColor) =>
140-
new PatternBrush(foreColor, Color.Transparent, HorizontalPattern);
139+
public static PatternBrush Horizontal(Color foreColor)
140+
=> new(foreColor, Color.Transparent, HorizontalPattern);
141141

142142
/// <summary>
143143
/// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors
144144
/// </summary>
145145
/// <param name="foreColor">Color of the foreground.</param>
146146
/// <param name="backColor">Color of the background.</param>
147147
/// <returns>A New <see cref="PatternBrush"/></returns>
148-
public static PatternBrush Horizontal(Color foreColor, Color backColor) =>
149-
new PatternBrush(foreColor, backColor, HorizontalPattern);
148+
public static PatternBrush Horizontal(Color foreColor, Color backColor)
149+
=> new(foreColor, backColor, HorizontalPattern);
150150

151151
/// <summary>
152152
/// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a
153153
/// transparent background.
154154
/// </summary>
155155
/// <param name="foreColor">Color of the foreground.</param>
156156
/// <returns>A New <see cref="PatternBrush"/></returns>
157-
public static PatternBrush Min(Color foreColor) => new PatternBrush(foreColor, Color.Transparent, MinPattern);
157+
public static PatternBrush Min(Color foreColor)
158+
=> new(foreColor, Color.Transparent, MinPattern);
158159

159160
/// <summary>
160161
/// Create as brush that will paint a Min Hatch Pattern with the specified colors
161162
/// </summary>
162163
/// <param name="foreColor">Color of the foreground.</param>
163164
/// <param name="backColor">Color of the background.</param>
164165
/// <returns>A New <see cref="PatternBrush"/></returns>
165-
public static PatternBrush Min(Color foreColor, Color backColor) =>
166-
new PatternBrush(foreColor, backColor, MinPattern);
166+
public static PatternBrush Min(Color foreColor, Color backColor)
167+
=> new(foreColor, backColor, MinPattern);
167168

168169
/// <summary>
169170
/// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a
170171
/// transparent background.
171172
/// </summary>
172173
/// <param name="foreColor">Color of the foreground.</param>
173174
/// <returns>A New <see cref="PatternBrush"/></returns>
174-
public static PatternBrush Vertical(Color foreColor) =>
175-
new PatternBrush(foreColor, Color.Transparent, VerticalPattern);
175+
public static PatternBrush Vertical(Color foreColor)
176+
=> new(foreColor, Color.Transparent, VerticalPattern);
176177

177178
/// <summary>
178179
/// Create as brush that will paint a Vertical Hatch Pattern with the specified colors
179180
/// </summary>
180181
/// <param name="foreColor">Color of the foreground.</param>
181182
/// <param name="backColor">Color of the background.</param>
182183
/// <returns>A New <see cref="PatternBrush"/></returns>
183-
public static PatternBrush Vertical(Color foreColor, Color backColor) =>
184-
new PatternBrush(foreColor, backColor, VerticalPattern);
184+
public static PatternBrush Vertical(Color foreColor, Color backColor)
185+
=> new(foreColor, backColor, VerticalPattern);
185186

186187
/// <summary>
187188
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a
188189
/// transparent background.
189190
/// </summary>
190191
/// <param name="foreColor">Color of the foreground.</param>
191192
/// <returns>A New <see cref="PatternBrush"/></returns>
192-
public static PatternBrush ForwardDiagonal(Color foreColor) =>
193-
new PatternBrush(foreColor, Color.Transparent, ForwardDiagonalPattern);
193+
public static PatternBrush ForwardDiagonal(Color foreColor)
194+
=> new(foreColor, Color.Transparent, ForwardDiagonalPattern);
194195

195196
/// <summary>
196197
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors
197198
/// </summary>
198199
/// <param name="foreColor">Color of the foreground.</param>
199200
/// <param name="backColor">Color of the background.</param>
200201
/// <returns>A New <see cref="PatternBrush"/></returns>
201-
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) =>
202-
new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
202+
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor)
203+
=> new(foreColor, backColor, ForwardDiagonalPattern);
203204

204205
/// <summary>
205206
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a
206207
/// transparent background.
207208
/// </summary>
208209
/// <param name="foreColor">Color of the foreground.</param>
209210
/// <returns>A New <see cref="PatternBrush"/></returns>
210-
public static PatternBrush BackwardDiagonal(Color foreColor) =>
211-
new PatternBrush(foreColor, Color.Transparent, BackwardDiagonalPattern);
211+
public static PatternBrush BackwardDiagonal(Color foreColor)
212+
=> new(foreColor, Color.Transparent, BackwardDiagonalPattern);
212213

213214
/// <summary>
214215
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors
215216
/// </summary>
216217
/// <param name="foreColor">Color of the foreground.</param>
217218
/// <param name="backColor">Color of the background.</param>
218219
/// <returns>A New <see cref="PatternBrush"/></returns>
219-
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) =>
220-
new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
220+
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor)
221+
=> new(foreColor, backColor, BackwardDiagonalPattern);
221222
}
222223
}

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
Brush 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
Brush 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
Brush 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
Brush 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
Brush 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
Brush 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
Brush 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
Brush 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
Brush 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
Brush 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.

0 commit comments

Comments
 (0)