diff options
| author | Basil L. Contovounesios | 2019-07-16 22:51:27 +0100 |
|---|---|---|
| committer | Basil L. Contovounesios | 2019-07-20 16:00:31 +0100 |
| commit | b728620a756db78b8cb0a41afa72db6209102cdf (patch) | |
| tree | 30b5a0597791fe9a47cae18dda203d737b453bfa | |
| parent | 6b882ea3532fffe31e2f27bfec265129a5e80348 (diff) | |
| download | emacs-b728620a756db78b8cb0a41afa72db6209102cdf.tar.gz emacs-b728620a756db78b8cb0a41afa72db6209102cdf.zip | |
Allow counter-clockwise rotations in image-rotate
* lisp/image.el (image-rotate): Extend with an optional argument
specifying the rotation in degrees (bug#35421).
* doc/lispref/display.texi (Showing Images):
* etc/NEWS: Document the change.
* test/lisp/image-tests.el (image-rotate): New test.
| -rw-r--r-- | doc/lispref/display.texi | 3 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/image.el | 22 | ||||
| -rw-r--r-- | test/lisp/image-tests.el | 23 |
4 files changed, 43 insertions, 10 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index a38569f7263..4b10788862e 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -5992,7 +5992,8 @@ Decrease the image size (@code{image-increase-size}). A prefix value | |||
| 5992 | of @samp{4} means to decrease the size by 40%. The default is 20%. | 5992 | of @samp{4} means to decrease the size by 40%. The default is 20%. |
| 5993 | 5993 | ||
| 5994 | @item r | 5994 | @item r |
| 5995 | Rotate the image by 90 degrees (@code{image-rotate}). | 5995 | Rotate the image by 90 degrees clockwise (@code{image-rotate}). |
| 5996 | A prefix means to rotate by 90 degrees counter-clockwise instead. | ||
| 5996 | 5997 | ||
| 5997 | @item o | 5998 | @item o |
| 5998 | Save the image to a file (@code{image-save}). | 5999 | Save the image to a file (@code{image-save}). |
| @@ -2257,6 +2257,11 @@ The image parameters 'image-transform-rotation', | |||
| 2257 | buffer-local, so each buffer could have its own values for these | 2257 | buffer-local, so each buffer could have its own values for these |
| 2258 | parameters. | 2258 | parameters. |
| 2259 | 2259 | ||
| 2260 | +++ | ||
| 2261 | *** The command 'image-rotate' now accepts a prefix argument. | ||
| 2262 | With a prefix argument, 'image-rotate' now rotates the image at point | ||
| 2263 | 90 degrees counter-clockwise, instead of the default clockwise. | ||
| 2264 | |||
| 2260 | ** Modules | 2265 | ** Modules |
| 2261 | 2266 | ||
| 2262 | *** The function 'load' now behaves correctly when loading modules. | 2267 | *** The function 'load' now behaves correctly when loading modules. |
diff --git a/lisp/image.el b/lisp/image.el index b58b1dc9542..c3e28655c38 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -1028,16 +1028,20 @@ default is 20%." | |||
| 1028 | (display-width (car (image-size image t)))) | 1028 | (display-width (car (image-size image t)))) |
| 1029 | (/ (float display-width) image-width))) | 1029 | (/ (float display-width) image-width))) |
| 1030 | 1030 | ||
| 1031 | (defun image-rotate () | 1031 | (defun image-rotate (&optional angle) |
| 1032 | "Rotate the image under point by 90 degrees clockwise." | 1032 | "Rotate the image under point by ANGLE degrees clockwise. |
| 1033 | (interactive) | 1033 | If nil, ANGLE defaults to 90. Interactively, rotate the image 90 |
| 1034 | degrees clockwise with no prefix argument, and counter-clockwise | ||
| 1035 | with a prefix argument. Note that most image types support | ||
| 1036 | rotations by only multiples of 90 degrees." | ||
| 1037 | (interactive (and current-prefix-arg '(-90))) | ||
| 1034 | (let ((image (image--get-imagemagick-and-warn))) | 1038 | (let ((image (image--get-imagemagick-and-warn))) |
| 1035 | (plist-put (cdr image) :rotation | 1039 | (setf (image-property image :rotation) |
| 1036 | (float (mod (+ (or (plist-get (cdr image) :rotation) 0) 90) | 1040 | (float (mod (+ (or (image-property image :rotation) 0) |
| 1037 | ;; We don't want to exceed 360 degrees | 1041 | (or angle 90)) |
| 1038 | ;; rotation, because it's not seen as valid | 1042 | ;; We don't want to exceed 360 degrees rotation, |
| 1039 | ;; in exif data. | 1043 | ;; because it's not seen as valid in Exif data. |
| 1040 | 360))))) | 1044 | 360))))) |
| 1041 | 1045 | ||
| 1042 | (defun image-save () | 1046 | (defun image-save () |
| 1043 | "Save the image under point." | 1047 | "Save the image under point." |
diff --git a/test/lisp/image-tests.el b/test/lisp/image-tests.el index 5a5b8ea1f71..01c81e3022f 100644 --- a/test/lisp/image-tests.el +++ b/test/lisp/image-tests.el | |||
| @@ -21,6 +21,8 @@ | |||
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'image) | 23 | (require 'image) |
| 24 | (eval-when-compile | ||
| 25 | (require 'cl-lib)) | ||
| 24 | 26 | ||
| 25 | (defconst image-tests--emacs-images-directory | 27 | (defconst image-tests--emacs-images-directory |
| 26 | (expand-file-name "../etc/images" (getenv "EMACS_TEST_DIRECTORY")) | 28 | (expand-file-name "../etc/images" (getenv "EMACS_TEST_DIRECTORY")) |
| @@ -53,4 +55,25 @@ | |||
| 53 | (expand-file-name "splash.svg" | 55 | (expand-file-name "splash.svg" |
| 54 | image-tests--emacs-images-directory))))) | 56 | image-tests--emacs-images-directory))))) |
| 55 | 57 | ||
| 58 | (ert-deftest image-rotate () | ||
| 59 | "Test `image-rotate'." | ||
| 60 | (cl-letf* ((image (list 'image)) | ||
| 61 | ((symbol-function 'image--get-imagemagick-and-warn) | ||
| 62 | (lambda () image))) | ||
| 63 | (let ((current-prefix-arg '(4))) | ||
| 64 | (call-interactively #'image-rotate)) | ||
| 65 | (should (equal image '(image :rotation 270.0))) | ||
| 66 | (call-interactively #'image-rotate) | ||
| 67 | (should (equal image '(image :rotation 0.0))) | ||
| 68 | (image-rotate) | ||
| 69 | (should (equal image '(image :rotation 90.0))) | ||
| 70 | (image-rotate 0) | ||
| 71 | (should (equal image '(image :rotation 90.0))) | ||
| 72 | (image-rotate 1) | ||
| 73 | (should (equal image '(image :rotation 91.0))) | ||
| 74 | (image-rotate 1234.5) | ||
| 75 | (should (equal image '(image :rotation 245.5))) | ||
| 76 | (image-rotate -154.5) | ||
| 77 | (should (equal image '(image :rotation 91.0))))) | ||
| 78 | |||
| 56 | ;;; image-tests.el ends here | 79 | ;;; image-tests.el ends here |