Skip to content

Commit

Permalink
Updated scaling logic for max-width and max-height images (#84)
Browse files Browse the repository at this point in the history
* Support max-width and max-height properties on img tags

* add support for max-width and max-height properties on img tags

* add support for max-width and max-height properties on img tags

* small tweak for for max-width and max-height properties to support edge cases

* Fix scaling algorithm

Make algo smarter if height and width are exceeding limits
  • Loading branch information
achuinard authored and danfickle committed Apr 11, 2017
1 parent 952d6be commit 6984f6e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ public ReplacedElement createReplacedElement(LayoutContext c, BlockBox box,
int intrinsicHeight = fsImage.getHeight();
int intrinsicWidth = fsImage.getWidth();

if (intrinsicHeight > maxHeight && intrinsicHeight >= intrinsicWidth && hasMaxHeight) {
fsImage.scale(-1, (int) maxHeight);
} else if (intrinsicWidth > maxWidth && hasMaxWidth) {
if (hasMaxWidth && hasMaxHeight) {
double rw = (double) intrinsicWidth / (double) maxWidth;
double rh = (double) intrinsicHeight / (double) maxHeight;

if (rw > rh) {
fsImage.scale((int) maxWidth, -1);
} else {
fsImage.scale(-1, (int) maxHeight);
}
} else if (hasMaxWidth && intrinsicWidth > maxWidth) {
fsImage.scale((int) maxWidth, -1);
} else if (hasMaxHeight && intrinsicHeight > maxHeight) {
fsImage.scale(-1, (int) maxHeight);
}
}
} else {
Expand Down

0 comments on commit 6984f6e

Please sign in to comment.