@@ -194,6 +194,8 @@ && hasChildRendererInHtmlMode()) {
194
194
Map <Integer , float []> textRendererSequenceAscentDescent = new HashMap <>();
195
195
float [] ascentDescentTextAscentTextDescentBeforeTextRendererSequence = null ;
196
196
197
+ MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper = null ;
198
+
197
199
while (childPos < childRenderers .size ()) {
198
200
IRenderer childRenderer = childRenderers .get (childPos );
199
201
LayoutResult childResult = null ;
@@ -402,8 +404,10 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
402
404
shouldBreakLayouting = textRendererMoveForwardsPostProcessing (moveForwardsSpecialScriptsOverflowX ,
403
405
moveForwardsTextRenderer , childPos , childRenderer , childResult , wasXOverflowChanged );
404
406
405
- updateTextRendererLayoutResults (textRendererLayoutResults , childRenderer , childPos , childResult );
406
- updateSpecialScriptLayoutResults (specialScriptLayoutResults , childRenderer , childPos , childResult );
407
+ updateTextRendererLayoutResults (textRendererLayoutResults , childRenderer , childPos , childResult ,
408
+ minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
409
+ updateSpecialScriptLayoutResults (specialScriptLayoutResults , childRenderer , childPos , childResult ,
410
+ minMaxWidthOfTextRendererSequenceHelper , noSoftWrap , widthHandler );
407
411
408
412
// it means that we've already increased layout area by MIN_MAX_WIDTH_CORRECTION_EPS
409
413
if (childResult instanceof MinMaxWidthLayoutResult && null != childBlockMinMaxWidth ) {
@@ -441,6 +445,10 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
441
445
textRendererSequenceAscentDescent , childPos , childAscentDescent ,
442
446
ascentDescentTextAscentTextDescentBeforeTextRendererSequence );
443
447
448
+ minMaxWidthOfTextRendererSequenceHelper = updateTextRendererSequenceMinMaxWidth (widthHandler , childPos ,
449
+ minMaxWidthOfTextRendererSequenceHelper , anythingPlaced , textRendererLayoutResults ,
450
+ specialScriptLayoutResults , lineLayoutContext .getTextIndent ());
451
+
444
452
boolean newLineOccurred = (childResult instanceof TextLayoutResult && ((TextLayoutResult ) childResult ).isSplitForcedByNewline ());
445
453
if (!shouldBreakLayouting ) {
446
454
shouldBreakLayouting = childResult .getStatus () != LayoutResult .FULL || newLineOccurred ;
@@ -482,6 +490,10 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
482
490
lastFittingChildRendererData .childIndex , specialScriptLayoutResults );
483
491
childPos = lastFittingChildRendererData .childIndex ;
484
492
childResult = lastFittingChildRendererData .childLayoutResult ;
493
+ minChildWidth = ((MinMaxWidthLayoutResult ) childResult ).getMinMaxWidth ().getMinWidth ();
494
+ updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (
495
+ noSoftWrap , childPos , childResult , widthHandler ,
496
+ minMaxWidthOfTextRendererSequenceHelper , specialScriptLayoutResults );
485
497
}
486
498
} else if (enableSpanWrapping ) {
487
499
boolean isOverflowFit = wasXOverflowChanged
@@ -509,6 +521,10 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
509
521
510
522
childPos = lastFittingChildRendererData .childIndex ;
511
523
childResult = lastFittingChildRendererData .childLayoutResult ;
524
+ minChildWidth = ((MinMaxWidthLayoutResult ) childResult ).getMinMaxWidth ().getMinWidth ();
525
+ updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (
526
+ noSoftWrap , childPos , childResult , widthHandler ,
527
+ minMaxWidthOfTextRendererSequenceHelper , textRendererLayoutResults );
512
528
}
513
529
}
514
530
}
@@ -622,6 +638,27 @@ && isTextRendererAndRequiresSpecialScriptPreLayoutProcessing(childRenderer)) {
622
638
childPos ++;
623
639
}
624
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
+ }
625
662
}
626
663
627
664
if (result == null ) {
@@ -1304,22 +1341,46 @@ static boolean isChildFloating(IRenderer childRenderer) {
1304
1341
&& FloatingHelper .isRendererFloating (childRenderer , kidFloatPropertyVal );
1305
1342
}
1306
1343
1307
- static void updateSpecialScriptLayoutResults (Map <Integer , LayoutResult > specialScriptLayoutResults ,
1308
- IRenderer childRenderer , int childPos , LayoutResult childResult ) {
1344
+ void updateSpecialScriptLayoutResults (
1345
+ Map <Integer , LayoutResult > specialScriptLayoutResults , IRenderer childRenderer , int childPos ,
1346
+ LayoutResult childResult , MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper ,
1347
+ boolean noSoftWrap , AbstractWidthHandler widthHandler ) {
1309
1348
if ((childRenderer instanceof TextRenderer && ((TextRenderer ) childRenderer )
1310
1349
.textContainsSpecialScriptGlyphs (true ))) {
1311
1350
specialScriptLayoutResults .put (childPos , childResult );
1312
1351
} else if (!specialScriptLayoutResults .isEmpty () && !isChildFloating (childRenderer )) {
1352
+ while (childPos >= 0 ) {
1353
+ if (specialScriptLayoutResults .get (childPos ) != null ) {
1354
+ break ;
1355
+ } else {
1356
+ childPos --;
1357
+ }
1358
+ }
1359
+ childResult = specialScriptLayoutResults .get (childPos );
1360
+ updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (noSoftWrap , childPos , childResult ,
1361
+ widthHandler , minMaxWidthOfTextRendererSequenceHelper , specialScriptLayoutResults );
1313
1362
specialScriptLayoutResults .clear ();
1314
1363
}
1315
1364
}
1316
1365
1317
- static void updateTextRendererLayoutResults (Map <Integer , LayoutResult > textRendererLayoutResults ,
1318
- IRenderer childRenderer , int childPos , LayoutResult childResult ) {
1366
+ void updateTextRendererLayoutResults (
1367
+ Map <Integer , LayoutResult > textRendererLayoutResults , IRenderer childRenderer , int childPos ,
1368
+ LayoutResult childResult , MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper ,
1369
+ boolean noSoftWrap , AbstractWidthHandler widthHandler ) {
1319
1370
if (childRenderer instanceof TextRenderer && !((TextRenderer ) childRenderer )
1320
1371
.textContainsSpecialScriptGlyphs (true )) {
1321
1372
textRendererLayoutResults .put (childPos , childResult );
1322
1373
} else if (!textRendererLayoutResults .isEmpty () && !isChildFloating (childRenderer )) {
1374
+ while (childPos >= 0 ) {
1375
+ if (textRendererLayoutResults .get (childPos ) != null ) {
1376
+ break ;
1377
+ } else {
1378
+ childPos --;
1379
+ }
1380
+ }
1381
+ childResult = textRendererLayoutResults .get (childPos );
1382
+ updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (noSoftWrap , childPos , childResult ,
1383
+ widthHandler , minMaxWidthOfTextRendererSequenceHelper , textRendererLayoutResults );
1323
1384
textRendererLayoutResults .clear ();
1324
1385
}
1325
1386
}
@@ -1551,6 +1612,82 @@ float[] updateTextRendererSequenceAscentDescent(Map<Integer, float[]> textRender
1551
1612
return preTextSequenceAscentDescent ;
1552
1613
}
1553
1614
1615
+ MinMaxWidthOfTextRendererSequenceHelper updateTextRendererSequenceMinMaxWidth (
1616
+ AbstractWidthHandler widthHandler , int childPos ,
1617
+ MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper , boolean anythingPlaced ,
1618
+ Map <Integer , LayoutResult > textRendererLayoutResults ,
1619
+ Map <Integer , LayoutResult > specialScriptLayoutResults , float textIndent ) {
1620
+ IRenderer childRenderer = childRenderers .get (childPos );
1621
+ if (isChildFloating (childRenderer )) {
1622
+ return minMaxWidthOfTextRendererSequenceHelper ;
1623
+ } else if (childRenderer instanceof TextRenderer ) {
1624
+ boolean firstTextRendererWithSpecialScripts =
1625
+ ((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (true )
1626
+ && specialScriptLayoutResults .size () == 1 ;
1627
+ boolean firstTextRendererWithoutSpecialScripts =
1628
+ !((TextRenderer ) childRenderer ).textContainsSpecialScriptGlyphs (true )
1629
+ && textRendererLayoutResults .size () == 1 ;
1630
+ if (firstTextRendererWithoutSpecialScripts || firstTextRendererWithSpecialScripts ) {
1631
+ minMaxWidthOfTextRendererSequenceHelper = new MinMaxWidthOfTextRendererSequenceHelper (
1632
+ widthHandler .minMaxWidth .getChildrenMinWidth (), textIndent , anythingPlaced );
1633
+ }
1634
+ return minMaxWidthOfTextRendererSequenceHelper ;
1635
+ } else {
1636
+ return null ;
1637
+ }
1638
+ }
1639
+
1640
+ void updateMinMaxWidthOfLineRendererAfterTextRendererSequenceProcessing (
1641
+ boolean noSoftWrap , int childPos , LayoutResult layoutResult , AbstractWidthHandler widthHandler ,
1642
+ MinMaxWidthOfTextRendererSequenceHelper minMaxWidthOfTextRendererSequenceHelper ,
1643
+ Map <Integer , LayoutResult > textRendererLayoutResults ) {
1644
+ if (noSoftWrap ) {
1645
+ return ;
1646
+ }
1647
+ TextLayoutResult currLayoutResult = (TextLayoutResult ) layoutResult ;
1648
+ float leftMinWidthCurrRenderer = currLayoutResult .getLeftMinWidth ();
1649
+ float generalMinWidthCurrRenderer = currLayoutResult .getMinMaxWidth ().getMinWidth ();
1650
+ float widthOfUnbreakableChunkSplitAcrossRenderers = leftMinWidthCurrRenderer ;
1651
+ float minWidthOfTextRendererSequence = generalMinWidthCurrRenderer ;
1652
+
1653
+ for (int prevRendererIndex = childPos - 1 ; prevRendererIndex >= 0 ; prevRendererIndex --) {
1654
+ if (textRendererLayoutResults .get (prevRendererIndex ) != null ) {
1655
+ TextLayoutResult prevLayoutResult = (TextLayoutResult ) textRendererLayoutResults .get (prevRendererIndex );
1656
+ float leftMinWidthPrevRenderer = prevLayoutResult .getLeftMinWidth ();
1657
+ float generalMinWidthPrevRenderer = prevLayoutResult .getMinMaxWidth ().getMinWidth ();
1658
+ float rightMinWidthPrevRenderer = prevLayoutResult .getRightMinWidth ();
1659
+ minWidthOfTextRendererSequence = Math .max (minWidthOfTextRendererSequence , generalMinWidthPrevRenderer );
1660
+
1661
+ if (!prevLayoutResult .isLineEndsWithSplitCharacterOrWhiteSpace ()
1662
+ && !currLayoutResult .isLineStartsWithWhiteSpace ()) {
1663
+ if (rightMinWidthPrevRenderer > -1f ) {
1664
+ widthOfUnbreakableChunkSplitAcrossRenderers += rightMinWidthPrevRenderer ;
1665
+ } else {
1666
+ widthOfUnbreakableChunkSplitAcrossRenderers += leftMinWidthPrevRenderer ;
1667
+ }
1668
+ minWidthOfTextRendererSequence = Math .max (minWidthOfTextRendererSequence ,
1669
+ widthOfUnbreakableChunkSplitAcrossRenderers );
1670
+ if (rightMinWidthPrevRenderer > -1f ) {
1671
+ widthOfUnbreakableChunkSplitAcrossRenderers = leftMinWidthPrevRenderer ;
1672
+ }
1673
+ } else {
1674
+ widthOfUnbreakableChunkSplitAcrossRenderers = leftMinWidthPrevRenderer ;
1675
+ }
1676
+ currLayoutResult = prevLayoutResult ;
1677
+ }
1678
+ }
1679
+
1680
+ if (!minMaxWidthOfTextRendererSequenceHelper .anythingPlacedBeforeTextRendererSequence ) {
1681
+ widthOfUnbreakableChunkSplitAcrossRenderers += minMaxWidthOfTextRendererSequenceHelper .textIndent ;
1682
+ minWidthOfTextRendererSequence = Math .max (minWidthOfTextRendererSequence ,
1683
+ widthOfUnbreakableChunkSplitAcrossRenderers );
1684
+ }
1685
+
1686
+ float lineMinWidth = Math .max (minWidthOfTextRendererSequence ,
1687
+ minMaxWidthOfTextRendererSequenceHelper .minWidthPreSequence );
1688
+ widthHandler .minMaxWidth .setChildrenMinWidth (lineMinWidth );
1689
+ }
1690
+
1554
1691
static float getCurWidthSpecialScriptsDecrement (int childPos , int newChildPos ,
1555
1692
Map <Integer , LayoutResult > specialScriptLayoutResults ) {
1556
1693
float decrement = 0.0f ;
@@ -2084,6 +2221,20 @@ public LastFittingChildRendererData(int childIndex, LayoutResult childLayoutResu
2084
2221
}
2085
2222
}
2086
2223
2224
+ static class MinMaxWidthOfTextRendererSequenceHelper {
2225
+ public float minWidthPreSequence ;
2226
+ public float textIndent ;
2227
+ public boolean anythingPlacedBeforeTextRendererSequence ;
2228
+
2229
+ public MinMaxWidthOfTextRendererSequenceHelper (float minWidthPreSequence , float textIndent ,
2230
+ boolean anythingPlacedBeforeTextRendererSequence ) {
2231
+ this .minWidthPreSequence = minWidthPreSequence ;
2232
+ this .textIndent = textIndent ;
2233
+ this .anythingPlacedBeforeTextRendererSequence = anythingPlacedBeforeTextRendererSequence ;
2234
+ }
2235
+
2236
+ }
2237
+
2087
2238
static enum SpecialScriptsContainingSequenceStatus {
2088
2239
MOVE_SEQUENCE_CONTAINING_SPECIAL_SCRIPTS_ON_NEXT_LINE ,
2089
2240
MOVE_TO_PREVIOUS_TEXT_RENDERER_CONTAINING_SPECIAL_SCRIPTS ,
0 commit comments