Class TextOnPathOptions
How ShapeOnPath(Font, string, Path, TextOnPathOptions?) lays text along a path.
public sealed record TextOnPathOptions : IEquatable<TextOnPathOptions>
- Inheritance
-
TextOnPathOptions
- Implements
- Inherited Members
Examples
// A label along a curve: each glyph's midpoint on the path, turned to its direction, as SVG's textPath. The result is
// still a glyph run, so a PDF backend writes it as searchable text.
Path curve = new PathBuilder().MoveTo(20, 150).CubicTo(80, 20, 240, 20, 300, 150).ToPath();
var font = new Font(face, 18);
using (RasterCanvas<Rgba8> canvas = image.CreateCanvas())
{
canvas.DrawTextOnPath("Text that follows the curve", curve, font, Rgba8.Black,
new TextOnPathOptions { StartFraction = 0.5f, Anchor = TextAnchor.Center, BaselineShift = 4 });
}
// Or place glyphs yourself, each with its own turn and scale.
GlyphRun dial = GlyphRun.CreateTransformed(font, [face.GetGlyph('N'), face.GetGlyph('E')],
[GlyphTransform.FromRotationScale(1, 0, new Vector2(150, 30)), GlyphTransform.FromRotationScale(1, 90, new Vector2(290, 90))]);
Properties
Anchor
Gets how the text sits at the start point. Defaults to Start.
public TextAnchor Anchor { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not defined.
BaselineShift
Gets how far each glyph moves off the path along its normal, in canvas units: positive away from the side the text stands on (up for text above a line). Defaults to 0.
public float BaselineShift { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not finite.
Default
Gets the default options: start at the path's start, anchored at the text's start, on the left side.
public static TextOnPathOptions Default { get; }
Property Value
Side
Gets the side of the path the text stands on. Defaults to Left.
public TextPathSide Side { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not defined.
StartFraction
Gets the start point as a fraction of the path's length, such as 0.5 for its middle, as SVG's percentage startOffset. Defaults to 0.
public float StartFraction { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not finite.
StartOffset
Gets the start point's distance along the path in canvas units, added to StartFraction. Defaults to 0.
public float StartOffset { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not finite.
WrapClosed
Gets whether glyphs past the end of a path of one closed contour wrap round to its start, instead of being dropped. Defaults to false, as SVG.
public bool WrapClosed { get; init; }