@@ -85,7 +85,8 @@ public void DrawString(IEnumerable<TextSegment> textSegments, XRect layoutRectan
85
85
textSegments ,
86
86
layoutRectangle ,
87
87
format ,
88
- ( block , dx , dy ) => _gfx . DrawString ( block . Text , block . Environment . Font , block . Environment . Brush , dx + block . Location . X , dy + block . Location . Y )
88
+ ( block , dx , dy ) => _gfx . DrawString ( block . Text , block . Environment . Font , block . Environment . Brush , dx + block . Location . X , dy + block . Location . Y ) ,
89
+ false
89
90
) ;
90
91
}
91
92
@@ -144,7 +145,7 @@ public XSize CalculateTextSize(IEnumerable<TextSegment> textSegments, double wid
144
145
var layoutRectangle = new XRect ( 0 , 0 , width , 100000000 ) ;
145
146
var blocks = new List < Block > ( ) ;
146
147
147
- ProcessTextSegments ( textSegments , layoutRectangle , format , ( block , dx , dy ) => blocks . Add ( block ) ) ;
148
+ ProcessTextSegments ( textSegments , layoutRectangle , format , ( block , dx , dy ) => blocks . Add ( block ) , true ) ;
148
149
149
150
var height = blocks . Max ( b => b . Location . Y ) ;
150
151
var maxLineHeight = 0.0 ;
@@ -170,7 +171,7 @@ public XSize CalculateTextSize(IEnumerable<TextSegment> textSegments, double wid
170
171
return new XSize ( calculatedWith , height + maxLineHeight ) ;
171
172
}
172
173
173
- private void ProcessTextSegments ( IEnumerable < TextSegment > textSegments , XRect layoutRectangle , XStringFormat format , Action < Block , double , double > applyBlock )
174
+ private void ProcessTextSegments ( IEnumerable < TextSegment > textSegments , XRect layoutRectangle , XStringFormat format , Action < Block , double , double > applyBlock , bool applyBlockIfLineBreak )
174
175
{
175
176
if ( textSegments . All ( ts => string . IsNullOrEmpty ( ts . Text ) ) )
176
177
{
@@ -242,7 +243,7 @@ private void ProcessTextSegments(IEnumerable<TextSegment> textSegments, XRect la
242
243
break ;
243
244
}
244
245
245
- if ( block . Type == BlockType . LineBreak )
246
+ if ( block . Type == BlockType . LineBreak && ! applyBlockIfLineBreak )
246
247
{
247
248
continue ;
248
249
}
@@ -397,6 +398,9 @@ private void CreateLayout(List<List<Block>> blockUnits, XRect layoutRectangle)
397
398
398
399
break ;
399
400
}
401
+
402
+ // necessary to correctly calculate closing line breaks
403
+ block . Location = new XPoint ( 0 , y ) ;
400
404
}
401
405
else
402
406
{
0 commit comments