@@ -116,7 +116,7 @@ public class TextRenderer : AbstractRenderer, ILeafElementRenderer {
116116
117117 private int specialScriptFirstNotFittingIndex = - 1 ;
118118
119- private bool layoutUntilTheLastPossibleBreak = false ;
119+ private int firstIndexExceedingAvailableWidth = - 1 ;
120120
121121 /// <summary>Creates a TextRenderer from its corresponding layout object.</summary>
122122 /// <param name="textElement">
@@ -303,8 +303,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
303303 == mode ) {
304304 containsPossibleBreak = true ;
305305 }
306- if ( ind + 1 == text . end || nextGlyphIsSpaceOrWhiteSpace ) {
307- if ( ind + 1 == text . end && layoutUntilTheLastPossibleBreak ) {
306+ if ( ind + 1 == text . end || nextGlyphIsSpaceOrWhiteSpace || ( ind + 1 >= firstIndexExceedingAvailableWidth &&
307+ firstIndexExceedingAvailableWidth != - 1 ) ) {
308+ if ( ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != - 1 ) {
308309 firstCharacterWhichExceedsAllowedWidth = currentTextPos ;
309310 break ;
310311 }
@@ -386,8 +387,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
386387 containsPossibleBreak = true ;
387388 }
388389 if ( ind + 1 == text . end || endOfNonBreakablePartCausedBySplitCharacter || endOfWordBelongingToSpecialScripts
389- ) {
390- if ( ind + 1 == text . end && layoutUntilTheLastPossibleBreak && ! endOfNonBreakablePartCausedBySplitCharacter
390+ || ( ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != - 1 ) ) {
391+ if ( ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != - 1 && ! endOfNonBreakablePartCausedBySplitCharacter
391392 ) {
392393 firstCharacterWhichExceedsAllowedWidth = currentTextPos ;
393394 }
@@ -440,7 +441,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
440441 // cannot fit a word as a whole
441442 bool wordSplit = false ;
442443 bool hyphenationApplied = false ;
443- if ( hyphenationConfig != null && ! layoutUntilTheLastPossibleBreak ) {
444+ if ( hyphenationConfig != null && firstIndexExceedingAvailableWidth == - 1 ) {
444445 if ( - 1 == nonBreakingHyphenRelatedChunkStart ) {
445446 int [ ] wordBounds = GetWordBoundsForHyphenation ( text , currentTextPos , text . end , Math . Max ( currentTextPos , firstCharacterWhichExceedsAllowedWidth
446447 - 1 ) ) ;
@@ -841,7 +842,7 @@ public override void Draw(DrawContext drawContext) {
841842 if ( horizontalScaling != null && horizontalScaling != 1 ) {
842843 canvas . SetHorizontalScaling ( ( float ) horizontalScaling * 100 ) ;
843844 }
844- GlyphLine . IGlyphLineFilter filter = new _IGlyphLineFilter_909 ( ) ;
845+ GlyphLine . IGlyphLineFilter filter = new _IGlyphLineFilter_912 ( ) ;
845846 bool appearanceStreamLayout = true . Equals ( GetPropertyAsBoolean ( Property . APPEARANCE_STREAM_LAYOUT ) ) ;
846847 if ( GetReversedRanges ( ) != null ) {
847848 bool writeReversedChars = ! appearanceStreamLayout ;
@@ -903,8 +904,8 @@ public override void Draw(DrawContext drawContext) {
903904 }
904905 }
905906
906- private sealed class _IGlyphLineFilter_909 : GlyphLine . IGlyphLineFilter {
907- public _IGlyphLineFilter_909 ( ) {
907+ private sealed class _IGlyphLineFilter_912 : GlyphLine . IGlyphLineFilter {
908+ public _IGlyphLineFilter_912 ( ) {
908909 }
909910
910911 public bool Accept ( Glyph glyph ) {
@@ -1250,8 +1251,8 @@ internal virtual int GetSpecialScriptFirstNotFittingIndex() {
12501251 return specialScriptFirstNotFittingIndex ;
12511252 }
12521253
1253- internal virtual void SetLayoutUntilTheLastPossibleBreak ( bool layoutUntilTheLastPossibleBreak ) {
1254- this . layoutUntilTheLastPossibleBreak = layoutUntilTheLastPossibleBreak ;
1254+ internal virtual void SetFirstIndexExceedingAvailableWidth ( int firstIndexExceedingAvailableWidth ) {
1255+ this . firstIndexExceedingAvailableWidth = firstIndexExceedingAvailableWidth ;
12551256 }
12561257
12571258 protected internal override Rectangle GetBackgroundArea ( Rectangle occupiedAreaWithMargins ) {
0 commit comments