File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1413,6 +1413,7 @@ void BreakLines()
14131413
14141414 // Skip line breaks
14151415 bool breakLine = false ;
1416+ bool isRequired = false ;
14161417 while ( lbrIndex < lineBreakPositions . Count )
14171418 {
14181419 // Past this run?
@@ -1447,6 +1448,7 @@ void BreakLines()
14471448 if ( lbr . Required )
14481449 {
14491450 breakLine = true ;
1451+ isRequired = true ;
14501452 break ;
14511453 }
14521454 }
@@ -1475,10 +1477,24 @@ void BreakLines()
14751477 fr = _fontRuns [ frIndex ] ;
14761478 var room = _maxWidthResolved - fr . XCoord ;
14771479 frSplitIndex = frIndex ;
1478- codePointIndexSplit = fr . FindBreakPosition ( room , frSplitIndex == frIndexStartOfLine ) ;
1479- codePointIndexWrap = codePointIndexSplit ;
1480- while ( codePointIndexWrap < _codePoints . Length && UnicodeClasses . LineBreakClass ( _codePoints [ codePointIndexWrap ] ) == LineBreakClass . SP )
1481- codePointIndexWrap ++ ;
1480+
1481+ var hasValidLinebreak = codePointIndexSplit >= fr . Start && codePointIndexSplit <= fr . End ;
1482+
1483+ // Only break at character if there is no required line break we can use.
1484+ if ( ! ( isRequired && hasValidLinebreak ) )
1485+ {
1486+ var breakPosition = fr . FindBreakPosition ( room , frSplitIndex == frIndexStartOfLine ) ;
1487+
1488+ // Prefer breaking at a character rather than a line break position.
1489+ if ( ! hasValidLinebreak || breakPosition > codePointIndexSplit )
1490+ {
1491+ codePointIndexSplit = breakPosition ;
1492+ codePointIndexWrap = codePointIndexSplit ;
1493+ while ( codePointIndexWrap < _codePoints . Length &&
1494+ UnicodeClasses . LineBreakClass ( _codePoints [ codePointIndexWrap ] ) == LineBreakClass . SP )
1495+ codePointIndexWrap ++ ;
1496+ }
1497+ }
14821498 }
14831499
14841500 // Split it
You can’t perform that action at this time.
0 commit comments