Skip to content

Commit 29a58d6

Browse files
code review fixes
DEVSIX-1267
1 parent 90f44ff commit 29a58d6

File tree

10 files changed

+12
-48
lines changed

10 files changed

+12
-48
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,17 +538,23 @@ public void drawBackground(DrawContext drawContext) {
538538
* @param drawContext the context (canvas, document, etc) of this drawing operation.
539539
*/
540540
public void drawChildren(DrawContext drawContext) {
541+
List<IRenderer> waitingRenderers = new ArrayList<>();
541542
for (IRenderer child : childRenderers) {
542543
if (FloatingHelper.isRendererFloating(child)) {
543544
RootRenderer rootRenderer = getRootRenderer();
544545
if (rootRenderer != null) {
545546
rootRenderer.waitingDrawingElements.add(child);
546547
child.setProperty(Property.FLOAT, null);
548+
} else {
549+
waitingRenderers.add(child);
547550
}
548551
} else {
549552
child.draw(drawContext);
550553
}
551554
}
555+
for (IRenderer waitingRenderer : waitingRenderers) {
556+
waitingRenderer.draw(drawContext);
557+
}
552558
}
553559

554560
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
165165
// the first renderer (one of childRenderers or their children) to produce LayoutResult.NOTHING
166166
IRenderer causeOfNothing = null;
167167
boolean anythingPlaced = false;
168-
for (int childPos = 0, length = childRenderers.size(); childPos < length; childPos++) {
168+
for (int childPos = 0; childPos < childRenderers.size(); childPos++) {
169169
IRenderer childRenderer = childRenderers.get(childPos);
170170
LayoutResult result;
171171
childRenderer.setParent(this);
@@ -363,7 +363,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
363363
result.getOverflowRenderer().setProperty(Property.MARGIN_LEFT, marginLeft + leftPoint - occupiedArea.getBBox().getLeft());
364364
}
365365
childRenderers.remove(childPos);
366-
length--;
367366
childPos--;
368367
waitingOverflowRenderers.add(result.getOverflowRenderer());
369368
break;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
122122
applyBorderBox(layoutBox, borders, false);
123123

124124
if (isAbsolutePosition()) {
125-
// TODO applying it after floats processing here and everywhere. is it correct?
126125
applyAbsolutePosition(layoutBox);
127126
}
128127

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
425425
if (anythingPlaced || floatsPlaced) {
426426
result = new LineLayoutResult(LayoutResult.PARTIAL, occupiedArea, split[0], split[1], causeOfNothing);
427427
} else {
428-
result = new LineLayoutResult(LayoutResult.NOTHING, null, split[0], split[1], causeOfNothing);
428+
result = new LineLayoutResult(LayoutResult.NOTHING, null, split[0], split[1], null);
429429
}
430430
}
431431
if (newLineOccurred) {

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -183,39 +183,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
183183
float lineIndent = anythingPlaced ? 0 : (float) this.getPropertyAsFloat(Property.FIRST_LINE_INDENT);
184184
float childBBoxWidth = layoutBox.getWidth() - lineIndent;
185185
Rectangle childLayoutBox = new Rectangle(layoutBox.getX() + lineIndent, layoutBox.getY(), childBBoxWidth, layoutBox.getHeight());
186-
187-
// if (childAffectedByFloat) {
188-
// currentRenderer.layout(new LayoutContext(new LayoutArea(pageNumber, childLayoutBox), layoutContext.getMarginsCollapseInfo(), floatRendererAreas));
189-
// float bottom = currentRenderer.getOccupiedArea().getBBox().getBottom();
190-
// float top = currentRenderer.getOccupiedArea().getBBox().getTop();
191-
// float left = currentRenderer.getOccupiedArea().getBBox().getLeft();
192-
// float right = currentRenderer.getOccupiedArea().getBBox().getRight();
193-
// boolean childLayoutBoxWasAdjusted;
194-
// float rightBorder = childLayoutBox.getRight();
195-
// float curRendWidth = currentRenderer.getOccupiedAreaBBox().getWidth();
196-
// do {
197-
// childLayoutBoxWasAdjusted = false;
198-
// for (Rectangle floatRendereArea : floatRendererAreas) {
199-
// if ((bottom > floatRendereArea.getBottom() && bottom < floatRendereArea.getTop()) || (top > floatRendereArea.getBottom() && top < floatRendereArea.getTop())) {
200-
// if ((left >= floatRendereArea.getLeft() && left < floatRendereArea.getRight()) ||
201-
// (right > floatRendereArea.getLeft() && right < floatRendereArea.getRight()) ||
202-
// (left > floatRendereArea.getLeft() && right < floatRendereArea.getRight())) {
203-
// childLayoutBox.setX(floatRendereArea.getRight());
204-
//
205-
//
206-
// if (childLayoutBox.getLeft() + curRendWidth > rightBorder) {
207-
// childLayoutBox.setWidth(rightBorder - childLayoutBox.getLeft());
208-
// } else {
209-
// childLayoutBox.setWidth(curRendWidth);
210-
// }
211-
// left = childLayoutBox.getLeft();
212-
// right = childLayoutBox.getRight();
213-
// childLayoutBoxWasAdjusted = true;
214-
// }
215-
// }
216-
// }
217-
// } while(childLayoutBoxWasAdjusted);
218-
// }
219186
LineLayoutResult result = ((LineRenderer) currentRenderer.setParent(this)).layout(new LayoutContext(
220187
new LayoutArea(pageNumber, childLayoutBox), null,
221188
floatRendererAreas));

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void addChild(IRenderer renderer) {
103103
}
104104

105105
// Static layout
106-
for (int i = 0, l = addedRenderers.size(); currentArea != null && i < l; i++) {
106+
for (int i = 0; currentArea != null && i < addedRenderers.size(); i++) {
107107
renderer = addedRenderers.get(i);
108108

109109
processWaitingKeepWithNextElement(renderer);
@@ -193,7 +193,6 @@ public void addChild(IRenderer renderer) {
193193
renderer = waitingRenderers.remove(0);
194194
addedRenderers.addAll(waitingRenderers);
195195
addedRenderers.add(result.getOverflowRenderer());
196-
l+= waitingRenderers.size() + 1;
197196
} else {
198197
renderer = result.getOverflowRenderer();
199198
}
@@ -320,7 +319,7 @@ protected void shrinkCurrentAreaAndProcessRenderer(IRenderer renderer, List<IRen
320319
if (currentArea != null) {
321320
float resultRendererHeight = result.getOccupiedArea().getBBox().getHeight();
322321
currentArea.getBBox().setHeight(currentArea.getBBox().getHeight() - resultRendererHeight);
323-
if (currentArea.isEmptyArea() && resultRendererHeight > 0) {
322+
if (currentArea.isEmptyArea() && (resultRendererHeight > 0 || FloatingHelper.isRendererFloating(renderer))) {
324323
currentArea.setEmptyArea(false);
325324
}
326325
processRenderer(renderer, resultRenderers);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ public LayoutResult layout(LayoutContext layoutContext) {
336336
// if this is the last renderer, we will use that information to enlarge rows proportionally
337337
List<Boolean> rowsHasCellWithSetHeight = new ArrayList<>();
338338

339-
List<Rectangle> childFloatRendererAreas = new ArrayList<>();
340339
for (row = 0; row < rows.size(); row++) {
340+
List<Rectangle> childFloatRendererAreas = new ArrayList<>();
341341
// if forced placement was earlier set, this means the element did not fit into the area, and in this case
342342
// we only want to place the first row in a forced way, not the next ones, otherwise they will be invisible
343343
if (row == 1 && Boolean.TRUE.equals(this.<Boolean>getProperty(Property.FORCED_PLACEMENT))) {

layout/src/test/java/com/itextpdf/layout/FloatTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ This file is part of the iText (R) project.
6868
import com.itextpdf.test.annotations.type.IntegrationTest;
6969
import org.junit.Assert;
7070
import org.junit.BeforeClass;
71-
import org.junit.Ignore;
7271
import org.junit.Test;
7372
import org.junit.experimental.categories.Category;
7473

@@ -222,12 +221,7 @@ public void floatDivTest02() throws IOException, InterruptedException {
222221
}
223222

224223
@Test
225-
@Ignore("block level floating elements page-overflow and splitting not supported yet")
226224
public void floatDivTest03() throws IOException, InterruptedException {
227-
//
228-
// TODO probably we shouldn't review forced placement applying on floated elements
229-
// May be check if there are any floated elements already on page
230-
//
231225
String cmpFileName = sourceFolder + "cmp_floatDivTest03.pdf";
232226
String outFile = destinationFolder + "floatDivTest03.pdf";
233227

@@ -289,7 +283,7 @@ public void floatingImageInCell() throws IOException, InterruptedException {
289283
}
290284

291285
@Test
292-
@Ignore("block level floating elements page-overflow and splitting not supported yet")
286+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA))
293287
public void floatingImageToNextPage() throws IOException, InterruptedException {
294288
String cmpFileName = sourceFolder + "cmp_floatingImageToNextPage.pdf";
295289
String outFile = destinationFolder + "floatingImageToNextPage.pdf";
Binary file not shown.

0 commit comments

Comments
 (0)