diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java index b9681cc0d..f76778f93 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java @@ -993,6 +993,9 @@ private static BlockBox createBlockBox( BlockBox result; if (style.isTable() || style.isInlineTable()) { result = new TableBox(); + } else if (style.isTableCell()) { + info.setContainsTableContent(true); + result = new TableCellBox(); } else { result = new BlockBox(); } @@ -1357,7 +1360,9 @@ private static void insertAnonymousBlocks( for (Styleable child : children) { if (child.getStyle().isLayedOutInInlineContext() && - ! (layoutRunningBlocks && child.getStyle().isRunning())) { + ! (layoutRunningBlocks && child.getStyle().isRunning()) && + !child.getStyle().isTableCell() //see issue https://github.com/danfickle/openhtmltopdf/issues/309 + ) { inline.add(child); if (child.getStyle().isInline()) { diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-309-classcastexception-on-float-td.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-309-classcastexception-on-float-td.pdf new file mode 100644 index 000000000..1f34c6c0e Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-309-classcastexception-on-float-td.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-309-classcastexception-on-float-td.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-309-classcastexception-on-float-td.html new file mode 100644 index 000000000..08d6086cb --- /dev/null +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-309-classcastexception-on-float-td.html @@ -0,0 +1 @@ +
ax
\ No newline at end of file diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java index dd4563d4e..1978f161e 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java @@ -911,7 +911,7 @@ public void testListCounterAfterPageBreak() throws IOException { public void testMissingHtml5BlockElements() throws IOException { assertTrue(vt.runTest("html5-missing-block-elements")); } - + /** * Tests that a paginated table doesn't add header and footer with no rows * on a page. @@ -943,6 +943,16 @@ public void testIssue420JustifyTextWhiteSpacePre() throws IOException { assertTrue(vt.runTest("issue-420-justify-text-white-space-pre")); } + /** + * Don't launch a ClassCastException if a td in a table is floated. + * + * See issue: https://github.com/danfickle/openhtmltopdf/issues/309 + */ + @Test + public void testIssue309ClassCastExceptionOnFloatTd() throws IOException { + assertTrue(vt.runTest("issue-309-classcastexception-on-float-td")); + } + // TODO: // + Elements that appear just on generated overflow pages. // + content property (page counters, etc)