@@ -80,15 +80,12 @@ This file is part of the iText (R) project.
80
80
81
81
public class LineRenderer extends AbstractRenderer {
82
82
83
+ // AbstractRenderer.EPS is not enough here
84
+ private static final float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f ;
83
85
protected float maxAscent ;
84
86
protected float maxDescent ;
85
-
86
87
// bidi levels
87
88
protected byte [] levels ;
88
-
89
- // AbstractRenderer.EPS is not enough here
90
- private static final float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f ;
91
-
92
89
private float maxTextAscent ;
93
90
private float maxTextDescent ;
94
91
private float maxBlockAscent ;
@@ -387,23 +384,40 @@ public LayoutResult layout(LayoutContext layoutContext) {
387
384
}
388
385
}
389
386
390
- maxAscent = Math .max (maxAscent , childAscent );
391
- if (childRenderer instanceof TextRenderer ) {
392
- maxTextAscent = Math .max (maxTextAscent , childAscent );
393
- } else if (!isChildFloating ) {
394
- maxBlockAscent = Math .max (maxBlockAscent , childAscent );
387
+ boolean newLineOccurred = (childResult instanceof TextLayoutResult && ((TextLayoutResult ) childResult ).isSplitForcedByNewline ());
388
+ boolean shouldBreakLayouting = childResult .getStatus () != LayoutResult .FULL || newLineOccurred ;
389
+
390
+ boolean wordWasSplitAndItWillFitOntoNextLine = false ;
391
+
392
+ if (shouldBreakLayouting && childResult instanceof TextLayoutResult && ((TextLayoutResult ) childResult ).isWordHasBeenSplit ()) {
393
+ if (wasXOverflowChanged ) {
394
+ setProperty (Property .OVERFLOW_X , oldXOverflow );
395
+ }
396
+ LayoutResult newLayoutResult = childRenderer .layout (new LayoutContext (new LayoutArea (layoutContext .getArea ().getPageNumber (), layoutBox ), wasParentsHeightClipped ));
397
+ if (wasXOverflowChanged ) {
398
+ setProperty (Property .OVERFLOW_X , OverflowPropertyValue .FIT );
399
+ }
400
+ if (newLayoutResult instanceof TextLayoutResult && !((TextLayoutResult ) newLayoutResult ).isWordHasBeenSplit ()) {
401
+ wordWasSplitAndItWillFitOntoNextLine = true ;
402
+ }
395
403
}
396
- maxDescent = Math .min (maxDescent , childDescent );
397
- if (childRenderer instanceof TextRenderer ) {
398
- maxTextDescent = Math .min (maxTextDescent , childDescent );
399
- } else if (!isChildFloating ) {
400
- maxBlockDescent = Math .min (maxBlockDescent , childDescent );
404
+
405
+ if (!wordWasSplitAndItWillFitOntoNextLine ) {
406
+ maxAscent = Math .max (maxAscent , childAscent );
407
+ if (childRenderer instanceof TextRenderer ) {
408
+ maxTextAscent = Math .max (maxTextAscent , childAscent );
409
+ } else if (!isChildFloating ) {
410
+ maxBlockAscent = Math .max (maxBlockAscent , childAscent );
411
+ }
412
+ maxDescent = Math .min (maxDescent , childDescent );
413
+ if (childRenderer instanceof TextRenderer ) {
414
+ maxTextDescent = Math .min (maxTextDescent , childDescent );
415
+ } else if (!isChildFloating ) {
416
+ maxBlockDescent = Math .min (maxBlockDescent , childDescent );
417
+ }
401
418
}
402
419
float maxHeight = maxAscent - maxDescent ;
403
420
404
- boolean newLineOccurred = (childResult instanceof TextLayoutResult && ((TextLayoutResult ) childResult ).isSplitForcedByNewline ());
405
- boolean shouldBreakLayouting = childResult .getStatus () != LayoutResult .FULL || newLineOccurred ;
406
-
407
421
float currChildTextIndent = anythingPlaced ? 0 : lineLayoutContext .getTextIndent ();
408
422
if (hangingTabStop != null
409
423
&& (TabAlignment .LEFT == hangingTabStop .getTabAlignment () || shouldBreakLayouting || childRenderers .size () - 1 == childPos || childRenderers .get (childPos + 1 ) instanceof TabRenderer )) {
@@ -421,7 +435,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
421
435
if (childResult .getSplitRenderer () != null ) {
422
436
childResult .getSplitRenderer ().move (tabWidth + sumOfAffectedRendererWidths - childResult .getSplitRenderer ().getOccupiedArea ().getBBox ().getWidth (), 0 );
423
437
}
424
-
425
438
float tabAndNextElemWidth = tabWidth + childResult .getOccupiedArea ().getBBox ().getWidth ();
426
439
if (hangingTabStop .getTabAlignment () == TabAlignment .RIGHT && curWidth + tabAndNextElemWidth < hangingTabStop .getTabPosition ()) {
427
440
curWidth = hangingTabStop .getTabPosition ();
@@ -438,26 +451,14 @@ public LayoutResult layout(LayoutContext layoutContext) {
438
451
widthHandler .updateMinChildWidth (minChildWidth + currChildTextIndent );
439
452
widthHandler .updateMaxChildWidth (maxChildWidth + currChildTextIndent );
440
453
}
441
- occupiedArea .setBBox (new Rectangle (layoutBox .getX (), layoutBox .getY () + layoutBox .getHeight () - maxHeight , curWidth , maxHeight ));
442
-
454
+ if (!wordWasSplitAndItWillFitOntoNextLine ) {
455
+ occupiedArea .setBBox (new Rectangle (layoutBox .getX (), layoutBox .getY () + layoutBox .getHeight () - maxHeight , curWidth , maxHeight ));
456
+ }
443
457
444
458
if (shouldBreakLayouting ) {
445
459
LineRenderer [] split = split ();
446
460
split [0 ].childRenderers = new ArrayList <>(childRenderers .subList (0 , childPos ));
447
461
448
- boolean wordWasSplitAndItWillFitOntoNextLine = false ;
449
- if (childResult instanceof TextLayoutResult && ((TextLayoutResult ) childResult ).isWordHasBeenSplit ()) {
450
- if (wasXOverflowChanged ) {
451
- setProperty (Property .OVERFLOW_X , oldXOverflow );
452
- }
453
- LayoutResult newLayoutResult = childRenderer .layout (new LayoutContext (new LayoutArea (layoutContext .getArea ().getPageNumber (), layoutBox ), wasParentsHeightClipped ));
454
- if (wasXOverflowChanged ) {
455
- setProperty (Property .OVERFLOW_X , OverflowPropertyValue .FIT );
456
- }
457
- if (newLayoutResult instanceof TextLayoutResult && !((TextLayoutResult ) newLayoutResult ).isWordHasBeenSplit ()) {
458
- wordWasSplitAndItWillFitOntoNextLine = true ;
459
- }
460
- }
461
462
462
463
if (wordWasSplitAndItWillFitOntoNextLine ) {
463
464
split [1 ].childRenderers .add (childRenderer );
@@ -779,8 +780,8 @@ public void justify(float width) {
779
780
childX = lastRightPos ;
780
781
if (child instanceof TextRenderer ) {
781
782
float childHSCale = (float ) ((TextRenderer ) child ).getPropertyAsFloat (Property .HORIZONTAL_SCALING , 1f );
782
- Float oldCharacterSpacing = ((TextRenderer )child ).getPropertyAsFloat (Property .CHARACTER_SPACING );
783
- Float oldWordSpacing = ((TextRenderer )child ).getPropertyAsFloat (Property .WORD_SPACING );
783
+ Float oldCharacterSpacing = ((TextRenderer ) child ).getPropertyAsFloat (Property .CHARACTER_SPACING );
784
+ Float oldWordSpacing = ((TextRenderer ) child ).getPropertyAsFloat (Property .WORD_SPACING );
784
785
child .setProperty (Property .CHARACTER_SPACING , (null == oldCharacterSpacing ? 0 : (float ) oldCharacterSpacing ) + characterSpacing / childHSCale );
785
786
child .setProperty (Property .WORD_SPACING , (null == oldWordSpacing ? 0 : (float ) oldWordSpacing ) + wordSpacing / childHSCale );
786
787
boolean isLastTextRenderer = child == lastChildRenderer ;
@@ -810,7 +811,7 @@ protected int getNumberOfSpaces() {
810
811
*/
811
812
protected int length () {
812
813
int length = 0 ;
813
- for (IRenderer child : childRenderers ) {
814
+ for (IRenderer child : childRenderers ) {
814
815
if (child instanceof TextRenderer && !FloatingHelper .isRendererFloating (child )) {
815
816
length += ((TextRenderer ) child ).lineLength ();
816
817
}
@@ -1255,12 +1256,12 @@ private boolean isInlineBlockChild(IRenderer child) {
1255
1256
}
1256
1257
1257
1258
static class RendererGlyph {
1259
+ public Glyph glyph ;
1260
+ public TextRenderer renderer ;
1261
+
1258
1262
public RendererGlyph (Glyph glyph , TextRenderer textRenderer ) {
1259
1263
this .glyph = glyph ;
1260
1264
this .renderer = textRenderer ;
1261
1265
}
1262
-
1263
- public Glyph glyph ;
1264
- public TextRenderer renderer ;
1265
1266
}
1266
1267
}
0 commit comments