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: Wed, 30 Mar 2011 12:20:37 +0200 Message-ID: <87vcz0x62y.fsf@member.fsf.org> References: <878vvz8sml.fsf@fastmail.fm> <87k4fj6z8e.fsf@member.fsf.org> <87hbanw3ll.fsf@member.fsf.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1301481444 1722 80.91.229.12 (30 Mar 2011 10:37:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 30 Mar 2011 10:37:24 +0000 (UTC) Cc: 8364@debbugs.gnu.org To: sho nakatani Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 30 12:37:20 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 1Q4sm7-0004HS-Nu for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Mar 2011 12:37:20 +0200 Original-Received: from localhost ([127.0.0.1]:46385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4sm6-00073B-U5 for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Mar 2011 06:37:18 -0400 Original-Received: from [140.186.70.92] (port=35227 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4sm1-00072w-3u for bug-gnu-emacs@gnu.org; Wed, 30 Mar 2011 06:37:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4sly-0005YY-U0 for bug-gnu-emacs@gnu.org; Wed, 30 Mar 2011 06:37:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4sly-0005YT-Ob for bug-gnu-emacs@gnu.org; Wed, 30 Mar 2011 06:37:10 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q4sWL-0001xE-Rr; Wed, 30 Mar 2011 06:21:01 -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: Wed, 30 Mar 2011 10:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8364 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 8364-submit@debbugs.gnu.org id=B8364.13014804467488 (code B ref 8364); Wed, 30 Mar 2011 10:21:01 +0000 Original-Received: (at 8364) by debbugs.gnu.org; 30 Mar 2011 10:20:46 +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 1Q4sW6-0001wi-CK for submit@debbugs.gnu.org; Wed, 30 Mar 2011 06:20:46 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q4sW4-0001wW-PV for 8364@debbugs.gnu.org; Wed, 30 Mar 2011 06:20:45 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 056777817771; Wed, 30 Mar 2011 12:20:39 +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 25465-10; Wed, 30 Mar 2011 12:20:38 +0200 (CEST) X-CHKRCPT: Envelopesender noch tassilo@member.fsf.org Original-Received: from thinkpad (tsdh.uni-koblenz.de [141.26.67.142]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 5669B7817765; Wed, 30 Mar 2011 12:20:37 +0200 (CEST) In-Reply-To: (sho nakatani's message of "Wed, 30 Mar 2011 18:10:05 +0900") 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 30 Mar 2011 06:21:01 -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:45494 Archived-At: Hi Nakatani, thanks a lot for fiddeling with the issue. I've found the bug in your code. Here's a working function: --8<---------------cut here---------------start------------->8--- (defun doc-view-fit-slice-width-to-window () (interactive) (let ((slice (doc-view-current-slice))) (if (null slice) (doc-view-fit-width-to-window) ;; If slice is set (let* ((slice-width (nth 2 slice)) (win-width (- (nth 2 (window-inside-pixel-edges)) (nth 0 (window-inside-pixel-edges)))) (scale-factor (/ (float win-width) (float slice-width))) (new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice))) (set (make-local-variable 'doc-view-resolution) (ceiling (* scale-factor doc-view-resolution))) (doc-view-enlarge scale-factor) (setf (doc-view-current-slice) new-slice) (doc-view-goto-page (doc-view-current-page)))))) --8<---------------cut here---------------end--------------->8--- The problematic issue was that the `new-slice' calculated by the `mapcar' contained floating point numbers, which are not allowed for slice specs. I found out by using `edebug-defun' on `doc-view-insert-image'. One minor thing: I would prefer if your three original functions would respect the current slice if there is one, instead of adding a fourth function for that purpose. Could you please make it that way? Thanks again, you really did very impressive work! And I'm especially pleased that my assumption of calculating the right scales of both image and slices out of the plain images without resorting to external tools turned out being right. ;-) Bye, Tassilo