Skip to content

Commit cfcaeef

Browse files
ars18wrwiText-CI
authored andcommitted
Skip KEEP_TOGETHER in case of AreaBreak
DEVSIX-5156 Autoported commit. Original commit hash: [6328d385a]
1 parent 17a37ee commit cfcaeef

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

itext.tests/itext.layout.tests/itext/layout/KeepTogetherTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ source product.
4141
4242
*/
4343
using System;
44+
using System.IO;
4445
using System.Text;
4546
using iText.IO.Font.Constants;
4647
using iText.IO.Image;
@@ -100,6 +101,20 @@ public virtual void KeepTogetherParagraphTest01() {
100101
"diff"));
101102
}
102103

104+
[NUnit.Framework.Test]
105+
public virtual void SkipKeepTogetherInCaseOfAreaBreak() {
106+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
107+
Document doc = new Document(pdfDoc);
108+
Div keptTogetherDiv = new Div();
109+
keptTogetherDiv.SetKeepTogether(true);
110+
AreaBreak areaBreak = new AreaBreak();
111+
keptTogetherDiv.Add(areaBreak);
112+
doc.Add(keptTogetherDiv);
113+
// If this line is not triggered, then an NPE occurred
114+
NUnit.Framework.Assert.IsTrue(true);
115+
doc.Close();
116+
}
117+
103118
[NUnit.Framework.Test]
104119
[LogMessage(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
105120
public virtual void KeepTogetherParagraphTest02() {

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,11 @@ protected internal virtual bool IsAbsolutePosition() {
20992099
}
21002100

21012101
protected internal virtual bool IsKeepTogether() {
2102-
return true.Equals(GetPropertyAsBoolean(Property.KEEP_TOGETHER));
2102+
return IsKeepTogether(null);
2103+
}
2104+
2105+
internal virtual bool IsKeepTogether(IRenderer causeOfNothing) {
2106+
return true.Equals(GetPropertyAsBoolean(Property.KEEP_TOGETHER)) && !(causeOfNothing is AreaBreakRenderer);
21032107
}
21042108

21052109
// Note! The second parameter is here on purpose. Currently occupied area is passed as a value of this parameter in

itext/itext.layout/itext/layout/renderer/BlockRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
155155
FloatingHelper.IncludeChildFloatsInOccupiedArea(floatRendererAreas, this, nonChildFloatingRendererAreas);
156156
FixOccupiedAreaIfOverflowedX(overflowX, layoutBox);
157157
result = new LayoutResult(LayoutResult.NOTHING, null, null, childRenderer);
158-
bool isKeepTogether = IsKeepTogether();
158+
bool isKeepTogether = IsKeepTogether(childRenderer);
159159
int layoutResult = anythingPlaced && !isKeepTogether ? LayoutResult.PARTIAL : LayoutResult.NOTHING;
160160
AbstractRenderer[] splitAndOverflowRenderers = CreateSplitAndOverflowRenderers(childPos, layoutResult, result
161161
, waitingFloatsSplitRenderers, waitingOverflowFloatRenderers);
@@ -736,7 +736,7 @@ internal virtual LayoutResult ProcessNotFullChildResult(LayoutContext layoutCont
736736
}
737737
else {
738738
if (result.GetStatus() == LayoutResult.NOTHING) {
739-
bool keepTogether = IsKeepTogether();
739+
bool keepTogether = IsKeepTogether(causeOfNothing);
740740
int layoutResult = anythingPlaced && !keepTogether ? LayoutResult.PARTIAL : LayoutResult.NOTHING;
741741
AbstractRenderer[] splitAndOverflowRenderers = CreateSplitAndOverflowRenderers(childPos, layoutResult, result
742742
, waitingFloatsSplitRenderers, waitingOverflowFloatRenderers);

itext/itext.layout/itext/layout/renderer/FlexContainerRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ internal override LayoutResult ProcessNotFullChildResult(LayoutContext layoutCon
175175
[] borders, UnitValue[] paddings, IList<Rectangle> areas, int currentAreaPos, Rectangle layoutBox, ICollection
176176
<Rectangle> nonChildFloatingRendererAreas, IRenderer causeOfNothing, bool anythingPlaced, int childPos
177177
, LayoutResult result) {
178-
bool keepTogether = IsKeepTogether();
178+
bool keepTogether = IsKeepTogether(causeOfNothing);
179179
AbstractRenderer[] splitAndOverflowRenderers = CreateSplitAndOverflowRenderers(childPos, result.GetStatus(
180180
), result, waitingFloatsSplitRenderers, waitingOverflowFloatRenderers);
181181
AbstractRenderer splitRenderer = splitAndOverflowRenderers[0];

itext/itext.layout/itext/layout/renderer/ParagraphRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ protected internal virtual LayoutResult DirectLayout(LayoutContext layoutContext
279279
firstLineInBox = true;
280280
}
281281
else {
282-
bool keepTogether = IsKeepTogether();
282+
bool keepTogether = IsKeepTogether(result.GetCauseOfNothing());
283283
if (keepTogether) {
284284
floatRendererAreas.RetainAll(nonChildFloatingRendererAreas);
285285
return new MinMaxWidthLayoutResult(LayoutResult.NOTHING, null, null, this, null == result.GetCauseOfNothing

itext/itext.layout/itext/layout/renderer/TableRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
887887
overflowRows.SetCell(row - splitResult[0].rows.Count, entry.Key, null);
888888
}
889889
}
890-
if ((IsKeepTogether() && 0 == lastFlushedRowBottomBorder.Count) && !true.Equals(GetPropertyAsBoolean(Property
891-
.FORCED_PLACEMENT))) {
890+
if (IsKeepTogether(firstCauseOfNothing) && 0 == lastFlushedRowBottomBorder.Count && !true.Equals(GetPropertyAsBoolean
891+
(Property.FORCED_PLACEMENT))) {
892892
return new LayoutResult(LayoutResult.NOTHING, null, null, this, null == firstCauseOfNothing ? this : firstCauseOfNothing
893893
);
894894
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
504a9a8cf451797fa1aa8ff775cf7ecb09012c41
1+
6328d385a64fd46355e1bbccdf94b8fb394d849a

0 commit comments

Comments
 (0)