@@ -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,9 +145,11 @@ 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
- var height = blocks . Max ( b => b . Location . Y ) ;
150
+ var height = blocks . Any ( )
151
+ ? blocks . Max ( b => b . Location . Y )
152
+ : 0 ;
150
153
var maxLineHeight = 0.0 ;
151
154
for ( int i = blocks . Count - 1 ; i >= 0 ; i -- )
152
155
{
@@ -170,7 +173,7 @@ public XSize CalculateTextSize(IEnumerable<TextSegment> textSegments, double wid
170
173
return new XSize ( calculatedWith , height + maxLineHeight ) ;
171
174
}
172
175
173
- private void ProcessTextSegments ( IEnumerable < TextSegment > textSegments , XRect layoutRectangle , XStringFormat format , Action < Block , double , double > applyBlock )
176
+ private void ProcessTextSegments ( IEnumerable < TextSegment > textSegments , XRect layoutRectangle , XStringFormat format , Action < Block , double , double > applyBlock , bool applyBlockIfLineBreak )
174
177
{
175
178
if ( textSegments . All ( ts => string . IsNullOrEmpty ( ts . Text ) ) )
176
179
{
@@ -242,7 +245,7 @@ private void ProcessTextSegments(IEnumerable<TextSegment> textSegments, XRect la
242
245
break ;
243
246
}
244
247
245
- if ( block . Type == BlockType . LineBreak )
248
+ if ( block . Type == BlockType . LineBreak && ! applyBlockIfLineBreak )
246
249
{
247
250
continue ;
248
251
}
@@ -397,6 +400,9 @@ private void CreateLayout(List<List<Block>> blockUnits, XRect layoutRectangle)
397
400
398
401
break ;
399
402
}
403
+
404
+ // necessary to correctly calculate closing line breaks
405
+ block . Location = new XPoint ( 0 , y ) ;
400
406
}
401
407
else
402
408
{
0 commit comments