@@ -40,6 +40,7 @@ internal sealed class RichTextGlyphRenderer : BaseGlyphBuilder, IColorGlyphRende
4040 private TextDecorationDetails ? currentUnderline ;
4141 private TextDecorationDetails ? currentStrikout ;
4242 private TextDecorationDetails ? currentOverline ;
43+ private bool currentDecorationsRotated ;
4344
4445 // Just enough accuracy to allow for 1/8 px differences which later are accumulated while rendering,
4546 // but do not grow into full px offsets.
@@ -101,7 +102,7 @@ protected override void BeginText(in FontRectangle bounds)
101102 protected override void BeginGlyph ( in FontRectangle bounds , in GlyphRendererParameters parameters )
102103 {
103104 this . currentColor = null ;
104-
105+ this . currentDecorationsRotated = parameters . LayoutMode . IsVertical ( ) || parameters . LayoutMode . IsVerticalMixed ( ) ;
105106 this . currentTextRun = parameters . TextRun ;
106107 if ( parameters . TextRun is RichTextRun drawingRun )
107108 {
@@ -219,41 +220,37 @@ public override void SetDecoration(TextDecorations textDecorations, Vector2 star
219220 }
220221 }
221222
222- // Clamp the line to whole pixels
223- Vector2 pad = new ( 0 , thickness * .5F ) ;
224- Vector2 tl = start - pad ;
225- Vector2 bl = start + pad ;
226- Vector2 tr = end - pad ;
227-
228- tl = ClampToPixel ( tl ) ;
229- bl = ClampToPixel ( bl ) ;
230- tr = ClampToPixel ( tr ) ;
231-
232223 // Always respect the pen stroke width if explicitly set.
233- if ( pen is null )
234- {
235- thickness = bl . Y - tl . Y ;
236- pen = new SolidPen ( this . currentBrush ?? this . defaultBrush , thickness ) ;
237- }
238- else
224+ if ( pen is not null )
239225 {
240226 thickness = pen . StrokeWidth ;
241227 }
242228
229+ // Center the line at the given position.
230+ bool rotated = this . currentDecorationsRotated ;
231+ Vector2 pad = rotated ? new ( thickness * .5F , 0 ) : new ( 0 , thickness * .5F ) ;
232+ Vector2 a = start - pad ;
233+ Vector2 b = start + pad ;
234+ Vector2 d = end - pad ;
235+ thickness = rotated ? b . X - a . X : b . Y - a . Y ;
236+
237+ pen ??= new SolidPen ( this . currentBrush ?? this . defaultBrush , thickness ) ;
238+
243239 // Drawing is always centered around the point so we need to offset by half.
244240 Vector2 offset = Vector2 . Zero ;
245241 if ( textDecorations == TextDecorations . Overline )
246242 {
247243 // CSS overline is drawn above the position, so we need to move it up.
248- offset = new Vector2 ( 0 , - ( thickness * .5F ) ) ;
244+ offset = rotated ? new ( thickness * .5F , 0 ) : new ( 0 , - ( thickness * .5F ) ) ;
249245 }
250246 else if ( textDecorations == TextDecorations . Underline )
251247 {
252248 // CSS underline is drawn below the position, so we need to move it down.
253- offset = new Vector2 ( 0 , thickness * .5F ) ;
249+ offset = rotated ? new ( - ( thickness * .5F ) , 0 ) : new ( 0 , thickness * .5F ) ;
254250 }
255251
256- this . AppendDecoration ( ref targetDecoration , tl + offset , tr + offset , pen , thickness ) ;
252+ // Clamp the line to whole pixels
253+ this . AppendDecoration ( ref targetDecoration , ClampToPixel ( a + offset ) , ClampToPixel ( d + offset ) , pen , ( float ) Math . Truncate ( thickness ) ) ;
257254 }
258255
259256 protected override void EndGlyph ( )
0 commit comments