diff options
| author | Lars Magne Ingebrigtsen | 2013-06-23 21:24:27 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2013-06-23 21:24:27 +0200 |
| commit | f3f9606c7acb4b3248dbe6f9fe16db6d5e46c3af (patch) | |
| tree | c96757e2023bc5b30e6ba77f58478cefcabd9ac7 /lisp/net | |
| parent | e854cfc719363ccee23beaa7d0f79aab65d82a98 (diff) | |
| download | emacs-f3f9606c7acb4b3248dbe6f9fe16db6d5e46c3af.tar.gz emacs-f3f9606c7acb4b3248dbe6f9fe16db6d5e46c3af.zip | |
Implement :max-width/:max-height for (ImageMagic) images
* doc/lispref/display.texi (ImageMagick Images): Mention :max-width and
:max-height.
* lisp/net/shr.el (shr-rescale-image): Use the new
:max-width/:max-height functionality.
* src/image.c (compute_image_size): New function to implement
:max-width and :max-height.
(imagemagick_load_image): Use it.
Diffstat (limited to 'lisp/net')
| -rw-r--r-- | lisp/net/shr.el | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 868956d3e21..979743f9588 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -741,34 +741,18 @@ size, and full-buffer size." | |||
| 741 | (defun shr-rescale-image (data &optional force) | 741 | (defun shr-rescale-image (data &optional force) |
| 742 | "Rescale DATA, if too big, to fit the current buffer. | 742 | "Rescale DATA, if too big, to fit the current buffer. |
| 743 | If FORCE, rescale the image anyway." | 743 | If FORCE, rescale the image anyway." |
| 744 | (let ((image (create-image data nil t :ascent 100))) | 744 | (if (or (not (fboundp 'imagemagick-types)) |
| 745 | (if (or (not (fboundp 'imagemagick-types)) | 745 | (not (get-buffer-window (current-buffer)))) |
| 746 | (not (get-buffer-window (current-buffer)))) | 746 | (create-image data nil t :ascent 100) |
| 747 | image | 747 | (let ((edges (window-inside-pixel-edges |
| 748 | (let* ((size (image-size image t)) | 748 | (get-buffer-window (current-buffer))))) |
| 749 | (width (car size)) | 749 | (create-image |
| 750 | (height (cdr size)) | 750 | data 'imagemagick t |
| 751 | (edges (window-inside-pixel-edges | 751 | :ascent 100 |
| 752 | (get-buffer-window (current-buffer)))) | 752 | :max-width (truncate (* shr-max-image-proportion |
| 753 | (window-width (truncate (* shr-max-image-proportion | 753 | (- (nth 2 edges) (nth 0 edges)))) |
| 754 | (- (nth 2 edges) (nth 0 edges))))) | 754 | :max-height (truncate (* shr-max-image-proportion |
| 755 | (window-height (truncate (* shr-max-image-proportion | 755 | (- (nth 3 edges) (nth 1 edges)))))))) |
| 756 | (- (nth 3 edges) (nth 1 edges))))) | ||
| 757 | scaled-image) | ||
| 758 | (when (or force | ||
| 759 | (> height window-height)) | ||
| 760 | (setq image (or (create-image data 'imagemagick t | ||
| 761 | :height window-height | ||
| 762 | :ascent 100) | ||
| 763 | image)) | ||
| 764 | (setq size (image-size image t))) | ||
| 765 | (when (> (car size) window-width) | ||
| 766 | (setq image (or | ||
| 767 | (create-image data 'imagemagick t | ||
| 768 | :width window-width | ||
| 769 | :ascent 100) | ||
| 770 | image))) | ||
| 771 | image)))) | ||
| 772 | 756 | ||
| 773 | ;; url-cache-extract autoloads url-cache. | 757 | ;; url-cache-extract autoloads url-cache. |
| 774 | (declare-function url-cache-create-filename "url-cache" (url)) | 758 | (declare-function url-cache-create-filename "url-cache" (url)) |