diff --git a/src/ImageSharp.Drawing/Primitives/ShapePath.cs b/src/ImageSharp.Drawing/Primitives/ShapePath.cs
index 2a569f061..7aae2bf8e 100644
--- a/src/ImageSharp.Drawing/Primitives/ShapePath.cs
+++ b/src/ImageSharp.Drawing/Primitives/ShapePath.cs
@@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Primitives
/// The pen to apply to the shape.
// TODO: SixLabors.shape will be moving to a Span/ReadOnlySpan based API shortly use ToArray for now.
public ShapePath(IPath shape, IPen pen)
- : base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern.ToArray()))
+ : base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern))
{
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextOnPathProcessor.cs b/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextOnPathProcessor.cs
index 6c33d306b..1e703d1cc 100644
--- a/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextOnPathProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextOnPathProcessor.cs
@@ -82,25 +82,18 @@ namespace SixLabors.ImageSharp.Processing.Text.Processors
{
ApplyKerning = this.Options.ApplyKerning,
TabWidth = this.Options.TabWidth,
- WrappingWidth = this.Options.WrapTextWidth,
+ WrappingWidth = this.Path.Length,
HorizontalAlignment = this.Options.HorizontalAlignment,
VerticalAlignment = this.Options.VerticalAlignment
};
IPathCollection glyphs = TextBuilder.GenerateGlyphs(this.Text, this.Path, style);
+ this.fillRegionProcessor = new FillRegionProcessor();
+ this.fillRegionProcessor.Options = (GraphicsOptions)this.Options;
- var pathOptions = (GraphicsOptions)this.Options;
if (this.Brush != null)
{
- // we will reuse the processor for all fill operations to reduce allocations
- if (this.fillRegionProcessor == null)
- {
- this.fillRegionProcessor = new FillRegionProcessor()
- {
- Brush = this.Brush,
- Options = pathOptions
- };
- }
+ this.fillRegionProcessor.Brush = this.Brush;
foreach (IPath p in glyphs)
{
@@ -111,15 +104,7 @@ namespace SixLabors.ImageSharp.Processing.Text.Processors
if (this.Pen != null)
{
- // we will reuse the processor for all fill operations to reduce allocations
- if (this.fillRegionProcessor == null)
- {
- this.fillRegionProcessor = new FillRegionProcessor()
- {
- Brush = this.Brush,
- Options = pathOptions
- };
- }
+ this.fillRegionProcessor.Brush = this.Pen.StrokeFill;
foreach (IPath p in glyphs)
{
diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs
index 400917f7a..a1a9b0222 100644
--- a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs
+++ b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs
@@ -17,10 +17,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
using System;
using System.Linq;
using System.Text;
+ using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
+ using SixLabors.Shapes;
[GroupOutput("Drawing/Text")]
public class DrawTextOnImageTests
@@ -163,6 +165,45 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
appendSourceFileOrDescription: true);
}
+
+ [Theory]
+ [WithSolidFilledImages(200, 100, "White", PixelTypes.Rgba32, 50, "SixLaborsSampleAB.woff", AB)]
+ [WithSolidFilledImages(900, 100, "White", PixelTypes.Rgba32, 50, "OpenSans-Regular.ttf", TestText)]
+ public void FontShapesAreRenderedCorrectlyAlongAPath(
+ TestImageProvider provider,
+ int fontSize,
+ string fontName,
+ string text)
+ where TPixel : struct, IPixel
+ {
+
+ Font font = CreateFont(fontName, fontSize);
+ string fnDisplayText = text.Replace("\n", "");
+ fnDisplayText = fnDisplayText.Substring(0, Math.Min(fnDisplayText.Length, 4));
+ TPixel colorOutline = NamedColors.Black;
+ TPixel colorFill = NamedColors.Gray;
+
+ provider.VerifyOperation(
+ ImageComparer.Tolerant(imageThreshold: 0.1f, perPixelManhattanThreshold: 20),
+ img =>
+ {
+
+ IPath path = new Path(new LinearLineSegment(new Point(0, img.Height), new Point(img.Width, 0)));
+ img.Mutate(c => c.DrawText(
+ new TextGraphicsOptions {
+ HorizontalAlignment = HorizontalAlignment.Center,
+ VerticalAlignment = VerticalAlignment.Top
+ } ,
+ text, new Font(font, fontSize),
+ Brushes.Solid(colorFill)
+ , Pens.DashDot(colorOutline, 3),
+ path));
+ },
+ $"pen_{fontName}-{fontSize}-{fnDisplayText}",
+ appendPixelTypeToFileName: false,
+ appendSourceFileOrDescription: true);
+ }
+
private static string Repeat(string str, int times) => string.Concat(Enumerable.Repeat(str, times));
private static Font CreateFont(string fontName, int size)
diff --git a/tests/Images/External b/tests/Images/External
index 09059fae2..83f6cbab9 160000
--- a/tests/Images/External
+++ b/tests/Images/External
@@ -1 +1 @@
-Subproject commit 09059fae2d8bea3a4c9288ab10fb184f1b648f40
+Subproject commit 83f6cbab9a08b550c84bf931c95188341140516a