diff options
Diffstat (limited to 'lisp/doc-view.el')
| -rw-r--r-- | lisp/doc-view.el | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index de342f1519e..77c06a8eaf9 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -435,6 +435,9 @@ Typically \"page-%s.png\".") | |||
| 435 | (define-key map (kbd "c m") 'doc-view-set-slice-using-mouse) | 435 | (define-key map (kbd "c m") 'doc-view-set-slice-using-mouse) |
| 436 | (define-key map (kbd "c b") 'doc-view-set-slice-from-bounding-box) | 436 | (define-key map (kbd "c b") 'doc-view-set-slice-from-bounding-box) |
| 437 | (define-key map (kbd "c r") 'doc-view-reset-slice) | 437 | (define-key map (kbd "c r") 'doc-view-reset-slice) |
| 438 | ;; Centering the image | ||
| 439 | (define-key map (kbd "c h") 'doc-view-center-page-horizontally) | ||
| 440 | (define-key map (kbd "c v") 'doc-view-center-page-vertically) | ||
| 438 | ;; Searching | 441 | ;; Searching |
| 439 | (define-key map (kbd "C-s") 'doc-view-search) | 442 | (define-key map (kbd "C-s") 'doc-view-search) |
| 440 | (define-key map (kbd "<find>") 'doc-view-search) | 443 | (define-key map (kbd "<find>") 'doc-view-search) |
| @@ -740,8 +743,7 @@ It's a subdirectory of `doc-view-cache-directory'." | |||
| 740 | Document types are symbols like `dvi', `ps', `pdf', or `odf' (any | 743 | Document types are symbols like `dvi', `ps', `pdf', or `odf' (any |
| 741 | OpenDocument format)." | 744 | OpenDocument format)." |
| 742 | (and (display-graphic-p) | 745 | (and (display-graphic-p) |
| 743 | (or (image-type-available-p 'imagemagick) | 746 | (image-type-available-p 'png) |
| 744 | (image-type-available-p 'png)) | ||
| 745 | (cond | 747 | (cond |
| 746 | ((eq type 'dvi) | 748 | ((eq type 'dvi) |
| 747 | (and (doc-view-mode-p 'pdf) | 749 | (and (doc-view-mode-p 'pdf) |
| @@ -769,10 +771,7 @@ OpenDocument format)." | |||
| 769 | (defun doc-view-enlarge (factor) | 771 | (defun doc-view-enlarge (factor) |
| 770 | "Enlarge the document by FACTOR." | 772 | "Enlarge the document by FACTOR." |
| 771 | (interactive (list doc-view-shrink-factor)) | 773 | (interactive (list doc-view-shrink-factor)) |
| 772 | (if (and doc-view-scale-internally | 774 | (if doc-view-scale-internally |
| 773 | (eq (plist-get (cdr (doc-view-current-image)) :type) | ||
| 774 | 'imagemagick)) | ||
| 775 | ;; ImageMagick supports on-the-fly-rescaling. | ||
| 776 | (let ((new (ceiling (* factor doc-view-image-width)))) | 775 | (let ((new (ceiling (* factor doc-view-image-width)))) |
| 777 | (unless (equal new doc-view-image-width) | 776 | (unless (equal new doc-view-image-width) |
| 778 | (setq-local doc-view-image-width new) | 777 | (setq-local doc-view-image-width new) |
| @@ -792,9 +791,7 @@ OpenDocument format)." | |||
| 792 | (defun doc-view-scale-reset () | 791 | (defun doc-view-scale-reset () |
| 793 | "Reset the document size/zoom level to the initial one." | 792 | "Reset the document size/zoom level to the initial one." |
| 794 | (interactive) | 793 | (interactive) |
| 795 | (if (and doc-view-scale-internally | 794 | (if doc-view-scale-internally |
| 796 | (eq (plist-get (cdr (doc-view-current-image)) :type) | ||
| 797 | 'imagemagick)) | ||
| 798 | (progn | 795 | (progn |
| 799 | (kill-local-variable 'doc-view-image-width) | 796 | (kill-local-variable 'doc-view-image-width) |
| 800 | (doc-view-insert-image | 797 | (doc-view-insert-image |
| @@ -927,6 +924,32 @@ Resize the containing frame if needed." | |||
| 927 | (when new-frame-params | 924 | (when new-frame-params |
| 928 | (modify-frame-parameters (selected-frame) new-frame-params)))) | 925 | (modify-frame-parameters (selected-frame) new-frame-params)))) |
| 929 | 926 | ||
| 927 | (defun doc-view-center-page-horizontally () | ||
| 928 | "Center page horizontally when page is wider than window." | ||
| 929 | (interactive) | ||
| 930 | (let ((page-width (car (image-size (doc-view-current-image) 'pixel))) | ||
| 931 | (window-width (window-body-width nil 'pixel)) | ||
| 932 | ;; How much do we scroll in order to center the page? | ||
| 933 | (pixel-hscroll 0) | ||
| 934 | ;; How many pixels are there in a column? | ||
| 935 | (col-in-pixel (/ (window-body-width nil 'pixel) | ||
| 936 | (window-body-width nil)))) | ||
| 937 | (when (> page-width window-width) | ||
| 938 | (setq pixel-hscroll (/ (- page-width window-width) 2)) | ||
| 939 | (set-window-hscroll (selected-window) | ||
| 940 | (/ pixel-hscroll col-in-pixel))))) | ||
| 941 | |||
| 942 | (defun doc-view-center-page-vertically () | ||
| 943 | "Center page vertically when page is wider than window." | ||
| 944 | (interactive) | ||
| 945 | (let ((page-height (cdr (image-size (doc-view-current-image) 'pixel))) | ||
| 946 | (window-height (window-body-height nil 'pixel)) | ||
| 947 | ;; How much do we scroll in order to center the page? | ||
| 948 | (pixel-scroll 0)) | ||
| 949 | (when (> page-height window-height) | ||
| 950 | (setq pixel-scroll (/ (- page-height window-height) 2)) | ||
| 951 | (set-window-vscroll (selected-window) pixel-scroll 'pixel)))) | ||
| 952 | |||
| 930 | (defun doc-view-reconvert-doc () | 953 | (defun doc-view-reconvert-doc () |
| 931 | "Reconvert the current document. | 954 | "Reconvert the current document. |
| 932 | Should be invoked when the cached images aren't up-to-date." | 955 | Should be invoked when the cached images aren't up-to-date." |
| @@ -1393,12 +1416,11 @@ ARGS is a list of image descriptors." | |||
| 1393 | ;; Only insert the image if the buffer is visible. | 1416 | ;; Only insert the image if the buffer is visible. |
| 1394 | (when (window-live-p (overlay-get ol 'window)) | 1417 | (when (window-live-p (overlay-get ol 'window)) |
| 1395 | (let* ((image (if (and file (file-readable-p file)) | 1418 | (let* ((image (if (and file (file-readable-p file)) |
| 1396 | (if (not (and doc-view-scale-internally | 1419 | (if (not doc-view-scale-internally) |
| 1397 | (fboundp 'imagemagick-types))) | ||
| 1398 | (apply #'create-image file doc-view--image-type nil args) | 1420 | (apply #'create-image file doc-view--image-type nil args) |
| 1399 | (unless (member :width args) | 1421 | (unless (member :width args) |
| 1400 | (setq args `(,@args :width ,doc-view-image-width))) | 1422 | (setq args `(,@args :width ,doc-view-image-width))) |
| 1401 | (apply #'create-image file 'imagemagick nil args)))) | 1423 | (apply #'create-image file doc-view--image-type nil args)))) |
| 1402 | (slice (doc-view-current-slice)) | 1424 | (slice (doc-view-current-slice)) |
| 1403 | (img-width (and image (car (image-size image)))) | 1425 | (img-width (and image (car (image-size image)))) |
| 1404 | (displayed-img-width (if (and image slice) | 1426 | (displayed-img-width (if (and image slice) |