Skip to content

Commit 960e86e

Browse files
Implement float elements splitting
DEVSIX-1267
1 parent d3032e7 commit 960e86e

File tree

16 files changed

+107
-9
lines changed

16 files changed

+107
-9
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/form/renderer/AbstractFormFieldRenderer.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ This file is part of the iText (R) project.
5151
import com.itextpdf.layout.layout.LayoutResult;
5252
import com.itextpdf.layout.layout.MinMaxWidthLayoutResult;
5353
import com.itextpdf.layout.minmaxwidth.MinMaxWidth;
54+
import com.itextpdf.layout.property.FloatPropertyValue;
5455
import com.itextpdf.layout.property.Property;
5556
import com.itextpdf.layout.property.UnitValue;
56-
import com.itextpdf.layout.renderer.AbstractRenderer;
57-
import com.itextpdf.layout.renderer.BlockRenderer;
58-
import com.itextpdf.layout.renderer.DrawContext;
59-
import com.itextpdf.layout.renderer.ILeafElementRenderer;
60-
import com.itextpdf.layout.renderer.IRenderer;
57+
import com.itextpdf.layout.renderer.*;
6158
import org.slf4j.LoggerFactory;
6259

6360
/**
@@ -233,7 +230,22 @@ private LayoutResult layout(LayoutContext layoutContext, boolean minMaxWidth) {
233230
}
234231

235232
if (!Boolean.TRUE.equals(getPropertyAsBoolean(Property.FORCED_PLACEMENT)) && (result.getStatus() != LayoutResult.FULL)) {
236-
setProperty(Property.FORCED_PLACEMENT, true);
233+
//@TODO investigate this tricky code a little more.
234+
FloatPropertyValue floatPropertyValue = this.<FloatPropertyValue>getProperty(Property.FLOAT);
235+
if (floatPropertyValue == null || floatPropertyValue == FloatPropertyValue.NONE) {
236+
setProperty(Property.FORCED_PLACEMENT, true);
237+
} else {
238+
flatRenderer = childRenderers.get(0);
239+
childRenderers.clear();
240+
LayoutArea flatRendererOccupiedArea = flatRenderer.getOccupiedArea();
241+
applyPaddings(flatRendererOccupiedArea.getBBox(), true);
242+
applyBorderBox(flatRendererOccupiedArea.getBBox(), true);
243+
applyMargins(flatRendererOccupiedArea.getBBox(), true);
244+
childRenderers.add(flatRenderer);
245+
adjustFieldLayout();
246+
occupiedArea.setBBox(flatRenderer.getOccupiedArea().getBBox().clone());
247+
}
248+
237249
return new MinMaxWidthLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this).setMinMaxWidth(new MinMaxWidth(0, parentWidth));
238250
}
239251
if (!childRenderers.isEmpty()) {
@@ -265,5 +277,4 @@ private LayoutResult layout(LayoutContext layoutContext, boolean minMaxWidth) {
265277
return new MinMaxWidthLayoutResult(LayoutResult.FULL, occupiedArea, this, null)
266278
.setMinMaxWidth(new MinMaxWidth(0, parentWidth, occupiedArea.getBBox().getWidth(), occupiedArea.getBBox().getWidth()));
267279
}
268-
269280
}

src/test/java/com/itextpdf/html2pdf/css/FloatTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,21 @@ public void float54Test() throws IOException, InterruptedException {
359359
runTest("float54Test", "diff54_");
360360
}
361361

362+
@Test
363+
public void float55Test() throws IOException, InterruptedException {
364+
runTest("float55Test", "diff55_");
365+
}
366+
367+
@Test
368+
public void float57Test() throws IOException, InterruptedException {
369+
runTest("float57Test", "diff57_");
370+
}
371+
372+
@Test@Ignore("DEVSIX-1372")
373+
public void float58Test() throws IOException, InterruptedException {
374+
runTest("float58Test", "diff58_");
375+
}
376+
362377
@Test
363378
public void floatAndTables01Test() throws IOException, InterruptedException {
364379
runTest("floatAndTables01Test", "diffTables01_");
@@ -424,7 +439,7 @@ public void floatImage03Test() throws IOException, InterruptedException {
424439
runTest("floatImage03Test", "diffImages03_");
425440
}
426441

427-
@Test
442+
@Test@Ignore
428443
public void floatImage04Test() throws IOException, InterruptedException {
429444
// TODO word splitting logic working not entirely correctly
430445
runTest("floatImage04Test", "diffImages04_");
@@ -467,7 +482,7 @@ public void floatImage11Test() throws IOException, InterruptedException {
467482
runTest("floatImage11Test", "diffImages11_");
468483
}
469484

470-
@Test
485+
@Test@Ignore
471486
public void floatImage12Test() throws IOException, InterruptedException {
472487
// TODO we don't apply leading on floats, this somewhat noticeable when huge line-height in html is used
473488
runTest("floatImage12Test", "diffImages12_");

src/test/java/com/itextpdf/html2pdf/css/w3c/css21/positioning/PositionAbsolute008Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.html2pdf.css.w3c.W3CCssTest;
4646

47+
// TODO DEVSIX-1267
4748
public class PositionAbsolute008Test extends W3CCssTest {
4849
@Override
4950
protected String getHtmlFileName() {
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<style>
4+
.div1 {
5+
border: 1px solid;
6+
}
7+
.div2 {
8+
float: left;
9+
height: 300px;
10+
}
11+
</style>
12+
13+
<body>
14+
<p style="height: 900px">somep</p>
15+
<div class="div1">
16+
<div class="div2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit, nisl quis ullamcorper euismod, nulla dui luctus nulla, ut ullamcorper orci felis sit amet sem. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam sit amet augue a quam varius vestibulum. Sed faucibus, diam vel ornare semper, arcu tortor congue ligula, non auctor dolor ante in leo. Cras sit amet magna velit. In iaculis felis eget turpis viverra, vel tristique felis hendrerit. Etiam tincidunt, orci eget convallis mattis, sem est lacinia orci, vel euismod dolor lectus non tortor. Nunc auctor egestas scelerisque. Integer eget orci accumsan, sagittis est non, vestibulum arcu. Pellentesque consectetur risus a tortor imperdiet blandit.</div>
17+
<div style="clear:both"></div>
18+
</div>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)