Skip to content

Commit deeef2e

Browse files
Push experimental renderer and debugging hacks
1 parent 6eafdf9 commit deeef2e

8 files changed

Lines changed: 613 additions & 29 deletions

File tree

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using SixLabors.Fonts;
88
using SixLabors.Fonts.Unicode;
9+
using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing;
910
using SixLabors.ImageSharp.Memory;
1011
using SixLabors.ImageSharp.PixelFormats;
1112
using SixLabors.ImageSharp.Processing.Processors;
@@ -19,7 +20,8 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Processors.Text
1920
internal class DrawTextProcessor<TPixel> : ImageProcessor<TPixel>
2021
where TPixel : unmanaged, IPixel<TPixel>
2122
{
22-
private CachingGlyphRenderer textRenderer;
23+
// private CachingGlyphRenderer textRenderer;
24+
private RichTextGlyphRenderer textRenderer;
2325
private readonly DrawTextProcessor definition;
2426

2527
public DrawTextProcessor(Configuration configuration, DrawTextProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
@@ -31,16 +33,23 @@ protected override void BeforeImageApply()
3133
base.BeforeImageApply();
3234

3335
// Do everything at the image level as we are delegating the processing down to other processors
34-
this.textRenderer = new CachingGlyphRenderer(
35-
this.Configuration.MemoryAllocator,
36-
this.definition.Text.GetGraphemeCount(),
36+
//this.textRenderer = new CachingGlyphRenderer(
37+
// this.Configuration.MemoryAllocator,
38+
// this.definition.Text.GetGraphemeCount(),
39+
// this.definition.TextOptions,
40+
// this.definition.Pen,
41+
// this.definition.Brush,
42+
// this.definition.DrawingOptions.Transform)
43+
//{
44+
// Options = this.definition.DrawingOptions
45+
//};
46+
47+
this.textRenderer = new RichTextGlyphRenderer(
3748
this.definition.TextOptions,
49+
this.definition.DrawingOptions,
50+
this.Configuration.MemoryAllocator,
3851
this.definition.Pen,
39-
this.definition.Brush,
40-
this.definition.DrawingOptions.Transform)
41-
{
42-
Options = this.definition.DrawingOptions
43-
};
52+
this.definition.Brush);
4453

4554
TextRenderer renderer = new(this.textRenderer);
4655
renderer.RenderText(this.definition.Text, this.definition.TextOptions);
@@ -49,6 +58,17 @@ protected override void BeforeImageApply()
4958
protected override void AfterImageApply()
5059
{
5160
base.AfterImageApply();
61+
62+
foreach (var path in this.textRenderer.Paths)
63+
{
64+
new FillPathProcessor(
65+
this.definition.DrawingOptions,
66+
new SolidBrush(Color.HotPink.WithAlpha(.5F)),
67+
path).Execute(this.Configuration, this.Source, this.SourceRectangle);
68+
}
69+
70+
71+
5272
this.textRenderer?.Dispose();
5373
this.textRenderer = null;
5474
}
@@ -62,7 +82,7 @@ void Draw(IEnumerable<DrawingOperation> operations)
6282
{
6383
using BrushApplicator<TPixel> app = operation.Brush.CreateApplicator(
6484
this.Configuration,
65-
this.textRenderer.Options.GraphicsOptions,
85+
this.definition.DrawingOptions.GraphicsOptions,
6686
source,
6787
this.SourceRectangle);
6888

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using SixLabors.ImageSharp.Advanced;
5+
using SixLabors.ImageSharp.PixelFormats;
6+
using SixLabors.ImageSharp.Processing.Processors;
7+
8+
namespace SixLabors.ImageSharp.Drawing.Processing.Processors.Text
9+
{
10+
internal static class ImageProcessorExtensions
11+
{
12+
/// <summary>
13+
/// Executes the processor against the given source image and rectangle bounds.
14+
/// </summary>
15+
/// <param name="processor">The processor.</param>
16+
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
17+
/// <param name="source">The source image.</param>
18+
/// <param name="sourceRectangle">The source bounds.</param>
19+
public static void Execute(this IImageProcessor processor, Configuration configuration, Image source, Rectangle sourceRectangle)
20+
=> source.AcceptVisitor(new ExecuteVisitor(configuration, processor, sourceRectangle));
21+
22+
private class ExecuteVisitor : IImageVisitor
23+
{
24+
private readonly Configuration configuration;
25+
private readonly IImageProcessor processor;
26+
private readonly Rectangle sourceRectangle;
27+
28+
public ExecuteVisitor(Configuration configuration, IImageProcessor processor, Rectangle sourceRectangle)
29+
{
30+
this.configuration = configuration;
31+
this.processor = processor;
32+
this.sourceRectangle = sourceRectangle;
33+
}
34+
35+
public void Visit<TPixel>(Image<TPixel> image)
36+
where TPixel : unmanaged, IPixel<TPixel>
37+
{
38+
using (IImageProcessor<TPixel> processorImpl = this.processor.CreatePixelSpecificProcessor(this.configuration, image, this.sourceRectangle))
39+
{
40+
processorImpl.Execute();
41+
}
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)