Skip to content

Commit

Permalink
#373 Fix for a regression when image sizing with max-width/height.
Browse files Browse the repository at this point in the history
Was broken when intrinsic width or height were greater than max-width or max-height.

Thanks again @rototor.

Public domain images provided by pexabay at www.pexels.com

Co-Authored-By: Emmeran Seehuber <rototor@rototor.de>
  • Loading branch information
danfickle and rototor committed Aug 20, 2019
1 parent 661252f commit 69d767a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<style>
@page {
size: 500px 800px;
margin: 0;
}
body {
max-width: 500px;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<table style="width:100%; border: 3px solid black;">
<tr>
<td style="border: 1px solid green;">
<img src="../../demos/images/landscape-sydney.jpg"
style="max-height:100px; max-width:200px;"/>
<img src="../../demos/images/portrait-shuttle.jpg"
style="max-height:100px; max-width:200px;"/>
</td>
</tr>
<tr>
<td style="border: 1px solid green;">
<img src="../../demos/images/landscape-sydney.jpg"
style="max-height:100px; "/>
<img src="../../demos/images/portrait-shuttle.jpg"
style="max-height:100px; "/>
</td>
</tr>
<tr>
<td style="border: 1px solid green;">
<img src="../../demos/images/landscape-sydney.jpg"
style="max-width:200px;"/>
<img src="../../demos/images/portrait-shuttle.jpg"
style="max-width:200px;"/>
</td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 69d767a

Please sign in to comment.