From: Yuan Fu <ykf5041@psu.edu>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: "42272@debbugs.gnu.org" <42272@debbugs.gnu.org>
Subject: bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
Date: Fri, 14 Aug 2020 11:02:58 -0400 [thread overview]
Message-ID: <89267A16-E930-479E-B4FA-4CFE61CE9FEC@psu.edu> (raw)
In-Reply-To: <874kp5a1fk.fsf@gnus.org>
[-- Attachment #1: Type: text/plain, Size: 223 bytes --]
> On Aug 14, 2020, at 7:53 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> "Fu, Yuan" <ykf5041@psu.edu> writes:
>
>> Here is the fix patch:
>
> Thanks; applied to Emacs 28.
Cool! Here is the centering patch.
Yuan
[-- Attachment #2: doc-view-center.patch --]
[-- Type: application/octet-stream, Size: 2726 bytes --]
From 216f20f3628900c5dc4ea98a14f38b326a71c480 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Thu, 13 Aug 2020 15:57:47 -0400
Subject: [PATCH] Add centering commands to doc-view.el
* lisp/doc-view.el (doc-view-mode-map): Add binding for centering
commands.
(doc-view-center-page-horizontally, doc-view-center-page-vertically):
New functions.
---
lisp/doc-view.el | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 3e2b244326..77c06a8eaf 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -435,6 +435,9 @@ doc-view-mode-map
(define-key map (kbd "c m") 'doc-view-set-slice-using-mouse)
(define-key map (kbd "c b") 'doc-view-set-slice-from-bounding-box)
(define-key map (kbd "c r") 'doc-view-reset-slice)
+ ;; Centering the image
+ (define-key map (kbd "c h") 'doc-view-center-page-horizontally)
+ (define-key map (kbd "c v") 'doc-view-center-page-vertically)
;; Searching
(define-key map (kbd "C-s") 'doc-view-search)
(define-key map (kbd "<find>") 'doc-view-search)
@@ -921,6 +924,32 @@ doc-view-fit-window-to-page
(when new-frame-params
(modify-frame-parameters (selected-frame) new-frame-params))))
+(defun doc-view-center-page-horizontally ()
+ "Center page horizontally when page is wider than window."
+ (interactive)
+ (let ((page-width (car (image-size (doc-view-current-image) 'pixel)))
+ (window-width (window-body-width nil 'pixel))
+ ;; How much do we scroll in order to center the page?
+ (pixel-hscroll 0)
+ ;; How many pixels are there in a column?
+ (col-in-pixel (/ (window-body-width nil 'pixel)
+ (window-body-width nil))))
+ (when (> page-width window-width)
+ (setq pixel-hscroll (/ (- page-width window-width) 2))
+ (set-window-hscroll (selected-window)
+ (/ pixel-hscroll col-in-pixel)))))
+
+(defun doc-view-center-page-vertically ()
+ "Center page vertically when page is wider than window."
+ (interactive)
+ (let ((page-height (cdr (image-size (doc-view-current-image) 'pixel)))
+ (window-height (window-body-height nil 'pixel))
+ ;; How much do we scroll in order to center the page?
+ (pixel-scroll 0))
+ (when (> page-height window-height)
+ (setq pixel-scroll (/ (- page-height window-height) 2))
+ (set-window-vscroll (selected-window) pixel-scroll 'pixel))))
+
(defun doc-view-reconvert-doc ()
"Reconvert the current document.
Should be invoked when the cached images aren't up-to-date."
--
2.27.0
next prev parent reply other threads:[~2020-08-14 15:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 19:30 bug#42272: 27.0.91; [PATCH] Fix doc-view rescale Fu, Yuan
2020-08-05 15:13 ` Lars Ingebrigtsen
2020-08-07 1:29 ` Yuan Fu
2020-08-07 7:10 ` Lars Ingebrigtsen
2020-08-13 19:34 ` Fu, Yuan
2020-08-14 11:53 ` Lars Ingebrigtsen
2020-08-14 15:02 ` Yuan Fu [this message]
2020-08-14 15:43 ` Lars Ingebrigtsen
2020-08-14 16:39 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=89267A16-E930-479E-B4FA-4CFE61CE9FEC@psu.edu \
--to=ykf5041@psu.edu \
--cc=42272@debbugs.gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).