emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r112043: * doc-view.el (doc-view-inse


From: Tassilo Horn
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112043: * doc-view.el (doc-view-insert-image): Don't modify overlay
Date: Thu, 14 Mar 2013 16:24:04 +0100
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 112043
committer: Tassilo Horn <address@hidden>
branch nick: trunk
timestamp: Thu 2013-03-14 16:24:04 +0100
message:
  * doc-view.el (doc-view-insert-image): Don't modify overlay
  associated with pseudo winprops entry, and implement horizontal
  centering of image in case it's smaller than the window
  (bug#13887).
modified:
  lisp/ChangeLog
  lisp/doc-view.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-03-13 18:54:05 +0000
+++ b/lisp/ChangeLog    2013-03-14 15:24:04 +0000
@@ -1,3 +1,10 @@
+2013-03-14  Tassilo Horn  <address@hidden>
+
+       * doc-view.el (doc-view-insert-image): Don't modify overlay
+       associated with pseudo winprops entry, and implement horizontal
+       centering of image in case it's smaller than the window
+       (bug#13887).
+
 2013-03-13  Karl Fogel  <address@hidden>
 
        * saveplace.el (save-place-alist-to-file): Don't sort

=== modified file 'lisp/doc-view.el'
--- a/lisp/doc-view.el  2013-02-28 04:02:36 +0000
+++ b/lisp/doc-view.el  2013-03-14 15:24:04 +0000
@@ -1250,44 +1250,60 @@
   (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)))
-    (setf (doc-view-current-image) image)
-    (move-overlay ol (point-min) (point-max))
-    (overlay-put ol 'display
-                 (cond
-                  (image
-                   (if slice
-                       (list (cons 'slice slice) 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*.
-                   "Cannot display this page (yet)!")
-                  (t
-                   ;; Typically happens if the conversion process somehow
-                   ;; failed.  Better not signal an error here because it
-                   ;; could prevent a subsequent reconversion from fixing
-                   ;; the problem.
-                   (concat "Cannot display this page!\n"
-                           "Maybe because of a conversion failure!"))))
-    (let ((win (overlay-get ol 'window)))
-      (if (stringp (overlay-get ol 'display))
-          (progn            ;Make sure the text is not scrolled out of view.
-            (set-window-hscroll win 0)
-            (set-window-vscroll win 0))
-        (let ((hscroll (image-mode-window-get 'hscroll win))
-              (vscroll (image-mode-window-get 'vscroll win)))
-          ;; Reset scroll settings, in case they were changed.
-          (if hscroll (set-window-hscroll win hscroll))
-          (if vscroll (set-window-vscroll win vscroll)))))))
+  (let ((ol (doc-view-current-overlay)))
+    ;; ol might be deleted (see `doc-view-new-window-function'), in
+    ;; which case we don't want to modify it.
+    (when (overlay-buffer ol)
+      (let* ((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 (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))
+       ;; In case the window is wider than the image, center the image
+       ;; horizontally.
+       (overlay-put ol 'before-string
+                    (when (and image (> window-width displayed-img-width))
+                      (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))
+                     ;; We're trying to display a page that doesn't exist.
+                     (doc-view-current-converter-processes
+                      ;; Maybe the page doesn't exist *yet*.
+                      "Cannot display this page (yet)!")
+                     (t
+                      ;; Typically happens if the conversion process somehow
+                      ;; failed.  Better not signal an error here because it
+                      ;; could prevent a subsequent reconversion from fixing
+                      ;; the problem.
+                      (concat "Cannot display this page!\n"
+                              "Maybe because of a conversion failure!"))))
+       (let ((win (overlay-get ol 'window)))
+         (if (stringp (overlay-get ol 'display))
+             (progn            ;Make sure the text is not scrolled out of view.
+               (set-window-hscroll win 0)
+               (set-window-vscroll win 0))
+           (let ((hscroll (image-mode-window-get 'hscroll win))
+                 (vscroll (image-mode-window-get 'vscroll win)))
+             ;; Reset scroll settings, in case they were changed.
+             (if hscroll (set-window-hscroll win hscroll))
+             (if vscroll (set-window-vscroll win vscroll)))))))))
 
 (defun doc-view-sort (a b)
   "Return non-nil if A should be sorted before B.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]