Commit d7b89879 authored by Tassilo Horn's avatar Tassilo Horn

Fit contents to emacs window support for doc-view by Sho Nakatani.

2011-03-28  Sho Nakatani <lay.sakura <at> gmail.com>

	* doc-view.el (doc-view-fit-width-to-window)
	(doc-view-fit-height-to-window, doc-view-fit-page-to-window): New
	functions for fitting the shown image to the Emacs window size.
	(doc-view-mode-map): Add bindings for the new functions.
parent 6b8bc570
2011-04-08 Sho Nakatani <lay.sakura@gmail.com>
* doc-view.el (doc-view-fit-width-to-window)
(doc-view-fit-height-to-window, doc-view-fit-page-to-window): New
functions for fitting the shown image to the Emacs window size.
(doc-view-mode-map): Add bindings for the new functions.
2011-03-24 Juanma Barranquero <lekktu@gmail.com>
* vc-annotate.el (vc-annotate-show-log-revision-at-line):
......
......@@ -328,6 +328,10 @@ Can be `dvi', `pdf', or `ps'.")
;; Zoom in/out.
(define-key map "+" 'doc-view-enlarge)
(define-key map "-" 'doc-view-shrink)
;; Fit the image to the window
(define-key map "W" 'doc-view-fit-width-to-window)
(define-key map "H" 'doc-view-fit-height-to-window)
(define-key map "P" 'doc-view-fit-page-to-window)
;; Killing the buffer (and the process)
(define-key map (kbd "k") 'doc-view-kill-proc-and-buffer)
(define-key map (kbd "K") 'doc-view-kill-proc)
......@@ -664,6 +668,78 @@ OpenDocument format)."
(interactive (list doc-view-shrink-factor))
(doc-view-enlarge (/ 1.0 factor)))
(defun doc-view-fit-width-to-window ()
"Fit the image width to the window width."
(interactive)
(let ((win-width (- (nth 2 (window-inside-pixel-edges))
(nth 0 (window-inside-pixel-edges))))
(slice (doc-view-current-slice)))
(if (not slice)
(let ((img-width (car (image-display-size
(image-get-display-property) t))))
(doc-view-enlarge (/ (float win-width) (float img-width))))
;; If slice is set
(let* ((slice-width (nth 2 slice))
(scale-factor (/ (float win-width) (float slice-width)))
(new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice)))
(doc-view-enlarge scale-factor)
(setf (doc-view-current-slice) new-slice)
(doc-view-goto-page (doc-view-current-page))))))
(defun doc-view-fit-height-to-window ()
"Fit the image height to the window height."
(interactive)
(let ((win-height (- (nth 3 (window-inside-pixel-edges))
(nth 1 (window-inside-pixel-edges))))
(slice (doc-view-current-slice)))
(if (not slice)
(let ((img-height (cdr (image-display-size
(image-get-display-property) t))))
;; When users call 'doc-view-fit-height-to-window',
;; they might want to go to next page by typing SPC
;; ONLY once. So I used '(- win-height 1)' instead of
;; 'win-height'
(doc-view-enlarge (/ (float (- win-height 1)) (float img-height))))
;; If slice is set
(let* ((slice-height (nth 3 slice))
(scale-factor (/ (float (- win-height 1)) (float slice-height)))
(new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice)))
(doc-view-enlarge scale-factor)
(setf (doc-view-current-slice) new-slice)
(doc-view-goto-page (doc-view-current-page))))))
(defun doc-view-fit-page-to-window ()
"Fit the image to the window.
More specifically, this function enlarges image by:
min {(window-width / image-width), (window-height / image-height)} times."
(interactive)
(let ((win-width (- (nth 2 (window-inside-pixel-edges))
(nth 0 (window-inside-pixel-edges))))
(win-height (- (nth 3 (window-inside-pixel-edges))
(nth 1 (window-inside-pixel-edges))))
(slice (doc-view-current-slice)))
(if (not slice)
(let ((img-width (car (image-display-size
(image-get-display-property) t)))
(img-height (cdr (image-display-size
(image-get-display-property) t))))
(doc-view-enlarge (min (/ (float win-width) (float img-width))
(/ (float (- win-height 1)) (float img-height)))))
;; If slice is set
(let* ((slice-width (nth 2 slice))
(slice-height (nth 3 slice))
(scale-factor (min (/ (float win-width) (float slice-width))
(/ (float (- win-height 1)) (float slice-height))))
(new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice)))
(doc-view-enlarge scale-factor)
(setf (doc-view-current-slice) new-slice)
(doc-view-goto-page (doc-view-current-page))))))
(defun doc-view-reconvert-doc ()
"Reconvert the current document.
Should be invoked when the cached images aren't up-to-date."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment