@@ -52,7 +52,6 @@ This file is part of the iText (R) project.
52
52
import com .itextpdf .io .util .TextUtil ;
53
53
import com .itextpdf .kernel .geom .Rectangle ;
54
54
import com .itextpdf .layout .element .TabStop ;
55
- import com .itextpdf .layout .element .Text ;
56
55
import com .itextpdf .layout .layout .LayoutArea ;
57
56
import com .itextpdf .layout .layout .LayoutContext ;
58
57
import com .itextpdf .layout .layout .LayoutResult ;
@@ -75,14 +74,11 @@ This file is part of the iText (R) project.
75
74
import java .util .ArrayList ;
76
75
import java .util .Arrays ;
77
76
import java .util .HashMap ;
78
- import java .util .HashSet ;
79
77
import java .util .LinkedHashMap ;
80
78
import java .util .List ;
81
79
import java .util .Map ;
82
80
import java .util .NavigableMap ;
83
- import java .util .Set ;
84
81
85
- import com .itextpdf .layout .splitting .ISplitCharacters ;
86
82
import org .slf4j .Logger ;
87
83
import org .slf4j .LoggerFactory ;
88
84
@@ -203,6 +199,15 @@ && hasChildRendererInHtmlMode()) {
203
199
204
200
RenderingMode childRenderingMode = childRenderer .<RenderingMode >getProperty (Property .RENDERING_MODE );
205
201
202
+ if (isTextRendererAndRequiresSpecialScriptPreLayoutProcessing (childRenderer )
203
+ && TypographyUtils .isPdfCalligraphAvailable ()) {
204
+ specialScriptPreLayoutProcessing (childPos );
205
+ }
206
+ resetTextSequenceIfItEnded (specialScriptLayoutResults , true , childRenderer , childPos ,
207
+ minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
208
+ resetTextSequenceIfItEnded (textRendererLayoutResults , false , childRenderer , childPos ,
209
+ minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
210
+
206
211
if (childRenderer instanceof TextRenderer ) {
207
212
// Delete these properties in case of relayout. We might have applied them during justify().
208
213
childRenderer .deleteOwnProperty (Property .CHARACTER_SPACING );
@@ -376,11 +381,6 @@ && hasChildRendererInHtmlMode()) {
376
381
boolean shouldBreakLayouting = false ;
377
382
378
383
if (childResult == null ) {
379
- if (TypographyUtils .isPdfCalligraphAvailable ()
380
- && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing (childRenderer )) {
381
- specialScriptPreLayoutProcessing (childPos );
382
- }
383
-
384
384
boolean setOverflowFitCausedBySpecialScripts = childRenderer instanceof TextRenderer
385
385
&& ((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (true );
386
386
@@ -404,10 +404,8 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
404
404
shouldBreakLayouting = textRendererMoveForwardsPostProcessing (moveForwardsSpecialScriptsOverflowX ,
405
405
moveForwardsTextRenderer , childPos , childRenderer , childResult , wasXOverflowChanged );
406
406
407
- updateTextRendererLayoutResults (textRendererLayoutResults , childRenderer , childPos , childResult ,
408
- minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
409
- updateSpecialScriptLayoutResults (specialScriptLayoutResults , childRenderer , childPos , childResult ,
410
- minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
407
+ updateTextRendererLayoutResults (textRendererLayoutResults , childRenderer , childPos , childResult );
408
+ updateSpecialScriptLayoutResults (specialScriptLayoutResults , childRenderer , childPos , childResult );
411
409
412
410
// it means that we've already increased layout area by MIN_MAX_WIDTH_CORRECTION_EPS
413
411
if (childResult instanceof MinMaxWidthLayoutResult && null != childBlockMinMaxWidth ) {
@@ -490,10 +488,11 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
490
488
lastFittingChildRendererData .childIndex , specialScriptLayoutResults );
491
489
childPos = lastFittingChildRendererData .childIndex ;
492
490
childResult = lastFittingChildRendererData .childLayoutResult ;
493
- minChildWidth = ((MinMaxWidthLayoutResult ) childResult ).getMinMaxWidth ().getMinWidth ();
494
- updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (
495
- noSoftWrap , childPos , childResult , widthHandler ,
496
- minMaxWidthOfTextRendererSequenceHelper , specialScriptLayoutResults );
491
+ specialScriptLayoutResults .put (childPos , childResult );
492
+
493
+ MinMaxWidth textSequenceElemminMaxWidth = ((MinMaxWidthLayoutResult ) childResult ).getMinMaxWidth ();
494
+ minChildWidth = textSequenceElemminMaxWidth .getMinWidth ();
495
+ maxChildWidth = textSequenceElemminMaxWidth .getMaxWidth ();
497
496
}
498
497
} else if (enableSpanWrapping ) {
499
498
boolean isOverflowFit = wasXOverflowChanged
@@ -521,10 +520,11 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
521
520
522
521
childPos = lastFittingChildRendererData .childIndex ;
523
522
childResult = lastFittingChildRendererData .childLayoutResult ;
524
- minChildWidth = ((MinMaxWidthLayoutResult ) childResult ).getMinMaxWidth ().getMinWidth ();
525
- updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (
526
- noSoftWrap , childPos , childResult , widthHandler ,
527
- minMaxWidthOfTextRendererSequenceHelper , textRendererLayoutResults );
523
+ textRendererLayoutResults .put (childPos , childResult );
524
+
525
+ MinMaxWidth textSequenceElemminMaxWidth = ((MinMaxWidthLayoutResult ) childResult ).getMinMaxWidth ();
526
+ minChildWidth = textSequenceElemminMaxWidth .getMinWidth ();
527
+ maxChildWidth = textSequenceElemminMaxWidth .getMaxWidth ();
528
528
}
529
529
}
530
530
}
@@ -638,29 +638,13 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
638
638
childPos ++;
639
639
}
640
640
}
641
-
642
- if (childPos == childRenderers .size ()
643
- && (!specialScriptLayoutResults .isEmpty () || !textRendererLayoutResults .isEmpty ())) {
644
- int lastTextRenderer = childPos ;
645
- boolean nonSpecialScripts = specialScriptLayoutResults .isEmpty ();
646
- while (lastTextRenderer >= 0 ) {
647
- if (nonSpecialScripts
648
- ? textRendererLayoutResults .get (lastTextRenderer ) != null
649
- : specialScriptLayoutResults .get (lastTextRenderer ) != null ) {
650
- break ;
651
- } else {
652
- lastTextRenderer --;
653
- }
654
- }
655
- LayoutResult lastTextLayoutResult = nonSpecialScripts
656
- ? textRendererLayoutResults .get (lastTextRenderer )
657
- : specialScriptLayoutResults .get (lastTextRenderer );
658
- updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (noSoftWrap , lastTextRenderer ,
659
- lastTextLayoutResult , widthHandler , minMaxWidthOfTextRendererSequenceHelper ,
660
- nonSpecialScripts ? textRendererLayoutResults : specialScriptLayoutResults );
661
- }
662
641
}
663
642
643
+ resetTextSequenceIfItEnded (specialScriptLayoutResults , true , null , childPos ,
644
+ minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
645
+ resetTextSequenceIfItEnded (textRendererLayoutResults , false , null , childPos ,
646
+ minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
647
+
664
648
if (result == null ) {
665
649
boolean noOverflowedFloats = floatsOverflowedToNextLine .isEmpty () && floatsToNextPageOverflowRenderers .isEmpty ();
666
650
if ((anythingPlaced || floatsPlaced ) && noOverflowedFloats || 0 == childRenderers .size ()) {
@@ -1332,7 +1316,8 @@ private BaseDirection applyOtf() {
1332
1316
static boolean isTextRendererAndRequiresSpecialScriptPreLayoutProcessing (IRenderer childRenderer ) {
1333
1317
return childRenderer instanceof TextRenderer
1334
1318
&& ((TextRenderer ) childRenderer ).getSpecialScriptsWordBreakPoints () == null
1335
- && ((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (false );
1319
+ && ((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (false )
1320
+ && !isChildFloating (childRenderer );
1336
1321
}
1337
1322
1338
1323
static boolean isChildFloating (IRenderer childRenderer ) {
@@ -1343,45 +1328,42 @@ static boolean isChildFloating(IRenderer childRenderer) {
1343
1328
1344
1329
void updateSpecialScriptLayoutResults (
1345
1330
Map <Integer , LayoutResult > specialScriptLayoutResults , IRenderer childRenderer , int childPos ,
1346
- LayoutResult childResult , MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper ,
1347
- boolean noSoftWrap , AbstractWidthHandler widthHandler ) {
1331
+ LayoutResult childResult ) {
1348
1332
if ((childRenderer instanceof TextRenderer
1349
1333
&& ((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (true ))) {
1350
1334
specialScriptLayoutResults .put (childPos , childResult );
1351
- } else
1352
- if (!specialScriptLayoutResults .isEmpty ()) {
1353
- while (childPos >= 0 ) {
1354
- if (specialScriptLayoutResults .get (childPos ) != null ) {
1355
- break ;
1356
- } else {
1357
- childPos --;
1358
- }
1359
- }
1360
- childResult = specialScriptLayoutResults .get (childPos );
1361
- updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (noSoftWrap , childPos , childResult ,
1362
- widthHandler , minMaxWidthOfTextRendererSequenceHelper , specialScriptLayoutResults );
1363
- specialScriptLayoutResults .clear ();
1364
1335
}
1365
1336
}
1366
1337
1367
- void updateTextRendererLayoutResults (
1368
- Map <Integer , LayoutResult > textRendererLayoutResults , IRenderer childRenderer , int childPos ,
1369
- LayoutResult childResult , MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper ,
1370
- boolean noSoftWrap , AbstractWidthHandler widthHandler ) {
1338
+ void updateTextRendererLayoutResults (Map <Integer , LayoutResult > textRendererLayoutResults ,
1339
+ IRenderer childRenderer , int childPos , LayoutResult childResult ) {
1371
1340
if (childRenderer instanceof TextRenderer
1372
1341
&& !((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (true )) {
1373
1342
textRendererLayoutResults .put (childPos , childResult );
1374
- } else if (!textRendererLayoutResults .isEmpty ()) {
1375
- while (childPos >= 0 ) {
1376
- if (textRendererLayoutResults .get (childPos ) != null ) {
1343
+ }
1344
+ }
1345
+
1346
+ void resetTextSequenceIfItEnded (Map <Integer , LayoutResult > textRendererLayoutResults , boolean specialScripts ,
1347
+ IRenderer childRenderer , int childPos ,
1348
+ MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper ,
1349
+ boolean noSoftWrap , AbstractWidthHandler widthHandler ) {
1350
+ if (childRenderer instanceof TextRenderer
1351
+ && ((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (true ) == specialScripts
1352
+ && !isChildFloating (childRenderer )) {
1353
+ return ;
1354
+ }
1355
+ if (!textRendererLayoutResults .isEmpty ()) {
1356
+ int lastChildInTextSequence = childPos ;
1357
+ while (lastChildInTextSequence >= 0 ) {
1358
+ if (textRendererLayoutResults .get (lastChildInTextSequence ) != null ) {
1377
1359
break ;
1378
1360
} else {
1379
- childPos --;
1361
+ lastChildInTextSequence --;
1380
1362
}
1381
1363
}
1382
- childResult = textRendererLayoutResults .get (childPos );
1383
- updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (noSoftWrap , childPos , childResult ,
1384
- widthHandler , minMaxWidthOfTextRendererSequenceHelper , textRendererLayoutResults );
1364
+ LayoutResult childResult = textRendererLayoutResults .get (lastChildInTextSequence );
1365
+ updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (noSoftWrap , lastChildInTextSequence ,
1366
+ childResult , widthHandler , minMaxWidthOfTextRendererSequenceHelper , textRendererLayoutResults );
1385
1367
textRendererLayoutResults .clear ();
1386
1368
}
1387
1369
}
@@ -1835,7 +1817,6 @@ LastFittingChildRendererData getIndexAndLayoutResultOfTheLastTextRendererWithNoS
1835
1817
if (textLayoutResult .isContainsPossibleBreak ()
1836
1818
&& textLayoutResult .getStatus () != LayoutResult .NOTHING ) {
1837
1819
textRenderer .setFirstIndexExceedingAvailableWidth (textRenderer .line .end );
1838
- // todo ? relayout in original bBox rather than occupied on the first layout area
1839
1820
LayoutArea layoutArea = textRenderer .getOccupiedArea ().clone ();
1840
1821
layoutArea .getBBox ()
1841
1822
.increaseHeight (0.0001F )
0 commit comments