Skip to content

Commit 8161b74

Browse files
LodrKumquatyulian-gaponenko
authored andcommitted
Change condition to stop TextRenderer#layout when a width limit is reached
DEVSIX-1192 Autoported commit. Original commit hash: [2ad033498e]
1 parent 121aa09 commit 8161b74

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

itext/itext.layout/itext/layout/renderer/LineRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,13 +1795,13 @@ internal virtual LineRenderer.LastFittingChildRendererData GetIndexAndLayoutResu
17951795
break;
17961796
}
17971797
if (textLayoutResult.IsContainsPossibleBreak() && textLayoutResult.GetStatus() != LayoutResult.NOTHING) {
1798-
textRenderer.SetLayoutUntilTheLastPossibleBreak(true);
1798+
textRenderer.SetFirstIndexExceedingAvailableWidth(textRenderer.line.end);
17991799
// todo ? relayout in original bBox rather than occupied on the first layout area
18001800
LayoutArea layoutArea = textRenderer.GetOccupiedArea().Clone();
18011801
layoutArea.GetBBox().IncreaseHeight(0.0001F).IncreaseWidth(0.0001F);
18021802
LayoutResult newChildLayoutResult = textRenderer.Layout(new LayoutContext(layoutArea, wasParentsHeightClipped
18031803
));
1804-
textRenderer.SetLayoutUntilTheLastPossibleBreak(false);
1804+
textRenderer.SetFirstIndexExceedingAvailableWidth(-1);
18051805
if (newChildLayoutResult.GetStatus() == LayoutResult.FULL) {
18061806
lastAnalyzedTextLayoutResult = new TextLayoutResult(LayoutResult.NOTHING, null, null, childRenderers[lastAnalyzedTextRenderer
18071807
]);

itext/itext.layout/itext/layout/renderer/TextRenderer.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class TextRenderer : AbstractRenderer, ILeafElementRenderer {
116116

117117
private int specialScriptFirstNotFittingIndex = -1;
118118

119-
private bool layoutUntilTheLastPossibleBreak = false;
119+
private int firstIndexExceedingAvailableWidth = -1;
120120

121121
/// <summary>Creates a TextRenderer from its corresponding layout object.</summary>
122122
/// <param name="textElement">
@@ -303,8 +303,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
303303
== mode) {
304304
containsPossibleBreak = true;
305305
}
306-
if (ind + 1 == text.end || nextGlyphIsSpaceOrWhiteSpace) {
307-
if (ind + 1 == text.end && layoutUntilTheLastPossibleBreak) {
306+
if (ind + 1 == text.end || nextGlyphIsSpaceOrWhiteSpace || (ind + 1 >= firstIndexExceedingAvailableWidth &&
307+
firstIndexExceedingAvailableWidth != -1)) {
308+
if (ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != -1) {
308309
firstCharacterWhichExceedsAllowedWidth = currentTextPos;
309310
break;
310311
}
@@ -386,8 +387,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
386387
containsPossibleBreak = true;
387388
}
388389
if (ind + 1 == text.end || endOfNonBreakablePartCausedBySplitCharacter || endOfWordBelongingToSpecialScripts
389-
) {
390-
if (ind + 1 == text.end && layoutUntilTheLastPossibleBreak && !endOfNonBreakablePartCausedBySplitCharacter
390+
|| (ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != -1)) {
391+
if (ind + 1 >= firstIndexExceedingAvailableWidth && firstIndexExceedingAvailableWidth != -1 && !endOfNonBreakablePartCausedBySplitCharacter
391392
) {
392393
firstCharacterWhichExceedsAllowedWidth = currentTextPos;
393394
}
@@ -440,7 +441,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
440441
// cannot fit a word as a whole
441442
bool wordSplit = false;
442443
bool hyphenationApplied = false;
443-
if (hyphenationConfig != null && !layoutUntilTheLastPossibleBreak) {
444+
if (hyphenationConfig != null && firstIndexExceedingAvailableWidth == -1) {
444445
if (-1 == nonBreakingHyphenRelatedChunkStart) {
445446
int[] wordBounds = GetWordBoundsForHyphenation(text, currentTextPos, text.end, Math.Max(currentTextPos, firstCharacterWhichExceedsAllowedWidth
446447
- 1));
@@ -841,7 +842,7 @@ public override void Draw(DrawContext drawContext) {
841842
if (horizontalScaling != null && horizontalScaling != 1) {
842843
canvas.SetHorizontalScaling((float)horizontalScaling * 100);
843844
}
844-
GlyphLine.IGlyphLineFilter filter = new _IGlyphLineFilter_909();
845+
GlyphLine.IGlyphLineFilter filter = new _IGlyphLineFilter_912();
845846
bool appearanceStreamLayout = true.Equals(GetPropertyAsBoolean(Property.APPEARANCE_STREAM_LAYOUT));
846847
if (GetReversedRanges() != null) {
847848
bool writeReversedChars = !appearanceStreamLayout;
@@ -903,8 +904,8 @@ public override void Draw(DrawContext drawContext) {
903904
}
904905
}
905906

906-
private sealed class _IGlyphLineFilter_909 : GlyphLine.IGlyphLineFilter {
907-
public _IGlyphLineFilter_909() {
907+
private sealed class _IGlyphLineFilter_912 : GlyphLine.IGlyphLineFilter {
908+
public _IGlyphLineFilter_912() {
908909
}
909910

910911
public bool Accept(Glyph glyph) {
@@ -1250,8 +1251,8 @@ internal virtual int GetSpecialScriptFirstNotFittingIndex() {
12501251
return specialScriptFirstNotFittingIndex;
12511252
}
12521253

1253-
internal virtual void SetLayoutUntilTheLastPossibleBreak(bool layoutUntilTheLastPossibleBreak) {
1254-
this.layoutUntilTheLastPossibleBreak = layoutUntilTheLastPossibleBreak;
1254+
internal virtual void SetFirstIndexExceedingAvailableWidth(int firstIndexExceedingAvailableWidth) {
1255+
this.firstIndexExceedingAvailableWidth = firstIndexExceedingAvailableWidth;
12551256
}
12561257

12571258
protected internal override Rectangle GetBackgroundArea(Rectangle occupiedAreaWithMargins) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
331d41b5533e9497787a729455f3aa0e0696c741
1+
2ad033498ee9a34948862200a45799746231aa3a

0 commit comments

Comments
 (0)