@@ -55,14 +55,14 @@ source product.
5555
5656namespace iText . Layout . Renderer {
5757 public class LineRenderer : AbstractRenderer {
58+ private const float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f ;
59+
5860 protected internal float maxAscent ;
5961
6062 protected internal float maxDescent ;
6163
6264 protected internal byte [ ] levels ;
6365
64- private const float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f ;
65-
6666 private float maxTextAscent ;
6767
6868 private float maxTextDescent ;
@@ -71,8 +71,8 @@ public class LineRenderer : AbstractRenderer {
7171
7272 private float maxBlockDescent ;
7373
74- // bidi levels
7574 // AbstractRenderer.EPS is not enough here
75+ // bidi levels
7676 public override LayoutResult Layout ( LayoutContext layoutContext ) {
7777 Rectangle layoutBox = layoutContext . GetArea ( ) . GetBBox ( ) . Clone ( ) ;
7878 bool wasParentsHeightClipped = layoutContext . IsClippedHeight ( ) ;
@@ -375,28 +375,45 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
375375 }
376376 }
377377 }
378- maxAscent = Math . Max ( maxAscent , childAscent ) ;
379- if ( childRenderer is TextRenderer ) {
380- maxTextAscent = Math . Max ( maxTextAscent , childAscent ) ;
381- }
382- else {
383- if ( ! isChildFloating ) {
384- maxBlockAscent = Math . Max ( maxBlockAscent , childAscent ) ;
378+ bool newLineOccurred = ( childResult is TextLayoutResult && ( ( TextLayoutResult ) childResult ) . IsSplitForcedByNewline
379+ ( ) ) ;
380+ bool shouldBreakLayouting = childResult . GetStatus ( ) != LayoutResult . FULL || newLineOccurred ;
381+ bool wordWasSplitAndItWillFitOntoNextLine = false ;
382+ if ( shouldBreakLayouting && childResult is TextLayoutResult && ( ( TextLayoutResult ) childResult ) . IsWordHasBeenSplit
383+ ( ) ) {
384+ if ( wasXOverflowChanged ) {
385+ SetProperty ( Property . OVERFLOW_X , oldXOverflow ) ;
386+ }
387+ LayoutResult newLayoutResult = childRenderer . Layout ( new LayoutContext ( new LayoutArea ( layoutContext . GetArea
388+ ( ) . GetPageNumber ( ) , layoutBox ) , wasParentsHeightClipped ) ) ;
389+ if ( wasXOverflowChanged ) {
390+ SetProperty ( Property . OVERFLOW_X , OverflowPropertyValue . FIT ) ;
391+ }
392+ if ( newLayoutResult is TextLayoutResult && ! ( ( TextLayoutResult ) newLayoutResult ) . IsWordHasBeenSplit ( ) ) {
393+ wordWasSplitAndItWillFitOntoNextLine = true ;
385394 }
386395 }
387- maxDescent = Math . Min ( maxDescent , childDescent ) ;
388- if ( childRenderer is TextRenderer ) {
389- maxTextDescent = Math . Min ( maxTextDescent , childDescent ) ;
390- }
391- else {
392- if ( ! isChildFloating ) {
393- maxBlockDescent = Math . Min ( maxBlockDescent , childDescent ) ;
396+ if ( ! wordWasSplitAndItWillFitOntoNextLine ) {
397+ maxAscent = Math . Max ( maxAscent , childAscent ) ;
398+ if ( childRenderer is TextRenderer ) {
399+ maxTextAscent = Math . Max ( maxTextAscent , childAscent ) ;
400+ }
401+ else {
402+ if ( ! isChildFloating ) {
403+ maxBlockAscent = Math . Max ( maxBlockAscent , childAscent ) ;
404+ }
405+ }
406+ maxDescent = Math . Min ( maxDescent , childDescent ) ;
407+ if ( childRenderer is TextRenderer ) {
408+ maxTextDescent = Math . Min ( maxTextDescent , childDescent ) ;
409+ }
410+ else {
411+ if ( ! isChildFloating ) {
412+ maxBlockDescent = Math . Min ( maxBlockDescent , childDescent ) ;
413+ }
394414 }
395415 }
396416 float maxHeight = maxAscent - maxDescent ;
397- bool newLineOccurred = ( childResult is TextLayoutResult && ( ( TextLayoutResult ) childResult ) . IsSplitForcedByNewline
398- ( ) ) ;
399- bool shouldBreakLayouting = childResult . GetStatus ( ) != LayoutResult . FULL || newLineOccurred ;
400417 float currChildTextIndent = anythingPlaced ? 0 : lineLayoutContext . GetTextIndent ( ) ;
401418 if ( hangingTabStop != null && ( TabAlignment . LEFT == hangingTabStop . GetTabAlignment ( ) || shouldBreakLayouting
402419 || childRenderers . Count - 1 == childPos || childRenderers [ childPos + 1 ] is TabRenderer ) ) {
@@ -436,25 +453,13 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
436453 widthHandler . UpdateMaxChildWidth ( maxChildWidth_1 + currChildTextIndent ) ;
437454 }
438455 }
439- occupiedArea . SetBBox ( new Rectangle ( layoutBox . GetX ( ) , layoutBox . GetY ( ) + layoutBox . GetHeight ( ) - maxHeight ,
440- curWidth , maxHeight ) ) ;
456+ if ( ! wordWasSplitAndItWillFitOntoNextLine ) {
457+ occupiedArea . SetBBox ( new Rectangle ( layoutBox . GetX ( ) , layoutBox . GetY ( ) + layoutBox . GetHeight ( ) - maxHeight ,
458+ curWidth , maxHeight ) ) ;
459+ }
441460 if ( shouldBreakLayouting ) {
442461 LineRenderer [ ] split = Split ( ) ;
443462 split [ 0 ] . childRenderers = new List < IRenderer > ( childRenderers . SubList ( 0 , childPos ) ) ;
444- bool wordWasSplitAndItWillFitOntoNextLine = false ;
445- if ( childResult is TextLayoutResult && ( ( TextLayoutResult ) childResult ) . IsWordHasBeenSplit ( ) ) {
446- if ( wasXOverflowChanged ) {
447- SetProperty ( Property . OVERFLOW_X , oldXOverflow ) ;
448- }
449- LayoutResult newLayoutResult = childRenderer . Layout ( new LayoutContext ( new LayoutArea ( layoutContext . GetArea
450- ( ) . GetPageNumber ( ) , layoutBox ) , wasParentsHeightClipped ) ) ;
451- if ( wasXOverflowChanged ) {
452- SetProperty ( Property . OVERFLOW_X , OverflowPropertyValue . FIT ) ;
453- }
454- if ( newLayoutResult is TextLayoutResult && ! ( ( TextLayoutResult ) newLayoutResult ) . IsWordHasBeenSplit ( ) ) {
455- wordWasSplitAndItWillFitOntoNextLine = true ;
456- }
457- }
458463 if ( wordWasSplitAndItWillFitOntoNextLine ) {
459464 split [ 1 ] . childRenderers . Add ( childRenderer ) ;
460465 split [ 1 ] . childRenderers . AddAll ( childRenderers . SubList ( childPos + 1 , childRenderers . Count ) ) ;
@@ -1288,14 +1293,14 @@ private bool IsInlineBlockChild(IRenderer child) {
12881293 }
12891294
12901295 internal class RendererGlyph {
1296+ public Glyph glyph ;
1297+
1298+ public TextRenderer renderer ;
1299+
12911300 public RendererGlyph ( Glyph glyph , TextRenderer textRenderer ) {
12921301 this . glyph = glyph ;
12931302 this . renderer = textRenderer ;
12941303 }
1295-
1296- public Glyph glyph ;
1297-
1298- public TextRenderer renderer ;
12991304 }
13001305 }
13011306}
0 commit comments