From a42b6b776ab37a365aaebb0684e217e2552eca9a Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Mon, 18 Nov 2019 15:50:14 +0100 Subject: [PATCH] fix issue #309, avoid adding AnonymousBlockBox on TableCells. Additionally build a TableCellBox instead of a BlockBox if it's a floating element --- .../com/openhtmltopdf/layout/BoxBuilder.java | 7 ++++++- .../issue-309-classcastexception-on-float-td.pdf | Bin 0 -> 1053 bytes ...issue-309-classcastexception-on-float-td.html | 1 + .../VisualRegressionTest.java | 12 +++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-309-classcastexception-on-float-td.pdf create mode 100644 openhtmltopdf-examples/src/main/resources/visualtest/html/issue-309-classcastexception-on-float-td.html 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 0000000000000000000000000000000000000000..1f34c6c0e5086b12b005b6c3c59a85ffa8af3431 GIT binary patch literal 1053 zcmah|O=uHA6b27gM=AyFQJ5Y=TeUkoo1NXP)JoIsLbYN^YFmjyx5*^kn(WlwjU);x zq6d}IQ$etZRzdI}Lj8fB#6wSdQUnpHhzBbk1VK=XIQv;zt|%sq;X4UBON6P5q%l5x8%w|8cI{+P2I_$kPp~& zCM%^`p|gfsT=j2dVF>^oa56qjsiKl&0QIq=8$eu>C{7v^0Xj%CjvZ$un35$KijNpX zQgi}iDwbk8;cP>;M>*Yko1EJX_|}I+Tn12r`mE@sxei(g{MA7ORPG$4ZZ4RFSd9W? zIr)HhimW^r#iVJLp`ubh;93=$L214)vvDezB`dAJ5Le zd2!_3)+Z08XtNmWdTo^fi$*JrSzHdN*L5!T)c_1*b;n{~IbQddU;!vuoCrd@2@nGm zw|yG&qhY5&{jLNn*e*c*E|<)4a}bR>Zm;V*6`*F`C68u-3=JSx7t{!e5}0kSVwg`z zEa+A-tQifMtn-5F;uM98P=`fTZjm~SkVZaYG{$KPe>Iidz_Xn^^}_d;V2nFC6c7!# zSq8=H;q@kr^lGMRDVDCsv8fpvCYGW0!2gGEgD0I+luH$Q(Ds5* OJ6%ygB+`G#0)GIQw=fw1 literal 0 HcmV?d00001 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)