@@ -679,20 +679,47 @@ private TextLine[] CreateTextLines()
679
679
680
680
private void UpdateMetrics ( TextLineImpl currentLine , ref bool first )
681
681
{
682
- _metrics . InkBounds = _metrics . InkBounds . Union ( new Rect ( new Point ( 0 , _metrics . Bounds . Bottom ) + currentLine . InkBounds . Position , currentLine . InkBounds . Size ) ) ;
683
- _metrics . Bounds = _metrics . Bounds . Union ( new Rect ( new Point ( 0 , _metrics . Bounds . Bottom ) + currentLine . Bounds . Position , currentLine . Bounds . Size ) ) ;
682
+ // 1) Offset each line’s bounding rectangles by the total height so far,
683
+ // so we keep an overall bounding box for the entire text block.
684
+ var lineTop = _metrics . Height ;
684
685
685
- _metrics . MinTextWidth = Math . Max ( _metrics . MinTextWidth , currentLine . Bounds . Width ) ;
686
- _metrics . MinTextWidth = Math . Max ( _metrics . MinTextWidth , currentLine . InkBounds . Width ) ;
686
+ // Offset the line's Bounds
687
+ var lineBoundsRect = new Rect (
688
+ currentLine . Bounds . X ,
689
+ lineTop + currentLine . Bounds . Y ,
690
+ currentLine . Bounds . Width ,
691
+ currentLine . Bounds . Height ) ;
687
692
688
- _metrics . Height = _metrics . Bounds . Height ;
689
- _metrics . Width = _metrics . InkBounds . Width ;
690
- _metrics . WidthIncludingTrailingWhitespace = _metrics . Bounds . Width ;
691
- _metrics . Extent = _metrics . InkBounds . Height ;
692
- _metrics . OverhangLeading = Math . Max ( 0 , _metrics . Bounds . Left - _metrics . InkBounds . Left ) ;
693
- _metrics . OverhangTrailing = Math . Max ( 0 , _metrics . InkBounds . Right - _metrics . Bounds . Right ) ;
694
- _metrics . OverhangAfter = Math . Max ( 0 , _metrics . InkBounds . Bottom - _metrics . Bounds . Bottom ) ;
693
+ _metrics . Bounds = _metrics . Bounds . Union ( lineBoundsRect ) ;
695
694
695
+ // Offset the line's InkBounds
696
+ var lineInkRect = new Rect (
697
+ currentLine . InkBounds . X ,
698
+ lineTop + currentLine . InkBounds . Y ,
699
+ currentLine . InkBounds . Width ,
700
+ currentLine . InkBounds . Height ) ;
701
+
702
+ _metrics . InkBounds = _metrics . InkBounds . Union ( lineInkRect ) ;
703
+
704
+ // 2) Accumulate total layout height by adding the line’s Height.
705
+ _metrics . Height += currentLine . Height ;
706
+
707
+ // 3) For the layout’s Width and WidthIncludingTrailingWhitespace,
708
+ // use the maximum of the line widths rather than the bounding box.
709
+ _metrics . Width = Math . Max ( _metrics . Width , currentLine . Width ) ;
710
+ _metrics . WidthIncludingTrailingWhitespace = Math . Max ( _metrics . WidthIncludingTrailingWhitespace , currentLine . WidthIncludingTrailingWhitespace ) ;
711
+
712
+ // 4) Extent is the max black-pixel extent among lines.
713
+ _metrics . Extent = Math . Max ( _metrics . Extent , currentLine . Extent ) ;
714
+
715
+ // 5) We can track min-text-width or overhangs similarly if needed.
716
+ _metrics . MinTextWidth = Math . Max ( _metrics . MinTextWidth , currentLine . Width ) ;
717
+
718
+ _metrics . OverhangLeading = Math . Max ( _metrics . OverhangLeading , currentLine . OverhangLeading ) ;
719
+ _metrics . OverhangTrailing = Math . Max ( _metrics . OverhangTrailing , currentLine . OverhangTrailing ) ;
720
+ _metrics . OverhangAfter = Math . Max ( _metrics . OverhangAfter , currentLine . OverhangAfter ) ;
721
+
722
+ // 6) Capture the baseline from the first line.
696
723
if ( first )
697
724
{
698
725
_metrics . Baseline = currentLine . Baseline ;
0 commit comments