Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6e61579
wip : Enable rich text
tocsoft Mar 4, 2022
adce707
normalize brush use
tocsoft Mar 4, 2022
6849908
always set calculate currentBrush
tocsoft Mar 4, 2022
31ccd1d
Fix issues related to 'bad' version of OpenSans
tocsoft Mar 5, 2022
46234fc
Render decorators
tocsoft Mar 6, 2022
5f11770
dotty underline
tocsoft Mar 6, 2022
159e672
Update enum names
JimBobSquarePants Mar 7, 2022
43c15e7
Merge branch 'main' into sw/rich-text
JimBobSquarePants Apr 16, 2022
caa08a6
Update ImageSharp.Drawing.csproj
JimBobSquarePants Apr 16, 2022
6942030
Fix build
JimBobSquarePants Apr 16, 2022
806d0ab
Minor cleanup and comments
JimBobSquarePants Apr 16, 2022
8c36d8c
Merge branch 'main' into sw/rich-text
JimBobSquarePants Oct 17, 2022
e4315e4
Update to latest Fonts
JimBobSquarePants Oct 30, 2022
b06732f
Fix build
JimBobSquarePants Oct 30, 2022
1f0765d
Merge branch 'main' into sw/rich-text
JimBobSquarePants Jan 26, 2023
6336d01
Attempt to fix funky LFS behavior
JimBobSquarePants Mar 8, 2023
b5eeb6b
Merge branch 'main' into sw/rich-text
JimBobSquarePants Mar 8, 2023
f136c25
Normalize and fix build
JimBobSquarePants Mar 9, 2023
a5f86ac
Fix corrupted LFS files
JimBobSquarePants Mar 9, 2023
6eafdf9
Update to latest Fonts
JimBobSquarePants Mar 13, 2023
deeef2e
Push experimental renderer and debugging hacks
JimBobSquarePants Mar 14, 2023
ab96c2e
RichTextGlyphRenderer works!
JimBobSquarePants Mar 15, 2023
89e0c67
Add caching
JimBobSquarePants Mar 15, 2023
38ecd48
Fix path handling and add basic test
JimBobSquarePants Mar 15, 2023
3ab04f1
Remove old renderer
JimBobSquarePants Mar 15, 2023
5a04d6a
Update Pens.cs
JimBobSquarePants Mar 15, 2023
e2e1efb
Rename options
JimBobSquarePants Mar 15, 2023
852ea38
Cleanup and update tests
JimBobSquarePants Mar 15, 2023
b3f997c
Update RichTextOptions.cs
JimBobSquarePants Mar 15, 2023
61a99a7
Fix restore sources
JimBobSquarePants Mar 15, 2023
a2b83d7
Re-jig feed sources config
JimBobSquarePants Mar 15, 2023
9fc9b65
Use a nuget.config file
JimBobSquarePants Mar 15, 2023
00b054f
Update ref and fix line rendering
JimBobSquarePants Mar 16, 2023
91fe704
Normalize pixel clamping
JimBobSquarePants Mar 16, 2023
5e91132
Update test refs
JimBobSquarePants Mar 16, 2023
f6dbef1
Fix multiline rendering
JimBobSquarePants Mar 16, 2023
5d116ce
Pixel perfect cached glyphs.
JimBobSquarePants Mar 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions samples/DrawShapesWithImageSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ private static void OutputStars()

DrawText(
"Hello World Hello World Hello World Hello World Hello World Hello World Hello World",
new EllipsePolygon(PointF.Empty, 100));
// new RectangularPolygon(PointF.Empty, new SizeF(100, 100)));
new EllipsePolygon(PointF.Empty, 100));
}

private static void DrawText(string text)
{
FontFamily fam = SystemFonts.Get("Arial");
var font = new Font(fam, 30);
TextOptions textOptions = new(font);
TextDrawingOptions textOptions = new(font);
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions);

glyphs.SaveImage("Text", text + ".png");
Expand All @@ -73,7 +72,7 @@ private static void DrawText(string text, IPath path)
{
FontFamily family = SystemFonts.Get("Arial");
Font font = new(family, 30);
TextOptions textOptions = new(font)
TextDrawingOptions textOptions = new(font)
{
WrappingLength = path.ComputeLength(),
VerticalAlignment = VerticalAlignment.Top,
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<None Include="..\..\shared-infrastructure\branding\icons\imagesharp.drawing\sixlabors.imagesharp.drawing.128.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta18" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>
<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static IImageProcessingContext DrawBeziers(
IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
source.Draw(options, new SolidPen(brush, thickness), new Path(new CubicBezierLineSegment(points)));

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

/// <summary>
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IImageProcessingContext DrawLines(
IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
source.Draw(options, new SolidPen(brush, thickness), new Path(new LinearLineSegment(points)));

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

/// <summary>
/// Draws the provided points as an open linear path at the provided thickness with the supplied brush.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static IImageProcessingContext Draw(
IBrush brush,
float thickness,
IPathCollection paths) =>
source.Draw(options, new Pen(brush, thickness), paths);
source.Draw(options, new SolidPen(brush, thickness), paths);

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

/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static IImageProcessingContext Draw(
IBrush brush,
float thickness,
IPath path) =>
source.Draw(options, new Pen(brush, thickness), path);
source.Draw(options, new SolidPen(brush, thickness), path);

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

/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static IImageProcessingContext DrawPolygon(
IBrush brush,
float thickness,
params PointF[] points) =>
source.DrawPolygon(options, new Pen(brush, thickness), points);
source.DrawPolygon(options, new SolidPen(brush, thickness), points);

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

/// <summary>
/// Draws the provided points as a closed linear polygon with the provided brush at the provided thickness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static IImageProcessingContext Draw(
IBrush brush,
float thickness,
RectangleF shape) =>
source.Draw(options, new Pen(brush, thickness), shape);
source.Draw(options, new SolidPen(brush, thickness), shape);

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

/// <summary>
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static IImageProcessingContext DrawText(
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextOptions textOptions,
TextDrawingOptions textOptions,
string text,
Color color) =>
source.DrawText(textOptions, text, Brushes.Solid(color), null);
Expand Down Expand Up @@ -115,7 +115,7 @@ public static IImageProcessingContext DrawText(
IPen pen,
PointF location)
{
TextOptions textOptions = new(font) { Origin = location };
TextDrawingOptions textOptions = new(font) { Origin = location };
return source.DrawText(textOptions, text, brush, pen);
}

Expand All @@ -129,7 +129,7 @@ public static IImageProcessingContext DrawText(
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextOptions textOptions,
TextDrawingOptions textOptions,
string text,
IBrush brush) =>
source.DrawText(source.GetDrawingOptions(), textOptions, text, brush, null);
Expand All @@ -144,7 +144,7 @@ public static IImageProcessingContext DrawText(
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextOptions textOptions,
TextDrawingOptions textOptions,
string text,
IPen pen) =>
source.DrawText(source.GetDrawingOptions(), textOptions, text, null, pen);
Expand All @@ -160,7 +160,7 @@ public static IImageProcessingContext DrawText(
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextOptions textOptions,
TextDrawingOptions textOptions,
string text,
IBrush brush,
IPen pen) =>
Expand Down Expand Up @@ -224,7 +224,7 @@ public static IImageProcessingContext DrawText(
IPen pen,
PointF location)
{
TextOptions textOptions = new(font) { Origin = location };
TextDrawingOptions textOptions = new(font) { Origin = location };
return source.ApplyProcessor(new DrawTextProcessor(drawingOptions, textOptions, text, brush, pen));
}

Expand All @@ -241,7 +241,7 @@ public static IImageProcessingContext DrawText(
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
DrawingOptions drawingOptions,
TextOptions textOptions,
TextDrawingOptions textOptions,
string text,
IBrush brush,
IPen pen)
Expand Down
13 changes: 13 additions & 0 deletions src/ImageSharp.Drawing/Processing/GradientBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Utilities;
using SixLabors.ImageSharp.Memory;
Expand Down Expand Up @@ -33,6 +34,18 @@ protected GradientBrush(GradientRepetitionMode repetitionMode, params ColorStop[
/// </summary>
protected ColorStop[] ColorStops { get; }

/// <inheritdoc />
public bool Equals(IBrush other)
{
if (other is GradientBrush sb)
{
return sb.RepetitionMode == this.RepetitionMode &&
Enumerable.SequenceEqual(sb.ColorStops, this.ColorStops);
}

return false;
}

/// <inheritdoc />
public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
Configuration configuration,
Expand Down
3 changes: 2 additions & 1 deletion src/ImageSharp.Drawing/Processing/IBrush.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System;
using SixLabors.ImageSharp.PixelFormats;

namespace SixLabors.ImageSharp.Drawing.Processing
Expand All @@ -12,7 +13,7 @@ namespace SixLabors.ImageSharp.Drawing.Processing
/// A brush is a simple class that will return an <see cref="BrushApplicator{TPixel}" /> that will perform the
/// logic for retrieving pixel values for specific locations.
/// </remarks>
public interface IBrush
public interface IBrush : IEquatable<IBrush>
{
/// <summary>
/// Creates the applicator for this brush.
Expand Down
39 changes: 24 additions & 15 deletions src/ImageSharp.Drawing/Processing/IPen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,40 @@ namespace SixLabors.ImageSharp.Drawing.Processing
/// <summary>
/// Interface representing the pattern and size of the stroke to apply with a Pen.
/// </summary>
public interface IPen
public interface IPen : IEquatable<IPen>
{
/// <summary>
/// Gets the stroke fill.
/// </summary>
IBrush StrokeFill { get; }

/// <summary>
/// Gets the width to apply to the stroke
/// </summary>
float StrokeWidth { get; }
///// <summary>
///// Gets the width to apply to the stroke
///// </summary>
//float StrokeWidth { get; }

/// <summary>
/// Gets the stoke pattern.
/// </summary>
ReadOnlySpan<float> StrokePattern { get; }
///// <summary>
///// Gets the stoke pattern.
///// </summary>
//ReadOnlySpan<float> StrokePattern { get; }

/// <summary>
/// Gets or sets the stroke joint style
/// </summary>
public JointStyle JointStyle { get; set; }
///// <summary>
///// Gets or sets the stroke joint style
///// </summary>
//public JointStyle JointStyle { get; set; }

///// <summary>
///// Gets or sets the stroke endcap style
///// </summary>
//public EndCapStyle EndCapStyle { get; set; }

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

}
}
11 changes: 11 additions & 0 deletions src/ImageSharp.Drawing/Processing/ImageBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ internal ImageBrush(Image image, RectangleF region)
this.region = region;
}

/// <inheritdoc />
public bool Equals(IBrush other)
{
if (other is ImageBrush sb)
{
return sb.image == this.image && sb.region == this.region;
}

return false;
}

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator<TPixel>(
Configuration configuration,
Expand Down
20 changes: 19 additions & 1 deletion src/ImageSharp.Drawing/Processing/PathGradientBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Utilities;
Expand Down Expand Up @@ -77,6 +78,17 @@ public PathGradientBrush(PointF[] points, Color[] colors, Color centerColor)
this.hasSpecialCenterColor = true;
}

/// <inheritdoc />
public bool Equals(IBrush other)
{
if (other is PathGradientBrush sb)
{
return Enumerable.SequenceEqual(sb.edges, this.edges);
}

return false;
}

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator<TPixel>(
Configuration configuration,
Expand Down Expand Up @@ -127,7 +139,7 @@ public Intersection(PointF point, float distance)
/// <summary>
/// An edge of the polygon that represents the gradient area.
/// </summary>
private class Edge
private class Edge : IEquatable<Edge>
{
private readonly float length;

Expand Down Expand Up @@ -163,6 +175,12 @@ public Vector4 ColorAt(float distance)
}

public Vector4 ColorAt(PointF point) => this.ColorAt(DistanceBetween(point, this.Start));

public bool Equals(Edge other)
=> other.Start == this.Start &&
other.End == this.End &&
other.StartColor.Equals(this.StartColor) &&
other.EndColor.Equals(this.EndColor);
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions src/ImageSharp.Drawing/Processing/PatternBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Utilities;
using SixLabors.ImageSharp.Memory;
Expand Down Expand Up @@ -86,6 +87,18 @@ internal PatternBrush(PatternBrush brush)
this.patternVector = brush.patternVector;
}

/// <inheritdoc />
public bool Equals(IBrush other)
{
if (other is PatternBrush sb)
{
return sb.pattern.Equals(this.pattern) &&
sb.patternVector.Equals(this.patternVector);
}

return false;
}

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator<TPixel>(
Configuration configuration,
Expand Down
Loading