From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: E Sabof Newsgroups: gmane.emacs.bugs Subject: bug#13887: 24.3; doc-view will render blurry images when image-magick is available Date: Thu, 7 Mar 2013 15:17:54 +0000 Message-ID: References: <8762153qc8.fsf@thinkpad.tsdh.de> <8762143co6.fsf@thinkpad.tsdh.de> <877glkgvqj.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=20cf3074b16af4e40e04d757359f X-Trace: ger.gmane.org 1362669528 23024 80.91.229.3 (7 Mar 2013 15:18:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 Mar 2013 15:18:48 +0000 (UTC) Cc: 13887@debbugs.gnu.org To: Tassilo Horn Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 07 16:19:08 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UDcb4-00040B-Dn for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Mar 2013 16:19:06 +0100 Original-Received: from localhost ([::1]:46320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDcai-0008R5-J8 for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Mar 2013 10:18:44 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:39472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDcab-0008K6-BV for bug-gnu-emacs@gnu.org; Thu, 07 Mar 2013 10:18:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDcaV-0004IJ-0a for bug-gnu-emacs@gnu.org; Thu, 07 Mar 2013 10:18:37 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60820) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDcaU-0004IC-Sh for bug-gnu-emacs@gnu.org; Thu, 07 Mar 2013 10:18:30 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UDcb0-0003Id-IE for bug-gnu-emacs@gnu.org; Thu, 07 Mar 2013 10:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: E Sabof Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Mar 2013 15:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13887 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13887-submit@debbugs.gnu.org id=B13887.136266951612652 (code B ref 13887); Thu, 07 Mar 2013 15:19:02 +0000 Original-Received: (at 13887) by debbugs.gnu.org; 7 Mar 2013 15:18:36 +0000 Original-Received: from localhost ([127.0.0.1]:36696 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDcaZ-0003I0-QM for submit@debbugs.gnu.org; Thu, 07 Mar 2013 10:18:36 -0500 Original-Received: from mail-qc0-f180.google.com ([209.85.216.180]:49231) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UDcaW-0003Hm-Ab for 13887@debbugs.gnu.org; Thu, 07 Mar 2013 10:18:34 -0500 Original-Received: by mail-qc0-f180.google.com with SMTP id v28so183334qcm.11 for <13887@debbugs.gnu.org>; Thu, 07 Mar 2013 07:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=rXvTgf+9KEYsLptkHtKNsMBSMAVSyVEBYavY2I93ti4=; b=Pp5H7DiyvIGBrUEKrEmi050j49qwUMlvVF0YfqP9vcyrj3plnInJAJS/NC+RCA2Xzy v3k2oV+wiTAqkTNwHPrkMFFFEJ51u2PLDFIUWWecLCwXJbhqiq/kORs4e4zlk0wPwaXt oEqPX8sMhY4Nos56pWwqGfiY48ToCdQcMTvXiDlU+5IAG8Al/bZCtw5GtDBLDprWdm4f LhyQJtbbVczPwVl4sD8L3/vgloTHkiQiz6Sw3eOk0uzE4khnk+sa9Z9aIGrZumaSqK0v mOmpiUjF3v7YfQKmdx0yXGI+vplOQ2m2nAwD33jkCg/d2hwGR8YL+lM/X5mHRL3HAbf8 HdSg== X-Received: by 10.224.108.4 with SMTP id d4mr30235075qap.83.1362669474206; Thu, 07 Mar 2013 07:17:54 -0800 (PST) Original-Received: by 10.49.70.233 with HTTP; Thu, 7 Mar 2013 07:17:54 -0800 (PST) In-Reply-To: <877glkgvqj.fsf@thinkpad.tsdh.de> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:72199 Archived-At: --20cf3074b16af4e40e04d757359f Content-Type: text/plain; charset=ISO-8859-1 I had a look at it, there are some issues with zooming. It doesn't work when I open a document that is larger than the window, and sometimes in other cases. On Wed, Mar 6, 2013 at 7:43 PM, Tassilo Horn wrote: > E Sabof writes: > > > This function gives the native pixel dimensions of an image: > > > > (defun es-image-file-pixel-dimensions (file) > > (let* ((type (image-type file nil nil)) > > (spec (list 'image :type type :file file))) > > (image-size spec t))) > > > > When > > > > (> (getf (cdr (doc-view-current-image)) :width) > > (car (es-image-file-pixel-dimensions > > (getf (cdr (doc-view-current-image)) :file)))) > > > > there is quality loss. > > Hm, ok. Maybe I'll give it a whirl. > > > What I don't want to see is margins having a different width - for the > > same reasons you wouldn't put a photograph in a frame in the top left > > corner. > > Could you test-drive this patch. It implements horizontal centering of > the image. > > --8<---------------cut here---------------start------------->8--- > === modified file 'lisp/doc-view.el' > --- lisp/doc-view.el 2013-02-28 04:02:36 +0000 > +++ lisp/doc-view.el 2013-03-06 19:35:43 +0000 > @@ -1250,23 +1250,34 @@ > (when doc-view-pending-cache-flush > (clear-image-cache) > (setq doc-view-pending-cache-flush nil)) > - (let ((ol (doc-view-current-overlay)) > - (image (if (and file (file-readable-p file)) > - (if (not (and doc-view-scale-internally > - (fboundp 'imagemagick-types))) > - (apply 'create-image file doc-view--image-type nil > args) > - (unless (member :width args) > - (setq args `(,@args :width ,doc-view-image-width))) > - (apply 'create-image file 'imagemagick nil args)))) > - (slice (doc-view-current-slice))) > + (let* ((ol (doc-view-current-overlay)) > + (image (if (and file (file-readable-p file)) > + (if (not (and doc-view-scale-internally > + (fboundp 'imagemagick-types))) > + (apply 'create-image file doc-view--image-type nil > args) > + (unless (member :width args) > + (setq args `(,@args :width ,doc-view-image-width))) > + (apply 'create-image file 'imagemagick nil args)))) > + (slice (doc-view-current-slice)) > + (img-width (car (image-size image))) > + (displayed-img-width (if slice > + (* (/ (float (nth 2 slice)) > + (car (image-size image 'pixels))) > + img-width) > + img-width)) > + (window-width (window-width (selected-window)))) > (setf (doc-view-current-image) image) > (move-overlay ol (point-min) (point-max)) > + (when (> window-width displayed-img-width) > + (overlay-put ol 'before-string > + (propertize " " 'display > + `(space :align-to (+ center (-0.5 . > ,displayed-img-width)))))) > (overlay-put ol 'display > (cond > (image > (if slice > (list (cons 'slice slice) image) > - image)) > + image)) > ;; We're trying to display a page that doesn't exist. > (doc-view-current-converter-processes > ;; Maybe the page doesn't exist *yet*. > --8<---------------cut here---------------end--------------->8--- > > > Ideally I'd also center vertically (should the image be shorter than > > the window) > > I think vertical centering is a bit more tricky since there's nothing > like :align-to or vertically stretchable spaces... > > Bye, > Tassilo > --20cf3074b16af4e40e04d757359f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I had a look at it, there are some issues with zooming. It= doesn't work when I open a document that is larger than the window, an= d sometimes in other cases.


On Wed, Mar 6, 2013 at 7:43 PM, Tassilo Horn <tsdh@gnu.org> wrot= e:
E Sabof <esabof@gm= ail.com> writes:

> This function gives the native pixel dimensions of an image:
>
> (defun es-image-file-pixel-dimensions (file)
> =A0 (let* ((type (image-type file nil nil))
> =A0 =A0 =A0 =A0 =A0(spec (list 'image :type type :file file)))
> =A0 =A0 (image-size spec t)))
>
> When
>
> (> (getf (cdr (doc-view-current-image)) :width)
> =A0 =A0(car (es-image-file-pixel-dimensions
> =A0 =A0 =A0 =A0 =A0(getf (cdr (doc-view-current-image)) :file))))
>
> there is quality loss.

Hm, ok. =A0Maybe I'll give it a whirl.

> What I don't want to see is margins having a different width - for= the
> same reasons you wouldn't put a photograph in a frame in the top l= eft
> corner.

Could you test-drive this patch. =A0It implements horizontal centerin= g of
the image.

--8<---------------cut here---------------start------------->8---
=3D=3D=3D modified file 'lisp/doc-view.el'
--- lisp/doc-view.el =A0 =A02013-02-28 04:02:36 +0000
+++ lisp/doc-view.el =A0 =A02013-03-06 19:35:43 +0000
@@ -1250,23 +1250,34 @@
=A0 =A0(when doc-view-pending-cache-flush
=A0 =A0 =A0(clear-image-cache)
=A0 =A0 =A0(setq doc-view-pending-cache-flush nil))
- =A0(let ((ol (doc-view-current-overlay))
- =A0 =A0 =A0 =A0(image (if (and file (file-readable-p file))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if (not (and doc-view-scale-internall= y
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (fboundp = 'imagemagick-types)))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(apply 'create-image file = doc-view--image-type nil args)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(unless (member :width args)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(setq args `(,@args :width ,do= c-view-image-width)))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(apply 'create-image file '= ;imagemagick nil args))))
- =A0 =A0 =A0 =A0(slice (doc-view-current-slice)))
+ =A0(let* ((ol (doc-view-current-overlay))
+ =A0 =A0 =A0 =A0(image (if (and file (file-readable-p file))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (not (and doc-view-scale-internal= ly
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (fboundp = 'imagemagick-types)))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (apply 'create-image file= doc-view--image-type nil args)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unless (member :width args)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq args `(,@args :width ,d= oc-view-image-width)))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (apply 'create-image file = 9;imagemagick nil args))))
+ =A0 =A0 =A0 =A0(slice (doc-view-current-slice))
+ =A0 =A0 =A0 =A0(img-width (car (image-size image)))
+ =A0 =A0 =A0 =A0(displayed-img-width (if slice
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (* (/ (fl= oat (nth 2 slice))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 (car (image-size image 'pixels)))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0im= g-width)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 img-width)) + =A0 =A0 =A0 =A0(window-width (window-width (selected-window))))
=A0 =A0 =A0(setf (doc-view-current-image) image)
=A0 =A0 =A0(move-overlay ol (point-min) (point-max))
+ =A0 =A0(when (> window-width displayed-img-width)
+ =A0 =A0 =A0(overlay-put ol 'before-string
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(propertize " " 'display=
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0`(space :align= -to (+ center (-0.5 . ,displayed-img-width))))))
=A0 =A0 =A0(overlay-put ol 'display
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (cond
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(image
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if slice
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (list (cons 'slice slic= e) image)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 image))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;; We're trying to display a pag= e that doesn't exist.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(doc-view-current-converter-processe= s
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; Maybe the page doesn't exist= *yet*.
--8<---------------cut here---------------end--------------->8---

> =A0Ideally I'd also center vertically (should the image be shorter= than
> the window)

I think vertical centering is a bit more tricky since there's not= hing
like :align-to or vertically stretchable spaces...

Bye,
Tassilo

--20cf3074b16af4e40e04d757359f--