Skip to content

Commit 3540e50

Browse files
code review fixes
DEVSIX-1267 Autoported commit. Original commit hash: [29a58d612]
1 parent e4319b1 commit 3540e50

File tree

11 files changed

+15
-47
lines changed

11 files changed

+15
-47
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,7 @@ public virtual void FloatDivTest02() {
200200
/// <exception cref="System.IO.IOException"/>
201201
/// <exception cref="System.Exception"/>
202202
[NUnit.Framework.Test]
203-
[NUnit.Framework.Ignore("block level floating elements page-overflow and splitting not supported yet")]
204203
public virtual void FloatDivTest03() {
205-
//
206-
// TODO probably we shouldn't review forced placement applying on floated elements
207-
// May be check if there are any floated elements already on page
208-
//
209204
String cmpFileName = sourceFolder + "cmp_floatDivTest03.pdf";
210205
String outFile = destinationFolder + "floatDivTest03.pdf";
211206
PdfWriter writer = new PdfWriter(outFile);
@@ -264,7 +259,7 @@ public virtual void FloatingImageInCell() {
264259
/// <exception cref="System.IO.IOException"/>
265260
/// <exception cref="System.Exception"/>
266261
[NUnit.Framework.Test]
267-
[NUnit.Framework.Ignore("block level floating elements page-overflow and splitting not supported yet")]
262+
[LogMessage(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
268263
public virtual void FloatingImageToNextPage() {
269264
String cmpFileName = sourceFolder + "cmp_floatingImageToNextPage.pdf";
270265
String outFile = destinationFolder + "floatingImageToNextPage.pdf";
Binary file not shown.
Binary file not shown.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,18 +520,25 @@ public virtual void DrawBackground(DrawContext drawContext) {
520520
/// </summary>
521521
/// <param name="drawContext">the context (canvas, document, etc) of this drawing operation.</param>
522522
public virtual void DrawChildren(DrawContext drawContext) {
523+
IList<IRenderer> waitingRenderers = new List<IRenderer>();
523524
foreach (IRenderer child in childRenderers) {
524525
if (FloatingHelper.IsRendererFloating(child)) {
525526
RootRenderer rootRenderer = GetRootRenderer();
526527
if (rootRenderer != null) {
527528
rootRenderer.waitingDrawingElements.Add(child);
528529
child.SetProperty(Property.FLOAT, null);
529530
}
531+
else {
532+
waitingRenderers.Add(child);
533+
}
530534
}
531535
else {
532536
child.Draw(drawContext);
533537
}
534538
}
539+
foreach (IRenderer waitingRenderer in waitingRenderers) {
540+
waitingRenderer.Draw(drawContext);
541+
}
535542
}
536543

537544
/// <summary>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
137137
// the first renderer (one of childRenderers or their children) to produce LayoutResult.NOTHING
138138
IRenderer causeOfNothing = null;
139139
bool anythingPlaced = false;
140-
for (int childPos = 0; childPos < length; childPos++) {
140+
for (int childPos = 0; childPos < childRenderers.Count; childPos++) {
141141
IRenderer childRenderer = childRenderers[childPos];
142142
LayoutResult result;
143143
childRenderer.SetParent(this);
@@ -343,7 +343,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
343343
().GetLeft());
344344
}
345345
childRenderers.JRemoveAt(childPos);
346-
length--;
347346
childPos--;
348347
waitingOverflowRenderers.Add(result.GetOverflowRenderer());
349348
break;

itext/itext.layout/itext/layout/renderer/ImageRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
119119
Border[] borders = GetBorders();
120120
ApplyBorderBox(layoutBox, borders, false);
121121
if (IsAbsolutePosition()) {
122-
// TODO applying it after floats processing here and everywhere. is it correct?
123122
ApplyAbsolutePosition(layoutBox);
124123
}
125124
occupiedArea = new LayoutArea(area.GetPageNumber(), new Rectangle(layoutBox.GetX(), layoutBox.GetY() + layoutBox

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
423423
result = new LineLayoutResult(LayoutResult.PARTIAL, occupiedArea, split[0], split[1], causeOfNothing);
424424
}
425425
else {
426-
result = new LineLayoutResult(LayoutResult.NOTHING, null, split[0], split[1], causeOfNothing);
426+
result = new LineLayoutResult(LayoutResult.NOTHING, null, split[0], split[1], null);
427427
}
428428
}
429429
if (newLineOccurred) {

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -169,38 +169,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
169169
float childBBoxWidth = layoutBox.GetWidth() - lineIndent;
170170
Rectangle childLayoutBox = new Rectangle(layoutBox.GetX() + lineIndent, layoutBox.GetY(), childBBoxWidth,
171171
layoutBox.GetHeight());
172-
// if (childAffectedByFloat) {
173-
// currentRenderer.layout(new LayoutContext(new LayoutArea(pageNumber, childLayoutBox), layoutContext.getMarginsCollapseInfo(), floatRendererAreas));
174-
// float bottom = currentRenderer.getOccupiedArea().getBBox().getBottom();
175-
// float top = currentRenderer.getOccupiedArea().getBBox().getTop();
176-
// float left = currentRenderer.getOccupiedArea().getBBox().getLeft();
177-
// float right = currentRenderer.getOccupiedArea().getBBox().getRight();
178-
// boolean childLayoutBoxWasAdjusted;
179-
// float rightBorder = childLayoutBox.getRight();
180-
// float curRendWidth = currentRenderer.getOccupiedAreaBBox().getWidth();
181-
// do {
182-
// childLayoutBoxWasAdjusted = false;
183-
// for (Rectangle floatRendereArea : floatRendererAreas) {
184-
// if ((bottom > floatRendereArea.getBottom() && bottom < floatRendereArea.getTop()) || (top > floatRendereArea.getBottom() && top < floatRendereArea.getTop())) {
185-
// if ((left >= floatRendereArea.getLeft() && left < floatRendereArea.getRight()) ||
186-
// (right > floatRendereArea.getLeft() && right < floatRendereArea.getRight()) ||
187-
// (left > floatRendereArea.getLeft() && right < floatRendereArea.getRight())) {
188-
// childLayoutBox.setX(floatRendereArea.getRight());
189-
//
190-
//
191-
// if (childLayoutBox.getLeft() + curRendWidth > rightBorder) {
192-
// childLayoutBox.setWidth(rightBorder - childLayoutBox.getLeft());
193-
// } else {
194-
// childLayoutBox.setWidth(curRendWidth);
195-
// }
196-
// left = childLayoutBox.getLeft();
197-
// right = childLayoutBox.getRight();
198-
// childLayoutBoxWasAdjusted = true;
199-
// }
200-
// }
201-
// }
202-
// } while(childLayoutBoxWasAdjusted);
203-
// }
204172
LineLayoutResult result = ((LineLayoutResult)((LineRenderer)currentRenderer.SetParent(this)).Layout(new LayoutContext
205173
(new LayoutArea(pageNumber, childLayoutBox), null, floatRendererAreas)));
206174
if (result.GetStatus() == LayoutResult.NOTHING) {

itext/itext.layout/itext/layout/renderer/RootRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override void AddChild(IRenderer renderer) {
100100
}
101101
}
102102
// Static layout
103-
for (int i = 0; currentArea != null && i < l; i++) {
103+
for (int i = 0; currentArea != null && i < addedRenderers.Count; i++) {
104104
renderer = addedRenderers[i];
105105
ProcessWaitingKeepWithNextElement(renderer);
106106
IList<IRenderer> resultRenderers = new List<IRenderer>();
@@ -206,7 +206,6 @@ public override void AddChild(IRenderer renderer) {
206206
renderer = waitingRenderers.JRemoveAt(0);
207207
addedRenderers.AddAll(waitingRenderers);
208208
addedRenderers.Add(result.GetOverflowRenderer());
209-
l += waitingRenderers.Count + 1;
210209
}
211210
else {
212211
renderer = result.GetOverflowRenderer();
@@ -334,7 +333,8 @@ protected internal virtual void ShrinkCurrentAreaAndProcessRenderer(IRenderer re
334333
if (currentArea != null) {
335334
float resultRendererHeight = result.GetOccupiedArea().GetBBox().GetHeight();
336335
currentArea.GetBBox().SetHeight(currentArea.GetBBox().GetHeight() - resultRendererHeight);
337-
if (currentArea.IsEmptyArea() && resultRendererHeight > 0) {
336+
if (currentArea.IsEmptyArea() && (resultRendererHeight > 0 || FloatingHelper.IsRendererFloating(renderer))
337+
) {
338338
currentArea.SetEmptyArea(false);
339339
}
340340
ProcessRenderer(renderer, resultRenderers);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
317317
int[] targetOverflowRowIndex = new int[numberOfColumns];
318318
// if this is the last renderer, we will use that information to enlarge rows proportionally
319319
IList<bool> rowsHasCellWithSetHeight = new List<bool>();
320-
IList<Rectangle> childFloatRendererAreas = new List<Rectangle>();
321320
for (row = 0; row < rows.Count; row++) {
321+
IList<Rectangle> childFloatRendererAreas = new List<Rectangle>();
322322
// if forced placement was earlier set, this means the element did not fit into the area, and in this case
323323
// we only want to place the first row in a forced way, not the next ones, otherwise they will be invisible
324324
if (row == 1 && true.Equals(this.GetProperty<bool?>(Property.FORCED_PLACEMENT))) {

0 commit comments

Comments
 (0)