@@ -391,12 +391,23 @@ private static IEnumerable<GlyphLayout> LayoutLineHorizontal(
391
391
TextLine . GlyphLayoutData data = textLine [ i ] ;
392
392
if ( data . IsNewLine )
393
393
{
394
+ glyphs . Add ( new GlyphLayout (
395
+ new Glyph ( data . Metrics [ 0 ] , data . PointSize ) ,
396
+ boxLocation ,
397
+ penLocation ,
398
+ Vector2 . Zero ,
399
+ data . ScaledAdvance ,
400
+ yLineAdvance ,
401
+ GlyphLayoutMode . Horizontal ,
402
+ true ,
403
+ data . GraphemeIndex ,
404
+ data . StringIndex ) ) ;
405
+
394
406
penLocation . X = originX ;
395
407
penLocation . Y += yLineAdvance ;
396
-
397
408
boxLocation . X = originX ;
398
409
boxLocation . Y += advanceY ;
399
- continue ;
410
+ return glyphs ;
400
411
}
401
412
402
413
int j = 0 ;
@@ -524,12 +535,23 @@ private static IEnumerable<GlyphLayout> LayoutLineVertical(
524
535
TextLine . GlyphLayoutData data = textLine [ i ] ;
525
536
if ( data . IsNewLine )
526
537
{
538
+ glyphs . Add ( new GlyphLayout (
539
+ new Glyph ( data . Metrics [ 0 ] , data . PointSize ) ,
540
+ boxLocation ,
541
+ penLocation ,
542
+ Vector2 . Zero ,
543
+ xLineAdvance ,
544
+ data . ScaledAdvance ,
545
+ GlyphLayoutMode . Vertical ,
546
+ true ,
547
+ data . GraphemeIndex ,
548
+ data . StringIndex ) ) ;
549
+
527
550
boxLocation . X += advanceX ;
528
551
boxLocation . Y = originY ;
529
-
530
552
penLocation . X += xLineAdvance ;
531
553
penLocation . Y = originY ;
532
- continue ;
554
+ return glyphs ;
533
555
}
534
556
535
557
int j = 0 ;
@@ -671,12 +693,23 @@ private static IEnumerable<GlyphLayout> LayoutLineVerticalMixed(
671
693
TextLine . GlyphLayoutData data = textLine [ i ] ;
672
694
if ( data . IsNewLine )
673
695
{
696
+ glyphs . Add ( new GlyphLayout (
697
+ new Glyph ( data . Metrics [ 0 ] , data . PointSize ) ,
698
+ boxLocation ,
699
+ penLocation ,
700
+ Vector2 . Zero ,
701
+ xLineAdvance ,
702
+ data . ScaledAdvance ,
703
+ GlyphLayoutMode . Vertical ,
704
+ true ,
705
+ data . GraphemeIndex ,
706
+ data . StringIndex ) ) ;
707
+
674
708
boxLocation . X += advanceX ;
675
709
boxLocation . Y = originY ;
676
-
677
710
penLocation . X += xLineAdvance ;
678
711
penLocation . Y = originY ;
679
- continue ;
712
+ return glyphs ;
680
713
}
681
714
682
715
if ( data . IsTransformed )
@@ -1170,10 +1203,30 @@ VerticalOrientationType.Rotate or
1170
1203
{
1171
1204
// Mandatory line break at index.
1172
1205
TextLine remaining = textLine . SplitAt ( i ) ;
1173
- textLines . Add ( textLine . Finalize ( options ) ) ;
1174
- textLine = remaining ;
1175
- i = - 1 ;
1176
- lineAdvance = 0 ;
1206
+
1207
+ if ( shouldWrap && textLine . ScaledLineAdvance - glyph . ScaledAdvance > wrappingLength )
1208
+ {
1209
+ // We've overshot the wrapping length so we need to split the line
1210
+ // at the previous break and add both lines.
1211
+ TextLine overflow = textLine . SplitAt ( lastLineBreak , keepAll ) ;
1212
+ if ( overflow != textLine )
1213
+ {
1214
+ textLines . Add ( textLine . Finalize ( options ) ) ;
1215
+ textLine = overflow ;
1216
+ }
1217
+
1218
+ textLines . Add ( textLine . Finalize ( options ) ) ;
1219
+ textLine = remaining ;
1220
+ i = - 1 ;
1221
+ lineAdvance = 0 ;
1222
+ }
1223
+ else
1224
+ {
1225
+ textLines . Add ( textLine . Finalize ( options ) ) ;
1226
+ textLine = remaining ;
1227
+ i = - 1 ;
1228
+ lineAdvance = 0 ;
1229
+ }
1177
1230
}
1178
1231
else if ( shouldWrap )
1179
1232
{
@@ -1201,7 +1254,7 @@ VerticalOrientationType.Rotate or
1201
1254
{
1202
1255
// If the current break is a space, and the line minus the space
1203
1256
// is less than the wrapping length, we can break using the current break.
1204
- float previousAdvance = lineAdvance - ( float ) glyph . ScaledAdvance ;
1257
+ float previousAdvance = lineAdvance - glyph . ScaledAdvance ;
1205
1258
TextLine . GlyphLayoutData lastGlyph = textLine [ i - 1 ] ;
1206
1259
if ( CodePoint . IsWhiteSpace ( lastGlyph . CodePoint ) )
1207
1260
{
@@ -1463,8 +1516,9 @@ public TextLine SplitAt(LineBreak lineBreak, bool keepAll)
1463
1516
1464
1517
private void TrimTrailingWhitespace ( )
1465
1518
{
1466
- int index = this . data . Count ;
1467
- while ( index > 0 )
1519
+ int count = this . data . Count ;
1520
+ int index = count ;
1521
+ while ( index > 1 )
1468
1522
{
1469
1523
// Trim trailing breaking whitespace.
1470
1524
CodePoint point = this . data [ index - 1 ] . CodePoint ;
@@ -1476,9 +1530,9 @@ private void TrimTrailingWhitespace()
1476
1530
index -- ;
1477
1531
}
1478
1532
1479
- if ( index < this . data . Count && index != 0 )
1533
+ if ( index < count )
1480
1534
{
1481
- this . data . RemoveRange ( index , this . data . Count - index ) ;
1535
+ this . data . RemoveRange ( index , count - index ) ;
1482
1536
}
1483
1537
}
1484
1538
0 commit comments