From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.bugs Subject: bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el Date: Mon, 28 Mar 2011 12:08:18 +0200 Message-ID: <878vvz8sml.fsf@fastmail.fm> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1301308650 29468 80.91.229.12 (28 Mar 2011 10:37:30 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 Mar 2011 10:37:30 +0000 (UTC) Cc: Sho Nakatani To: 8364@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 28 12:37:26 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q49p7-0004rY-BF for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Mar 2011 12:37:25 +0200 Original-Received: from localhost ([127.0.0.1]:34312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q49p5-0003ww-L8 for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Mar 2011 06:37:23 -0400 Original-Received: from [140.186.70.92] (port=51082 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q49oy-0003vm-UH for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2011 06:37:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q49ox-0000as-2V for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2011 06:37:16 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51625) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q49ow-0000an-Vf for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2011 06:37:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q49Ne-0007zJ-O8; Mon, 28 Mar 2011 06:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tassilo Horn Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Mar 2011 10:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8364 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130130692430672 (code B ref -1); Mon, 28 Mar 2011 10:09:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Mar 2011 10:08:44 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q49NL-0007yf-1V for submit@debbugs.gnu.org; Mon, 28 Mar 2011 06:08:43 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q49NJ-0007yU-5j for submit@debbugs.gnu.org; Mon, 28 Mar 2011 06:08:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q49ND-0003ao-1u for submit@debbugs.gnu.org; Mon, 28 Mar 2011 06:08:36 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:40936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q49NC-0003af-ME for submit@debbugs.gnu.org; Mon, 28 Mar 2011 06:08:35 -0400 Original-Received: from [140.186.70.92] (port=51456 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q49N4-0007di-RW for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2011 06:08:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q49Mz-0003aR-Ue for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2011 06:08:23 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:9293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q49Mz-0003aN-Mp for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2011 06:08:21 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 21A267816FAA; Mon, 28 Mar 2011 12:08:19 +0200 (CEST) Original-Received: from deliver.uni-koblenz.de ([127.0.0.1]) by localhost (deliver.uni-koblenz.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 16817-08; Mon, 28 Mar 2011 12:08:18 +0200 (CEST) X-CHKRCPT: Envelopesender noch thorn@fastmail.fm Original-Received: from thinkpad (tsdh.uni-koblenz.de [141.26.67.142]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 2C4247816F95; Mon, 28 Mar 2011 12:08:18 +0200 (CEST) User-Agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.9999 (gnu/linux) X-Virus-Scanned: amavisd-new at uni-koblenz.de X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 28 Mar 2011 06:09:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45413 Archived-At: This patch created by Sho Nakatani (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---