@@ -81,6 +81,7 @@ This file is part of the iText (R) project.
81
81
import com .itextpdf .layout .property .FloatPropertyValue ;
82
82
import com .itextpdf .layout .property .FontKerning ;
83
83
import com .itextpdf .layout .property .OverflowPropertyValue ;
84
+ import com .itextpdf .layout .property .OverflowWrapPropertyValue ;
84
85
import com .itextpdf .layout .property .Property ;
85
86
import com .itextpdf .layout .property .RenderingMode ;
86
87
import com .itextpdf .layout .property .TransparentColor ;
@@ -178,6 +179,12 @@ public LayoutResult layout(LayoutContext layoutContext) {
178
179
179
180
OverflowPropertyValue overflowX = this .parent .<OverflowPropertyValue >getProperty (Property .OVERFLOW_X );
180
181
182
+ OverflowWrapPropertyValue overflowWrap = this .<OverflowWrapPropertyValue >getProperty (Property .OVERFLOW_WRAP );
183
+ if (overflowWrap == OverflowWrapPropertyValue .ANYWHERE
184
+ || overflowWrap == OverflowWrapPropertyValue .BREAK_WORD ) {
185
+ overflowX = OverflowPropertyValue .FIT ;
186
+ }
187
+
181
188
List <Rectangle > floatRendererAreas = layoutContext .getFloatRendererAreas ();
182
189
FloatPropertyValue floatPropertyValue = this .<FloatPropertyValue >getProperty (Property .FLOAT );
183
190
@@ -390,6 +397,12 @@ public LayoutResult layout(LayoutContext layoutContext) {
390
397
}
391
398
}
392
399
400
+ if (OverflowWrapPropertyValue .ANYWHERE == overflowWrap ) {
401
+ widthHandler .updateMinChildWidth ((float ) ((double ) glyphWidth + (double ) xAdvance
402
+ + (double ) italicSkewAddition + (double ) boldSimulationAddition ));
403
+ widthHandler .updateMaxChildWidth ((float ) ((double ) glyphWidth + (double ) xAdvance ));
404
+ }
405
+
393
406
boolean endOfWordBelongingToSpecialScripts = textContainsSpecialScriptGlyphs (true )
394
407
&& findPossibleBreaksSplitPosition (specialScriptsWordBreakPoints ,
395
408
ind + 1 , true ) >= 0 ;
@@ -412,8 +425,17 @@ && findPossibleBreaksSplitPosition(specialScriptsWordBreakPoints,
412
425
currentLineHeight = Math .max (currentLineHeight , nonBreakablePartMaxHeight );
413
426
currentTextPos = nonBreakablePartEnd + 1 ;
414
427
currentLineWidth += nonBreakablePartFullWidth ;
415
- widthHandler .updateMinChildWidth (nonBreakablePartWidthWhichDoesNotExceedAllowedWidth + italicSkewAddition + boldSimulationAddition );
416
- widthHandler .updateMaxChildWidth (nonBreakablePartWidthWhichDoesNotExceedAllowedWidth + italicSkewAddition + boldSimulationAddition );
428
+ if (OverflowWrapPropertyValue .ANYWHERE == overflowWrap ) {
429
+ widthHandler .updateMaxChildWidth ((float ) ((double ) italicSkewAddition
430
+ + (double ) boldSimulationAddition ));
431
+ } else {
432
+ widthHandler .updateMinChildWidth (
433
+ (float ) ((double ) nonBreakablePartWidthWhichDoesNotExceedAllowedWidth
434
+ + (double ) italicSkewAddition + (double ) boldSimulationAddition ));
435
+ widthHandler .updateMaxChildWidth (
436
+ (float ) ((double ) nonBreakablePartWidthWhichDoesNotExceedAllowedWidth
437
+ + (double ) italicSkewAddition + (double ) boldSimulationAddition ));
438
+ }
417
439
anythingPlaced = true ;
418
440
} else {
419
441
// check if line height exceeds the allowed height
@@ -465,9 +487,19 @@ && findPossibleBreaksSplitPosition(specialScriptsWordBreakPoints,
465
487
currentLineHeight = Math .max (currentLineHeight , nonBreakablePartMaxHeight );
466
488
467
489
currentLineWidth += currentHyphenationChoicePreTextWidth ;
468
- widthHandler .updateMinChildWidth (currentHyphenationChoicePreTextWidth + italicSkewAddition + boldSimulationAddition );
469
- widthHandler .updateMaxChildWidth (currentHyphenationChoicePreTextWidth + italicSkewAddition + boldSimulationAddition );
470
-
490
+ if (OverflowWrapPropertyValue .ANYWHERE == overflowWrap ) {
491
+ widthHandler .updateMaxChildWidth ((float ) ((double ) italicSkewAddition
492
+ + (double ) boldSimulationAddition ));
493
+ } else {
494
+ widthHandler .updateMinChildWidth (
495
+ (float ) ((double ) currentHyphenationChoicePreTextWidth
496
+ + (double ) italicSkewAddition
497
+ + (double ) boldSimulationAddition ));
498
+ widthHandler .updateMaxChildWidth (
499
+ (float ) ((double ) currentHyphenationChoicePreTextWidth
500
+ + (double ) italicSkewAddition
501
+ + (double ) boldSimulationAddition ));
502
+ }
471
503
currentTextPos = wordBounds [0 ] + pre .length ();
472
504
break ;
473
505
}
@@ -509,8 +541,17 @@ && findPossibleBreaksSplitPosition(specialScriptsWordBreakPoints,
509
541
currentLineDescender = Math .min (currentLineDescender , nonBreakablePartMaxDescender );
510
542
currentLineHeight = Math .max (currentLineHeight , nonBreakablePartMaxHeight );
511
543
currentLineWidth += nonBreakablePartWidthWhichDoesNotExceedAllowedWidth ;
512
- widthHandler .updateMinChildWidth (nonBreakablePartWidthWhichDoesNotExceedAllowedWidth + italicSkewAddition + boldSimulationAddition );
513
- widthHandler .updateMaxChildWidth (nonBreakablePartWidthWhichDoesNotExceedAllowedWidth + italicSkewAddition + boldSimulationAddition );
544
+ if (OverflowWrapPropertyValue .ANYWHERE == overflowWrap ) {
545
+ widthHandler .updateMaxChildWidth ((float ) ((double ) italicSkewAddition
546
+ + (double ) boldSimulationAddition ));
547
+ } else {
548
+ widthHandler .updateMinChildWidth (
549
+ (float ) ((double ) nonBreakablePartWidthWhichDoesNotExceedAllowedWidth
550
+ + (double ) italicSkewAddition + (double ) boldSimulationAddition ));
551
+ widthHandler .updateMaxChildWidth (
552
+ (float ) ((double ) nonBreakablePartWidthWhichDoesNotExceedAllowedWidth
553
+ + (double ) italicSkewAddition + (double ) boldSimulationAddition ));
554
+ }
514
555
} else {
515
556
// process empty line (e.g. '\n')
516
557
currentLineAscender = ascender ;
0 commit comments