diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java index 9ca07a3df..b5e33a1fb 100755 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java @@ -782,9 +782,9 @@ private void sizeReplacedElement(LayoutContext c, ReplacedElement re) { if (rw > rh) { nw = cssWidth; - nh = intrinsicHeight; + nh = (int) (intrinsicHeight / rw); } else { - nw = intrinsicWidth; + nw = (int) (intrinsicWidth / rh); nh = cssHeight; } } else { diff --git a/openhtmltopdf-examples/src/main/resources/demos/images/landscape-sydney.jpg b/openhtmltopdf-examples/src/main/resources/demos/images/landscape-sydney.jpg new file mode 100644 index 000000000..10b76c04f Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/demos/images/landscape-sydney.jpg differ diff --git a/openhtmltopdf-examples/src/main/resources/demos/images/portrait-shuttle.jpg b/openhtmltopdf-examples/src/main/resources/demos/images/portrait-shuttle.jpg new file mode 100644 index 000000000..7199a6898 Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/demos/images/portrait-shuttle.jpg differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-img-in-table-cell-3.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-img-in-table-cell-3.pdf new file mode 100644 index 000000000..466035805 Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-img-in-table-cell-3.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/replaced-img-in-table-cell-3.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/replaced-img-in-table-cell-3.html new file mode 100644 index 000000000..3c2a8089e --- /dev/null +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/replaced-img-in-table-cell-3.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + 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 121f2531d..c8f80f0d6 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java @@ -686,6 +686,15 @@ public void testReplacedImgInTableCell2() throws IOException { assertTrue(vt.runTest("replaced-img-in-table-cell-2")); } + /** + * Tests that large images with smaller max-width and/or max-height are correctly resized. + * PR number 373. + */ + @Test + public void testReplacedImgInTableCell3() throws IOException { + assertTrue(vt.runTest("replaced-img-in-table-cell-3")); + } + /** * Tests that a fixed position element correctly resizes to the sum of its child boxes * using border-box sizing.