Skip to content

Commit

Permalink
Merge pull request #415 from syjer/309-float-td-classcast-exception
Browse files Browse the repository at this point in the history
fixes issue #309, avoid adding AnonymousBlockBox on TableCells. Additionally build a TableCellBox instead of a BlockBox if it's a floating element
  • Loading branch information
danfickle authored Dec 9, 2019
2 parents 2afa909 + a42b6b7 commit 73a26c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><table><tr><td>a</td><td style="float:left">x</td></tr></table></body></html>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 73a26c9

Please sign in to comment.