@@ -55,14 +55,14 @@ source product.
55
55
56
56
namespace iText . Layout . Renderer {
57
57
public class LineRenderer : AbstractRenderer {
58
+ private const float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f ;
59
+
58
60
protected internal float maxAscent ;
59
61
60
62
protected internal float maxDescent ;
61
63
62
64
protected internal byte [ ] levels ;
63
65
64
- private const float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f ;
65
-
66
66
private float maxTextAscent ;
67
67
68
68
private float maxTextDescent ;
@@ -71,8 +71,8 @@ public class LineRenderer : AbstractRenderer {
71
71
72
72
private float maxBlockDescent ;
73
73
74
- // bidi levels
75
74
// AbstractRenderer.EPS is not enough here
75
+ // bidi levels
76
76
public override LayoutResult Layout ( LayoutContext layoutContext ) {
77
77
Rectangle layoutBox = layoutContext . GetArea ( ) . GetBBox ( ) . Clone ( ) ;
78
78
bool wasParentsHeightClipped = layoutContext . IsClippedHeight ( ) ;
@@ -375,28 +375,45 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
375
375
}
376
376
}
377
377
}
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 ;
385
394
}
386
395
}
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
+ }
394
414
}
395
415
}
396
416
float maxHeight = maxAscent - maxDescent ;
397
- bool newLineOccurred = ( childResult is TextLayoutResult && ( ( TextLayoutResult ) childResult ) . IsSplitForcedByNewline
398
- ( ) ) ;
399
- bool shouldBreakLayouting = childResult . GetStatus ( ) != LayoutResult . FULL || newLineOccurred ;
400
417
float currChildTextIndent = anythingPlaced ? 0 : lineLayoutContext . GetTextIndent ( ) ;
401
418
if ( hangingTabStop != null && ( TabAlignment . LEFT == hangingTabStop . GetTabAlignment ( ) || shouldBreakLayouting
402
419
|| childRenderers . Count - 1 == childPos || childRenderers [ childPos + 1 ] is TabRenderer ) ) {
@@ -436,25 +453,13 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
436
453
widthHandler . UpdateMaxChildWidth ( maxChildWidth_1 + currChildTextIndent ) ;
437
454
}
438
455
}
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
+ }
441
460
if ( shouldBreakLayouting ) {
442
461
LineRenderer [ ] split = Split ( ) ;
443
462
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
- }
458
463
if ( wordWasSplitAndItWillFitOntoNextLine ) {
459
464
split [ 1 ] . childRenderers . Add ( childRenderer ) ;
460
465
split [ 1 ] . childRenderers . AddAll ( childRenderers . SubList ( childPos + 1 , childRenderers . Count ) ) ;
@@ -1288,14 +1293,14 @@ private bool IsInlineBlockChild(IRenderer child) {
1288
1293
}
1289
1294
1290
1295
internal class RendererGlyph {
1296
+ public Glyph glyph ;
1297
+
1298
+ public TextRenderer renderer ;
1299
+
1291
1300
public RendererGlyph ( Glyph glyph , TextRenderer textRenderer ) {
1292
1301
this . glyph = glyph ;
1293
1302
this . renderer = textRenderer ;
1294
1303
}
1295
-
1296
- public Glyph glyph ;
1297
-
1298
- public TextRenderer renderer ;
1299
1304
}
1300
1305
}
1301
1306
}
0 commit comments