Skip to content

Commit 80ab951

Browse files
yulian-gaponenkoitext-teamcity
authored andcommitted
Return adjusted by float and clear properties area for elements which have PARTIAL layout result
Autoported commit. Original commit hash: [9b2dfd9]
1 parent f9d1aa2 commit 80ab951

File tree

7 files changed

+96
-28
lines changed

7 files changed

+96
-28
lines changed

itext.tests/itext.layout.tests/itext/layout/FloatTest.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ source product.
5151
using iText.Layout.Element;
5252
using iText.Layout.Properties;
5353
using iText.Test;
54+
using iText.Test.Attributes;
5455

5556
namespace iText.Layout {
5657
public class FloatTest : ExtendedITextTest {
@@ -413,7 +414,7 @@ public virtual void FloatingImageInParagraph() {
413414
document.Add(p);
414415
document.Close();
415416
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
416-
"diff10_"));
417+
"diff11_"));
417418
}
418419

419420
/// <exception cref="System.IO.IOException"/>
@@ -449,7 +450,61 @@ public virtual void FloatsOnCanvas() {
449450
canvas.Close();
450451
pdfDoc.Close();
451452
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
452-
"diff10_"));
453+
"diff12_"));
454+
}
455+
456+
/// <exception cref="System.IO.IOException"/>
457+
/// <exception cref="System.Exception"/>
458+
[NUnit.Framework.Test]
459+
[LogMessage(iText.IO.LogMessageConstant.CLIP_ELEMENT, Count = 3)]
460+
public virtual void FloatFixedHeightContentNotFit() {
461+
String cmpFileName = sourceFolder + "cmp_floatFixedHeightContentNotFit.pdf";
462+
String outFile = destinationFolder + "floatFixedHeightContentNotFit.pdf";
463+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
464+
Div div = new Div().SetBorder(new SolidBorder(Color.RED, 2));
465+
div.Add(new Paragraph("Floating div.")).Add(new Paragraph(text));
466+
div.SetHeight(200).SetWidth(100);
467+
div.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
468+
document.Add(div);
469+
document.Add(new Paragraph(text));
470+
Paragraph p = new Paragraph("Floating p.\n" + text).SetBorder(new SolidBorder(Color.RED, 2));
471+
p.SetHeight(200).SetWidth(100);
472+
p.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
473+
document.Add(p);
474+
document.Add(new Paragraph(text));
475+
Table table = new Table(UnitValue.CreatePercentArray(new float[] { 0.3f, 0.7f })).SetBorder(new SolidBorder
476+
(Color.RED, 2));
477+
table.AddCell(new Paragraph("Floating table.")).AddCell(new Paragraph(text));
478+
table.SetHeight(200).SetWidth(300);
479+
table.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
480+
document.Add(table);
481+
document.Add(new Paragraph(text));
482+
document.Close();
483+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
484+
"diff13_"));
485+
}
486+
487+
/// <exception cref="System.IO.IOException"/>
488+
/// <exception cref="System.Exception"/>
489+
[NUnit.Framework.Test]
490+
public virtual void ClearanceApplyingPageSplit() {
491+
String cmpFileName = sourceFolder + "cmp_clearanceApplyingPageSplit.pdf";
492+
String outFile = destinationFolder + "clearanceApplyingPageSplit.pdf";
493+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
494+
document.Add(new Paragraph(text));
495+
Div div = new Div().SetBorder(new SolidBorder(Color.RED, 2));
496+
div.Add(new Paragraph("Floating div."));
497+
div.SetHeight(200).SetWidth(100);
498+
div.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
499+
document.Add(div);
500+
Div divClear = new Div().SetBackgroundColor(Color.GREEN);
501+
divClear.Add(new Paragraph("Cleared div.")).Add(new Paragraph(text));
502+
divClear.SetHeight(400);
503+
divClear.SetProperty(Property.CLEAR, ClearPropertyValue.BOTH);
504+
document.Add(divClear);
505+
document.Close();
506+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
507+
"diff13_"));
453508
}
454509
}
455510
}

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
164164
()));
165165
}
166166
}
167+
if (FloatingHelper.IsRendererFloating(this) || isCellRenderer) {
168+
FloatingHelper.IncludeChildFloatsInOccupiedArea(floatRendererAreas, this);
169+
}
167170
if (result.GetSplitRenderer() != null) {
168171
// Use occupied area's bbox width so that for absolutely positioned renderers we do not align using full width
169172
// in case when parent box should wrap around child boxes.
@@ -197,9 +200,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
197200
else {
198201
if (result.GetStatus() == LayoutResult.PARTIAL) {
199202
if (currentAreaPos + 1 == areas.Count) {
200-
if (FloatingHelper.IsRendererFloating(this) || isCellRenderer) {
201-
FloatingHelper.IncludeChildFloatsInOccupiedArea(floatRendererAreas, this);
202-
}
203203
AbstractRenderer splitRenderer = CreateSplitRenderer(LayoutResult.PARTIAL);
204204
splitRenderer.childRenderers = new List<IRenderer>(childRenderers.SubList(0, childPos));
205205
splitRenderer.childRenderers.Add(result.GetSplitRenderer());
@@ -231,12 +231,13 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
231231
ApplyPaddings(occupiedArea.GetBBox(), paddings, true);
232232
ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
233233
ApplyMargins(occupiedArea.GetBBox(), true);
234+
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
235+
(), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
234236
if (wasHeightClipped) {
235-
return new LayoutResult(LayoutResult.FULL, occupiedArea, splitRenderer, null);
237+
return new LayoutResult(LayoutResult.FULL, editedArea, splitRenderer, null);
236238
}
237239
else {
238-
return new LayoutResult(LayoutResult.PARTIAL, occupiedArea, splitRenderer, overflowRenderer, causeOfNothing
239-
);
240+
return new LayoutResult(LayoutResult.PARTIAL, editedArea, splitRenderer, overflowRenderer, causeOfNothing);
240241
}
241242
}
242243
else {
@@ -295,12 +296,14 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
295296
ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
296297
ApplyMargins(occupiedArea.GetBBox(), true);
297298
//splitRenderer.occupiedArea = occupiedArea.clone();
299+
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
300+
(), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
298301
if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) || wasHeightClipped) {
299-
return new LayoutResult(LayoutResult.FULL, occupiedArea, splitRenderer, null, null);
302+
return new LayoutResult(LayoutResult.FULL, editedArea, splitRenderer, null, null);
300303
}
301304
else {
302305
if (layoutResult != LayoutResult.NOTHING) {
303-
return new LayoutResult(layoutResult, occupiedArea, splitRenderer, overflowRenderer, null).SetAreaBreak(result
306+
return new LayoutResult(layoutResult, editedArea, splitRenderer, overflowRenderer, null).SetAreaBreak(result
304307
.GetAreaBreak());
305308
}
306309
else {
@@ -403,7 +406,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
403406
}
404407
ApplyVerticalAlignment();
405408
FloatingHelper.RemoveFloatsAboveRendererBottom(floatRendererAreas, this);
406-
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
409+
LayoutArea editedArea_1 = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
407410
(), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
408411
if (floatPropertyValue != null && !floatPropertyValue.Equals(FloatPropertyValue.NONE)) {
409412
// TODO anything like this on any other floated renderer?
@@ -418,10 +421,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
418421
}
419422
}
420423
if (null == overflowRenderer_1) {
421-
return new LayoutResult(LayoutResult.FULL, editedArea, null, null, causeOfNothing);
424+
return new LayoutResult(LayoutResult.FULL, editedArea_1, null, null, causeOfNothing);
422425
}
423426
else {
424-
return new LayoutResult(LayoutResult.PARTIAL, editedArea, this, overflowRenderer_1, causeOfNothing);
427+
return new LayoutResult(LayoutResult.PARTIAL, editedArea_1, this, overflowRenderer_1, causeOfNothing);
425428
}
426429
}
427430

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,22 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
296296
ApplyPaddings(occupiedArea.GetBBox(), paddings, true);
297297
ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
298298
ApplyMargins(occupiedArea.GetBBox(), true);
299+
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
300+
(), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
299301
if (wasHeightClipped) {
300-
return new MinMaxWidthLayoutResult(LayoutResult.FULL, occupiedArea, split[0], null).SetMinMaxWidth(minMaxWidth
302+
return new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, split[0], null).SetMinMaxWidth(minMaxWidth
301303
);
302304
}
303305
else {
304306
if (anythingPlaced) {
305-
return new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, occupiedArea, split[0], split[1]).SetMinMaxWidth(
306-
minMaxWidth);
307+
return new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea, split[0], split[1]).SetMinMaxWidth(minMaxWidth
308+
);
307309
}
308310
else {
309311
if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT))) {
310312
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), currentRenderer.GetOccupiedArea(
311313
).GetBBox()));
314+
editedArea.SetBBox(Rectangle.GetCommonRectangle(editedArea.GetBBox(), occupiedArea.GetBBox()));
312315
parent.SetProperty(Property.FULL, true);
313316
lines.Add(currentRenderer);
314317
// Force placement of children we have and do not force placement of the others
@@ -317,11 +320,11 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
317320
int firstNotRendered = currentRenderer.childRenderers.IndexOf(childNotRendered);
318321
currentRenderer.childRenderers.RetainAll(currentRenderer.childRenderers.SubList(0, firstNotRendered));
319322
split[1].childRenderers.RemoveAll(split[1].childRenderers.SubList(0, firstNotRendered));
320-
return new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, occupiedArea, this, split[1], null).SetMinMaxWidth
321-
(minMaxWidth);
323+
return new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea, this, split[1], null).SetMinMaxWidth(
324+
minMaxWidth);
322325
}
323326
else {
324-
return new MinMaxWidthLayoutResult(LayoutResult.FULL, occupiedArea, null, null, this).SetMinMaxWidth(minMaxWidth
327+
return new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, null, null, this).SetMinMaxWidth(minMaxWidth
325328
);
326329
}
327330
}
@@ -407,14 +410,14 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
407410
}
408411
}
409412
FloatingHelper.RemoveFloatsAboveRendererBottom(floatRendererAreas, this);
410-
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
413+
LayoutArea editedArea_1 = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas
411414
(), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
412415
if (null == overflowRenderer) {
413-
return new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, null, null, null).SetMinMaxWidth(minMaxWidth
416+
return new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea_1, null, null, null).SetMinMaxWidth(minMaxWidth
414417
);
415418
}
416419
else {
417-
return new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea, this, overflowRenderer, null).SetMinMaxWidth
420+
return new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea_1, this, overflowRenderer, null).SetMinMaxWidth
418421
(minMaxWidth);
419422
}
420423
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
772772
}
773773
ApplyFixedXOrYPosition(false, layoutBox);
774774
ApplyMargins(occupiedArea.GetBBox(), true);
775-
return new LayoutResult(LayoutResult.FULL, occupiedArea, splitResult[0], null);
775+
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, siblingFloatRendererAreas
776+
, layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
777+
return new LayoutResult(LayoutResult.FULL, editedArea, splitResult[0], null);
776778
}
777779
else {
778780
ApplyFixedXOrYPosition(false, layoutBox);
@@ -786,8 +788,13 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
786788
if (HasProperty(Property.MAX_HEIGHT)) {
787789
splitResult[1].SetProperty(Property.MAX_HEIGHT, RetrieveMaxHeight() - occupiedArea.GetBBox().GetHeight());
788790
}
789-
return new LayoutResult(status, status != LayoutResult.NOTHING ? occupiedArea : null, splitResult[0], splitResult
790-
[1], null == firstCauseOfNothing ? this : firstCauseOfNothing);
791+
LayoutArea editedArea = null;
792+
if (status != LayoutResult.NOTHING) {
793+
editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, siblingFloatRendererAreas, layoutContext
794+
.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
795+
}
796+
return new LayoutResult(status, editedArea, splitResult[0], splitResult[1], null == firstCauseOfNothing ?
797+
this : firstCauseOfNothing);
791798
}
792799
}
793800
}
@@ -900,9 +907,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
900907
}
901908
AdjustFooterAndFixOccupiedArea(layoutBox);
902909
FloatingHelper.RemoveFloatsAboveRendererBottom(siblingFloatRendererAreas, this);
903-
LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, siblingFloatRendererAreas
910+
LayoutArea editedArea_1 = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, siblingFloatRendererAreas
904911
, layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled);
905-
return new LayoutResult(LayoutResult.FULL, editedArea, null, null, null);
912+
return new LayoutResult(LayoutResult.FULL, editedArea_1, null, null, null);
906913
}
907914

908915
/// <summary><inheritDoc/></summary>

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e3aa7a26a3905b9c0238d37763f2cb7205181272
1+
9b2dfd99f1a709dc3b4b5df17e0dc53dd9a536e2

0 commit comments

Comments
 (0)