aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorChong Yidong2011-04-09 16:28:01 -0400
committerChong Yidong2011-04-09 16:28:01 -0400
commita32d40405d31edd2ce4349b95277306554fb54a4 (patch)
tree7b94ea7a28ae8eff395c6953d94bc86f14593ff1 /lisp
parent8546720e6f25eb988e8215de6678798053031440 (diff)
downloademacs-a32d40405d31edd2ce4349b95277306554fb54a4.tar.gz
emacs-a32d40405d31edd2ce4349b95277306554fb54a4.zip
Cleanups to the ImageMagick code and docstrings.
* lisp/image-mode.el (image-toggle-display-image): Signal an error if not in Image mode. (image-transform-mode, image-transform-resize) (image-transform-set-rotation): Doc fix. (image-transform-set-resize): Deleted. (image-transform-set-scale, image-transform-fit-to-height) (image-transform-fit-to-width): Handle image-toggle-display-image and image-transform-resize directly. * src/image.c (Fimagemagick_types): Doc fix, and comment cleanup.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/image-mode.el113
2 files changed, 71 insertions, 53 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8d705cdaed6..402b078be7b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12011-04-09 Chong Yidong <cyd@stupidchicken.com>
2
3 * image-mode.el (image-toggle-display-image): Signal an error if
4 not in Image mode.
5 (image-transform-mode, image-transform-resize)
6 (image-transform-set-rotation): Doc fix.
7 (image-transform-set-resize): Deleted.
8 (image-transform-set-scale, image-transform-fit-to-height)
9 (image-transform-fit-to-width): Handle image-toggle-display-image
10 and image-transform-resize directly.
11
12011-04-08 Sho Nakatani <lay.sakura@gmail.com> 122011-04-08 Sho Nakatani <lay.sakura@gmail.com>
2 13
3 * doc-view.el (doc-view-fit-width-to-window) 14 * doc-view.el (doc-view-fit-width-to-window)
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 64dcf9076ae..96d874dbec6 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -469,6 +469,8 @@ Remove text properties that display the image."
469 "Show the image of the image file. 469 "Show the image of the image file.
470Turn the image data into a real image, but only if the whole file 470Turn the image data into a real image, but only if the whole file
471was inserted." 471was inserted."
472 (unless (derived-mode-p 'image-mode major-mode)
473 (error "The buffer is not in Image mode"))
472 (let* ((filename (buffer-file-name)) 474 (let* ((filename (buffer-file-name))
473 (data-p (not (and filename 475 (data-p (not (and filename
474 (file-readable-p filename) 476 (file-readable-p filename)
@@ -485,8 +487,7 @@ was inserted."
485 (type (image-type file-or-data nil data-p)) 487 (type (image-type file-or-data nil data-p))
486 (image0 (create-animated-image file-or-data type data-p)) 488 (image0 (create-animated-image file-or-data type data-p))
487 (image (append image0 489 (image (append image0
488 (image-transform-properties image0) 490 (image-transform-properties image0)))
489 ))
490 (props 491 (props
491 `(display ,image 492 `(display ,image
492 intangible ,image 493 intangible ,image
@@ -557,80 +558,86 @@ the image file and `image-mode' showing the image as an image."
557 558
558(defvar image-transform-minor-mode-map 559(defvar image-transform-minor-mode-map
559 (let ((map (make-sparse-keymap))) 560 (let ((map (make-sparse-keymap)))
560; (define-key map [(control ?+)] 'image-scale-in) 561 ;; (define-key map [(control ?+)] 'image-scale-in)
561; (define-key map [(control ?-)] 'image-scale-out) 562 ;; (define-key map [(control ?-)] 'image-scale-out)
562; (define-key map [(control ?=)] 'image-scale-none) 563 ;; (define-key map [(control ?=)] 'image-scale-none)
563;; (define-key map "c f h" 'image-scale-fit-height) 564 ;; (define-key map "c f h" 'image-scale-fit-height)
564;; (define-key map "c ]" 'image-rotate-right) 565 ;; (define-key map "c ]" 'image-rotate-right)
565 map) 566 map)
566 "Minor mode keymap for transforming the view of images Image mode.") 567 "Minor mode keymap `image-transform-mode'.")
567 568
568(define-minor-mode image-transform-mode 569(define-minor-mode image-transform-mode
569 "minor mode for scaleing and rotation" 570 "Minor mode for scaling and rotating images.
570 nil "image-transform" 571This minor mode has no effect unless Emacs is compiled with
571 image-transform-minor-mode-map) 572ImageMagick support."
572 573 nil "image-transform" image-transform-minor-mode-map)
573(defvar image-transform-resize nil 574
574 "The image resize operation. See the command 575(defvar image-transform-resize nil
575 `image-transform-set-scale' for more information." ) 576 "The image resize operation.
577Its value should be one of the following:
578 - nil, meaning no resizing.
579 - `fit-height', meaning to fit the image to the window height.
580 - `fit-width', meaning to fit the image to the window width.
581 - A number, which is a scale factor (the default size is 100).")
576 582
577(defvar image-transform-rotation 0.0) 583(defvar image-transform-rotation 0.0)
578 584
579
580(defun image-transform-properties (display) 585(defun image-transform-properties (display)
581 "Calculate the display properties for transformations; scaling 586 "Rescale and/or rotate the current image.
582and rotation. " 587The scale factor and rotation angle are given by the variables
583 (let* 588`image-transform-resize' and `image-transform-rotation'. This
584 ((size (image-size display t)) 589takes effect only if Emacs is compiled with ImageMagick support."
585 (height 590 (let* ((size (image-size display t))
586 (cond 591 (height
587 ((and (numberp image-transform-resize) (eq 100 image-transform-resize)) 592 (cond
588 nil) 593 ((numberp image-transform-resize)
589 ((numberp image-transform-resize) 594 (unless (= image-transform-resize 100)
590 (* image-transform-resize (cdr size))) 595 (* image-transform-resize (cdr size))))
591 ((eq image-transform-resize 'fit-height) 596 ((eq image-transform-resize 'fit-height)
592 (- (nth 3 (window-inside-pixel-edges)) (nth 1 (window-inside-pixel-edges)))) 597 (- (nth 3 (window-inside-pixel-edges))
593 (t nil))) 598 (nth 1 (window-inside-pixel-edges))))))
594 (width (if (eq image-transform-resize 'fit-width) 599 (width (if (eq image-transform-resize 'fit-width)
595 (- (nth 2 (window-inside-pixel-edges)) (nth 0 (window-inside-pixel-edges)))))) 600 (- (nth 2 (window-inside-pixel-edges))
596 601 (nth 0 (window-inside-pixel-edges))))))
602 ;;TODO fit-to-* should consider the rotation angle
597 `(,@(if height (list :height height)) 603 `(,@(if height (list :height height))
598 ,@(if width (list :width width)) 604 ,@(if width (list :width width))
599 ,@(if (not (equal 0.0 image-transform-rotation)) 605 ,@(if (not (equal 0.0 image-transform-rotation))
600 (list :rotation image-transform-rotation)) 606 (list :rotation image-transform-rotation)))))
601 ;;TODO fit-to-* should consider the rotation angle
602 )))
603 607
604(defun image-transform-set-scale (scale) 608(defun image-transform-set-scale (scale)
605 "SCALE sets the scaling for images. " 609 "Prompt for a number, and resize the current image by that amount.
606 (interactive "nscale:") 610This command has no effect unless Emacs is compiled with
607 (image-transform-set-resize (float scale))) 611ImageMagick support."
612 (interactive "nScale: ")
613 (setq image-transform-resize resize)
614 (image-toggle-display-image))
608 615
609(defun image-transform-fit-to-height () 616(defun image-transform-fit-to-height ()
610 "Fit image height to window height. " 617 "Fit the current image to the height of the current window.
618This command has no effect unless Emacs is compiled with
619ImageMagick support."
611 (interactive) 620 (interactive)
612 (image-transform-set-resize 'fit-height)) 621 (setq image-transform-resize 'fit-height)
622 (image-toggle-display-image))
613 623
614(defun image-transform-fit-to-width () 624(defun image-transform-fit-to-width ()
615 "Fit image width to window width. " 625 "Fit the current image to the width of the current window.
626This command has no effect unless Emacs is compiled with
627ImageMagick support."
616 (interactive) 628 (interactive)
617 (image-transform-set-resize 'fit-width)) 629 (setq image-transform-resize 'fit-width)
618 630 (image-toggle-display-image))
619(defun image-transform-set-resize (resize)
620 "Set the resize mode for images. The RESIZE value can be the
621symbol fit-height which fits the image to the window height. The
622symbol fit-width fits the image to the window width. A number
623indicates a scaling factor. nil indicates scale to 100%. "
624 (setq image-transform-resize resize)
625 (if (eq 'image-mode major-mode) (image-toggle-display-image)))
626 631
627(defun image-transform-set-rotation (rotation) 632(defun image-transform-set-rotation (rotation)
628 "Set the image ROTATION angle. " 633 "Prompt for an angle ROTATION, and rotate the image by that amount.
629 (interactive "nrotation:") 634ROTATION should be in degrees. This command has no effect unless
635Emacs is compiled with ImageMagick support."
636 (interactive "nRotation angle (in degrees): ")
630 ;;TODO 0 90 180 270 degrees are the only reasonable angles here 637 ;;TODO 0 90 180 270 degrees are the only reasonable angles here
631 ;;otherwise combining with rescaling will get very awkward 638 ;;otherwise combining with rescaling will get very awkward
632 (setq image-transform-rotation (float rotation)) 639 (setq image-transform-rotation (float rotation))
633 (if (eq major-mode 'image-mode) (image-toggle-display-image))) 640 (image-toggle-display-image))
634 641
635(provide 'image-mode) 642(provide 'image-mode)
636 643