unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el
@ 2011-03-28 10:08 Tassilo Horn
       [not found] ` <handler.8364.B.130130692430672.ack@debbugs.gnu.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Tassilo Horn @ 2011-03-28 10:08 UTC (permalink / raw)
  To: 8364; +Cc: Sho Nakatani

This patch created by Sho Nakatani <lay.sakura@gmail.com> (in Cc) adds a
feature to fit the current doc to the window height/width.  I already
tested it, and it works as expected.  The emacs coding standards are
also met.

I have instructed Nakatani in doing the copyright assignment, and he is
willing to do so.  When the assignment is confirmed, I'll apply and push
his changes.

Here's the patch:

--8<---------------cut here---------------start------------->8---
=== modified file 'lisp/doc-view.el'
--- old/lisp/doc-view.el	2011-01-25 04:08:28 +0000
+++ new/lisp/doc-view.el	2011-03-28 08:59:52 +0000
@@ -327,6 +327,10 @@
     ;; 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)
@@ -665,6 +669,45 @@
   (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 ((img-width (car (image-display-size
+                         (image-get-display-property))))
+        (win-width (- (nth 2 (window-inside-edges))
+                      (nth 0 (window-inside-edges)))))
+    (doc-view-enlarge (/ win-width img-width))))
+
+(defun doc-view-fit-height-to-window ()
+  "Fit the image height to the window width."
+  (interactive)
+  (let ((img-height (cdr (image-display-size
+                          (image-get-display-property))))
+        (win-height (- (nth 3 (window-inside-edges))
+                       (nth 1 (window-inside-edges)))))
+    ;; 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 (/ (- win-height 1) img-height))))
+
+(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 ((img-width (car (image-display-size
+                         (image-get-display-property))))
+        (win-width (- (nth 2 (window-inside-edges))
+                      (nth 0 (window-inside-edges))))
+        (img-height (cdr (image-display-size
+                          (image-get-display-property))))
+        (win-height (- (nth 3 (window-inside-edges))
+                       (nth 1 (window-inside-edges)))))
+    (doc-view-enlarge (min (/ win-width img-width)
+                           (/ (- win-height 1) img-height)))))
+
 (defun doc-view-reconvert-doc ()
   "Reconvert the current document.
 Should be invoked when the cached images aren't up-to-date."

--8<---------------cut here---------------end--------------->8---





^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2011-04-08 20:12 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-28 10:08 bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el Tassilo Horn
     [not found] ` <handler.8364.B.130130692430672.ack@debbugs.gnu.org>
2011-03-28 10:38   ` bug#8364: Acknowledgement (24.0.9999; PATCH: Fit to width/height/page for doc-view.el) Tassilo Horn
2011-03-28 14:36 ` bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el Stefan Monnier
2011-03-28 14:56   ` sho nakatani
2011-03-28 15:17     ` Stefan Monnier
2011-03-29  9:32       ` joakim
2011-03-28 15:28     ` Tassilo Horn
2011-03-28 15:58       ` sho nakatani
2011-03-28 17:35         ` Tassilo Horn
2011-03-30  9:10           ` sho nakatani
2011-03-30 10:20             ` Tassilo Horn
     [not found]               ` <AANLkTinuF6KanSo5XuTQOm+G-+qHzS8QM9zMy3S73-_g@mail.gmail.com>
2011-03-30 13:18                 ` Tassilo Horn
2011-03-30 14:35                   ` sho nakatani
2011-03-30 15:17                     ` Tassilo Horn
2011-03-30 15:49                       ` sho nakatani
2011-03-30 17:07                         ` Tassilo Horn
2011-03-30 17:13                           ` sho nakatani
2011-03-30 14:42             ` Stefan Monnier
2011-03-30 15:08               ` Tassilo Horn
2011-03-30 21:07                 ` Stefan Monnier
2011-03-31  6:32                   ` Tassilo Horn
2011-03-31  6:57                     ` sho nakatani
2011-03-31  7:47                       ` Tassilo Horn
2011-04-08 16:18 ` Chong Yidong
2011-04-08 20:12   ` Tassilo Horn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).