* @private * @param {(LEFT|RIGHT|CENTER)} xAlign either LEFT, RIGHT or CENTER * @param {(TOP|BOTTOM|CENTER)} yAlign either TOP, BOTTOM or CENTER * @param {Number} dx * @param {Number} dy * @param {Number} dw * @param {Number} dh * @param {Number} sw * @param {Number} sh *
(xAlign, yAlign, dx, dy, dw, dh, sw, sh)
| 724 | */ |
| 725 | |
| 726 | function _imageContain(xAlign, yAlign, dx, dy, dw, dh, sw, sh) { |
| 727 | const r = Math.max(sw / dw, sh / dh); |
| 728 | const [adjusted_dw, adjusted_dh] = [sw / r, sh / r]; |
| 729 | let x = dx; |
| 730 | let y = dy; |
| 731 | |
| 732 | if (xAlign === constants.CENTER) { |
| 733 | x += (dw - adjusted_dw) / 2; |
| 734 | } else if (xAlign === constants.RIGHT) { |
| 735 | x += dw - adjusted_dw; |
| 736 | } |
| 737 | |
| 738 | if (yAlign === constants.CENTER) { |
| 739 | y += (dh - adjusted_dh) / 2; |
| 740 | } else if (yAlign === constants.BOTTOM) { |
| 741 | y += dh - adjusted_dh; |
| 742 | } |
| 743 | return { x, y, w: adjusted_dw, h: adjusted_dh }; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * @private |