-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCustomGlyphBuilder.cs
More file actions
50 lines (40 loc) · 1.34 KB
/
CustomGlyphBuilder.cs
File metadata and controls
50 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.Fonts;
using SixLabors.Fonts.Rendering;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Text;
namespace DrawWithImageSharp;
/// <summary>
/// A custom glyph builder used to render character and text bounds.
/// </summary>
internal class CustomGlyphBuilder : GlyphBuilder
{
private readonly List<FontRectangle> glyphBounds = [];
public CustomGlyphBuilder()
{
}
public CustomGlyphBuilder(Vector2 origin)
: base(origin)
{
}
/// <summary>
/// Gets the paths that have been rendered by this.
/// </summary>
public IPathCollection Boxes => new PathCollection(this.glyphBounds.Select(x => new RectangularPolygon(x.X, x.Y, x.Width, x.Height)));
/// <summary>
/// Gets the paths that have been rendered by this builder.
/// </summary>
public IPath TextBox { get; private set; }
protected override void BeginText(in FontRectangle bounds)
{
this.TextBox = new RectangularPolygon(bounds.X, bounds.Y, bounds.Width, bounds.Height);
base.BeginText(bounds);
}
protected override void BeginGlyph(in FontRectangle bounds, in GlyphRendererParameters parameters)
{
this.glyphBounds.Add(bounds);
base.BeginText(bounds);
}
}