Subject: Re: bug#13887: 24.3; doc-view will render blurry images when image-magick is available

From: Tassilo Horn <[email-masked]>
Date: Thu, 07 Mar 2013 16:55:52 +0100

E Sabof <[email-masked]> writes:

> 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,

Does that mean that you'd like to set the hscoll when the window is
smaller than the images so that the center of the image is displayed at
the center of the window?

Hm, this could at least be done once when initially opening some
document.  When switching pages, the current hscroll is preserved and I
consider that a good thing.  It shouldn't re-center then.

> and sometimes in other cases.

I know there were some issues/errors when the image of a page isn't
there already.  That should be fixed by this version of the patch.

--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-07 08:14:09 +0000
@@ -1250,7 +1250,7 @@
   (when doc-view-pending-cache-flush
     (clear-image-cache)
     (setq doc-view-pending-cache-flush nil))
-  (let ((ol (doc-view-current-overlay))
+  (let* ((ol (doc-view-current-overlay))
         (image (if (and file (file-readable-p file))
                   (if (not (and doc-view-scale-internally
                                  (fboundp 'imagemagick-types)))
@@ -1258,9 +1258,20 @@
                     (unless (member :width args)
                       (setq args `(,@args :width ,doc-view-image-width)))
                     (apply 'create-image file 'imagemagick nil args))))
-        (slice (doc-view-current-slice)))
+        (slice (doc-view-current-slice))
+        (img-width (and image (car (image-size image))))
+        (displayed-img-width (if (and image 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 (and image (> 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
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo