Skip to content

Commit 2ad0334

Browse files
LodrKumquatyulian-gaponenko
authored andcommitted
Change condition to stop TextRenderer#layout when a width limit is reached
DEVSIX-1192
1 parent 331d41b commit 2ad0334

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/LineRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,15 +1694,15 @@ LastFittingChildRendererData getIndexAndLayoutResultOfTheLastTextRendererWithNoS
16941694
}
16951695
if (textLayoutResult.isContainsPossibleBreak()
16961696
&& textLayoutResult.getStatus() != LayoutResult.NOTHING) {
1697-
textRenderer.setLayoutUntilTheLastPossibleBreak(true);
1697+
textRenderer.setFirstIndexExceedingAvailableWidth(textRenderer.line.end);
16981698
// todo ? relayout in original bBox rather than occupied on the first layout area
16991699
LayoutArea layoutArea = textRenderer.getOccupiedArea().clone();
17001700
layoutArea.getBBox()
17011701
.increaseHeight(0.0001F)
17021702
.increaseWidth(0.0001F);
17031703
LayoutResult newChildLayoutResult = textRenderer
17041704
.layout(new LayoutContext(layoutArea, wasParentsHeightClipped));
1705-
textRenderer.setLayoutUntilTheLastPossibleBreak(false);
1705+
textRenderer.setFirstIndexExceedingAvailableWidth(-1);
17061706
if (newChildLayoutResult.getStatus() == LayoutResult.FULL) {
17071707
lastAnalyzedTextLayoutResult = new TextLayoutResult(LayoutResult.NOTHING, null,
17081708
null, childRenderers.get(lastAnalyzedTextRenderer));

layout/src/main/java/com/itextpdf/layout/renderer/TextRenderer.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public class TextRenderer extends AbstractRenderer implements ILeafElementRender
134134

135135
private int specialScriptFirstNotFittingIndex = -1;
136136

137-
private boolean layoutUntilTheLastPossibleBreak = false;
137+
private int firstIndexExceedingAvailableWidth = -1;
138138

139139
/**
140140
* Creates a TextRenderer from its corresponding layout object.
@@ -343,8 +343,10 @@ public LayoutResult layout(LayoutContext layoutContext) {
343343
&& RenderingMode.HTML_MODE == mode) {
344344
containsPossibleBreak = true;
345345
}
346-
if (ind + 1 == text.end || nextGlyphIsSpaceOrWhiteSpace) {
347-
if (ind + 1 == text.end && layoutUntilTheLastPossibleBreak) {
346+
if (ind + 1 == text.end || nextGlyphIsSpaceOrWhiteSpace
347+
|| (ind + 1 >= firstIndexExceedingAvailableWidth
348+
&& firstIndexExceedingAvailableWidth != -1)) {
349+
if (ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != -1) {
348350
firstCharacterWhichExceedsAllowedWidth = currentTextPos;
349351
break;
350352
} else {
@@ -434,8 +436,9 @@ && findPossibleBreaksSplitPosition(specialScriptsWordBreakPoints,
434436
}
435437
if (ind + 1 == text.end
436438
|| endOfNonBreakablePartCausedBySplitCharacter
437-
|| endOfWordBelongingToSpecialScripts) {
438-
if (ind + 1 == text.end && layoutUntilTheLastPossibleBreak
439+
|| endOfWordBelongingToSpecialScripts
440+
|| (ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != -1)) {
441+
if (ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != -1
439442
&& !endOfNonBreakablePartCausedBySplitCharacter) {
440443
firstCharacterWhichExceedsAllowedWidth = currentTextPos;
441444
}
@@ -493,7 +496,7 @@ && findPossibleBreaksSplitPosition(specialScriptsWordBreakPoints,
493496
boolean wordSplit = false;
494497
boolean hyphenationApplied = false;
495498

496-
if (hyphenationConfig != null && !layoutUntilTheLastPossibleBreak) {
499+
if (hyphenationConfig != null && firstIndexExceedingAvailableWidth == -1) {
497500
if (-1 == nonBreakingHyphenRelatedChunkStart) {
498501
int[] wordBounds = getWordBoundsForHyphenation(text, currentTextPos, text.end, Math.max(currentTextPos, firstCharacterWhichExceedsAllowedWidth - 1));
499502
if (wordBounds != null) {
@@ -1303,8 +1306,8 @@ int getSpecialScriptFirstNotFittingIndex() {
13031306
return specialScriptFirstNotFittingIndex;
13041307
}
13051308

1306-
void setLayoutUntilTheLastPossibleBreak(boolean layoutUntilTheLastPossibleBreak) {
1307-
this.layoutUntilTheLastPossibleBreak = layoutUntilTheLastPossibleBreak;
1309+
void setFirstIndexExceedingAvailableWidth(int firstIndexExceedingAvailableWidth) {
1310+
this.firstIndexExceedingAvailableWidth = firstIndexExceedingAvailableWidth;
13081311
}
13091312

13101313
@Override

0 commit comments

Comments
 (0)