@@ -16,12 +16,14 @@ internal sealed class PathGlyphBuilder : GlyphBuilder
1616 private const float Pi = MathF . PI ;
1717 private readonly IPathInternals path ;
1818 private Vector2 textOffset ;
19+ private TextOptions textOptions ;
1920
2021 /// <summary>
2122 /// Initializes a new instance of the <see cref="PathGlyphBuilder"/> class.
2223 /// </summary>
2324 /// <param name="path">The path to render the glyphs along.</param>
24- public PathGlyphBuilder ( IPath path )
25+ /// <param name="textOptions">The text rendering options.</param>
26+ public PathGlyphBuilder ( IPath path , TextOptions textOptions )
2527 {
2628 if ( path is IPathInternals internals )
2729 {
@@ -31,10 +33,30 @@ public PathGlyphBuilder(IPath path)
3133 {
3234 this . path = new ComplexPolygon ( path ) ;
3335 }
36+
37+ this . textOptions = textOptions ;
3438 }
3539
3640 /// <inheritdoc/>
37- protected override void BeginText ( FontRectangle bounds ) => this . textOffset = new ( bounds . Left , bounds . Bottom ) ;
41+ protected override void BeginText ( FontRectangle bounds )
42+ {
43+ float yOffset = this . textOptions . VerticalAlignment switch
44+ {
45+ VerticalAlignment . Center => bounds . Bottom - ( bounds . Height * .5F ) ,
46+ VerticalAlignment . Bottom => bounds . Bottom ,
47+ VerticalAlignment . Top => bounds . Top ,
48+ _ => bounds . Top ,
49+ } ;
50+
51+ float xOffset = this . textOptions . HorizontalAlignment switch
52+ {
53+ HorizontalAlignment . Center => bounds . Right - ( bounds . Width * .5F ) ,
54+ HorizontalAlignment . Right => bounds . Right ,
55+ HorizontalAlignment . Left => bounds . Left ,
56+ _ => bounds . Left ,
57+ } ;
58+ this . textOffset = new ( xOffset , yOffset ) ;
59+ }
3860
3961 /// <inheritdoc/>
4062 protected override void BeginGlyph ( FontRectangle bounds ) => this . TransformGlyph ( bounds ) ;
0 commit comments