diff options
| author | Lars Ingebrigtsen | 2016-02-10 13:47:58 +1100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2016-02-10 13:47:58 +1100 |
| commit | 7c1a75da5b57af136f3ed063e87fcd2420d86252 (patch) | |
| tree | 6090eec8be0d83885b6bfdb8e80555ffae264889 | |
| parent | 318f76a5792551b7ff19d80a00fade162a92c9d2 (diff) | |
| download | emacs-7c1a75da5b57af136f3ed063e87fcd2420d86252.tar.gz emacs-7c1a75da5b57af136f3ed063e87fcd2420d86252.zip | |
Allow interactively scaling past :max-width etc
* lisp/image.el (image--current-scaling)
(image--image-without-parameters): New functions.
(image--change-size): Use them to allow changing the size of a
image even if it has :width/:max-width (etc.) already set.
| -rw-r--r-- | lisp/image.el | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/lisp/image.el b/lisp/image.el index 1b07ee2491e..855dffad293 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -931,18 +931,18 @@ has no effect." | |||
| 931 | If N is 3, then the image size will be increased by 30%. The | 931 | If N is 3, then the image size will be increased by 30%. The |
| 932 | default is 20%." | 932 | default is 20%." |
| 933 | (interactive "P") | 933 | (interactive "P") |
| 934 | (image-change-size (if n | 934 | (image--change-size (if n |
| 935 | (1+ (/ n 10)) | 935 | (1+ (/ n 10)) |
| 936 | 1.2))) | 936 | 1.2))) |
| 937 | 937 | ||
| 938 | (defun image-decrease-size (n) | 938 | (defun image-decrease-size (n) |
| 939 | "Decrease the image size by a factor of N. | 939 | "Decrease the image size by a factor of N. |
| 940 | If N is 3, then the image size will be decreased by 30%. The | 940 | If N is 3, then the image size will be decreased by 30%. The |
| 941 | default is 20%." | 941 | default is 20%." |
| 942 | (interactive "P") | 942 | (interactive "P") |
| 943 | (image-change-size (if n | 943 | (image--change-size (if n |
| 944 | (- 1 (/ n 10)) | 944 | (- 1 (/ n 10)) |
| 945 | 0.8))) | 945 | 0.8))) |
| 946 | 946 | ||
| 947 | (defun image--get-image () | 947 | (defun image--get-image () |
| 948 | (let ((image (or (get-text-property (point) 'display) | 948 | (let ((image (or (get-text-property (point) 'display) |
| @@ -964,10 +964,30 @@ default is 20%." | |||
| 964 | (plist-put (cdr image) :type 'imagemagick) | 964 | (plist-put (cdr image) :type 'imagemagick) |
| 965 | image)) | 965 | image)) |
| 966 | 966 | ||
| 967 | (defun image-change-size (factor) | 967 | (defun image--change-size (factor) |
| 968 | (let ((image (image--get-imagemagick-and-warn))) | 968 | (let* ((image (image--get-imagemagick-and-warn)) |
| 969 | (plist-put (cdr image) :scale | 969 | (new-image (image--image-without-parameters image)) |
| 970 | (* (or (plist-get (cdr image) :scale) 1) factor)))) | 970 | (scale (image--current-scaling image new-image))) |
| 971 | (setcdr image (cdr new-image)) | ||
| 972 | (plist-put (cdr image) :scale (* scale factor)))) | ||
| 973 | |||
| 974 | (defun image--image-without-parameters (image) | ||
| 975 | (cons (pop image) | ||
| 976 | (let ((new nil)) | ||
| 977 | (while image | ||
| 978 | (let ((key (pop image)) | ||
| 979 | (val (pop image))) | ||
| 980 | (unless (memq key '(:scale :width :height :max-width :max-height)) | ||
| 981 | (setq new (nconc new (list key val)))))) | ||
| 982 | new))) | ||
| 983 | |||
| 984 | (defun image--current-scaling (image new-image) | ||
| 985 | ;; The image may be scaled due to many reasons (:scale, :max-width, | ||
| 986 | ;; etc), so find out what the current scaling is based on the | ||
| 987 | ;; original image size and the displayed size. | ||
| 988 | (let ((image-width (car (image-size new-image t))) | ||
| 989 | (display-width (car (image-size image t)))) | ||
| 990 | (/ (float display-width) image-width))) | ||
| 971 | 991 | ||
| 972 | (defun image-rotate () | 992 | (defun image-rotate () |
| 973 | "Rotate the image under point by 90 degrees clockwise." | 993 | "Rotate the image under point by 90 degrees clockwise." |