Skip to content

Commit c5c3c19

Browse files
Evgeniy PrudnikovUbuntu
authored andcommitted
Add ticket number and tests for the corresponding TODOs
DEVSIX-6453
1 parent 9f10d14 commit c5c3c19

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
284284
fixOccupiedAreaIfOverflowedX(overflowX, layoutBox);
285285

286286
if (result.getSplitRenderer() != null) {
287-
// Use occupied area's bbox width so that for absolutely positioned renderers we do not align using full width
288-
// in case when parent box should wrap around child boxes.
289-
// TODO in the latter case, all elements should be layouted first so that we know maximum width needed to place all children and then apply horizontal alignment
287+
// TODO DEVSIX-6488 all elements should be layouted first in case when parent box should wrap around child boxes
290288
alignChildHorizontally(result.getSplitRenderer(), occupiedArea.getBBox());
291289
}
292290

@@ -340,9 +338,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
340338
if (result.getStatus() == LayoutResult.FULL) {
341339
decreaseLayoutBoxAfterChildPlacement(layoutBox, result, childRenderer);
342340
if (childRenderer.getOccupiedArea() != null) {
343-
// Use occupied area's bbox width so that for absolutely positioned renderers we do not align using full width
344-
// in case when parent box should wrap around child boxes.
345-
// TODO in the latter case, all elements should be layouted first so that we know maximum width needed to place all children and then apply horizontal alignment
341+
// TODO DEVSIX-6488 all elements should be layouted first in case when parent box should wrap around child boxes
346342
alignChildHorizontally(childRenderer, occupiedArea.getBBox());
347343
}
348344
}

layout/src/test/java/com/itextpdf/layout/renderer/BlockRendererTest.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,45 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.layout.renderer;
2424

25+
import com.itextpdf.io.logs.IoLogMessageConstant;
26+
import com.itextpdf.kernel.colors.ColorConstants;
2527
import com.itextpdf.kernel.geom.Rectangle;
28+
import com.itextpdf.kernel.pdf.PdfDocument;
29+
import com.itextpdf.kernel.pdf.PdfWriter;
30+
import com.itextpdf.kernel.utils.CompareTool;
31+
import com.itextpdf.layout.Document;
2632
import com.itextpdf.layout.element.Div;
33+
import com.itextpdf.layout.element.Paragraph;
2734
import com.itextpdf.layout.layout.LayoutArea;
35+
import com.itextpdf.layout.layout.LayoutPosition;
2836
import com.itextpdf.layout.properties.OverflowPropertyValue;
37+
import com.itextpdf.layout.properties.Property;
2938
import com.itextpdf.layout.properties.UnitValue;
3039
import com.itextpdf.test.ExtendedITextTest;
40+
import com.itextpdf.test.LogLevelConstants;
41+
import com.itextpdf.test.annotations.LogMessage;
42+
import com.itextpdf.test.annotations.LogMessages;
3143
import com.itextpdf.test.annotations.type.IntegrationTest;
3244

45+
import java.io.IOException;
3346
import org.junit.Assert;
47+
import org.junit.BeforeClass;
3448
import org.junit.Test;
3549
import org.junit.experimental.categories.Category;
3650

3751
@Category(IntegrationTest.class)
3852
public class BlockRendererTest extends ExtendedITextTest {
3953

54+
public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/layout/BlockRendererTest/";
55+
public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/layout/BlockRendererTest/";
56+
57+
@BeforeClass
58+
public static void beforeClass() {
59+
createOrClearDestinationFolder(DESTINATION_FOLDER);
60+
}
61+
4062
@Test
41-
public void applyMinHeightForSpecificDimensionsCausingFloatPrecisionError () {
63+
public void applyMinHeightForSpecificDimensionsCausingFloatPrecisionErrorTest() {
4264
float divHeight = 42.55f;
4365

4466
Div div = new Div();
@@ -55,4 +77,40 @@ public void applyMinHeightForSpecificDimensionsCausingFloatPrecisionError () {
5577
new Rectangle(0, 243.40012f, 0, leftHeight));
5678
Assert.assertNull(renderer);
5779
}
80+
81+
@Test
82+
@LogMessages(messages = {
83+
@LogMessage(messageTemplate = IoLogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, count = 2,
84+
logLevel = LogLevelConstants.ERROR)
85+
})
86+
// TODO DEVSIX-6488 all elements should be layouted first in case when parent box should wrap around child boxes
87+
public void parentBoxWrapAroundChildBoxesTest() throws IOException, InterruptedException {
88+
String cmpFileName = SOURCE_FOLDER + "cmp_parentBoxWrapAroundChildBoxes.pdf";
89+
String outFile = DESTINATION_FOLDER + "parentBoxWrapAroundChildBoxes.pdf";
90+
int enoughDivsToOccupyWholePage = 30;
91+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
92+
93+
Div div = new Div();
94+
div.setBackgroundColor(ColorConstants.CYAN);
95+
div.setProperty(Property.POSITION, LayoutPosition.ABSOLUTE);
96+
97+
Div childDiv = new Div();
98+
childDiv.add(new Paragraph("ChildDiv"));
99+
childDiv.setBackgroundColor(ColorConstants.YELLOW);
100+
childDiv.setWidth(100);
101+
102+
for (int i = 0; enoughDivsToOccupyWholePage > i; i++) {
103+
div.add(childDiv);
104+
}
105+
Div divThatDoesntFitButItsWidthShouldBeConsidered = new Div();
106+
divThatDoesntFitButItsWidthShouldBeConsidered.add(new Paragraph("ChildDiv1"));
107+
divThatDoesntFitButItsWidthShouldBeConsidered.setBackgroundColor(ColorConstants.GREEN);
108+
divThatDoesntFitButItsWidthShouldBeConsidered.setWidth(200);
109+
110+
div.add(divThatDoesntFitButItsWidthShouldBeConsidered);
111+
document.add(div);
112+
113+
document.close();
114+
Assert.assertNull(new CompareTool().compareByContent(outFile, cmpFileName, DESTINATION_FOLDER));
115+
}
58116
}

0 commit comments

Comments
 (0)