Function: doc-view-fit-page-to-window
doc-view-fit-page-to-window is an interactive and byte-compiled
function defined in doc-view.el.gz.
Signature
(doc-view-fit-page-to-window)
Documentation
Fit the image to the window.
More specifically, this function enlarges image by:
min {(window-width / image-width), (window-height / image-height)} times.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/doc-view.el.gz
(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))))))