* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
@ 2020-07-08 19:30 Fu, Yuan
2020-08-05 15:13 ` Lars Ingebrigtsen
0 siblings, 1 reply; 9+ messages in thread
From: Fu, Yuan @ 2020-07-08 19:30 UTC (permalink / raw)
To: 42272
[-- Attachment #1.1: Type: text/plain, Size: 8515 bytes --]
In Emacs 27, doc-view doesn’t to image rescaling if imagemagick is not present. However, since we have native image rescaling now, we want to rescale regardless of imagemagick. I also added convenient centering commands to doc-view.el. Note that the patch is made on Emacs master branch.
Yuan
In GNU Emacs 27.0.91 (build 1, x86_64-apple-darwin19.5.0, NS appkit-1894.50 Version 10.15.5 (Build 19F101))
of 2020-07-07 built on missSilver
Windowing system distributor 'Apple', version 10.3.1894
System Description: Mac OS X 10.15.5
Recent messages:
Auto-saving...done
Mark set
previous-line: Beginning of buffer [3 times]
Auto-saving...done
Saving file /Users/yuan/emacs/.git/COMMIT_EDITMSG...
Wrote /Users/yuan/emacs/.git/COMMIT_EDITMSG
Starting new Ispell process aspell with default dictionary...done
Git finished
user-error: Beginning of history; no preceding item
Sh finished
Configured using:
'configure --with-modules --with-pdumper=yes
--oldincludedir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2/
--with-ns
PKG_CONFIG_PATH=/usr/local/Cellar/zlib/1.2.8/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig'
Configured features:
RSVG DBUS GLIB NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS
XIM NS MODULES THREADS JSON PDUMPER LCMS2
Important settings:
value of $LANG: en_CN.UTF-8
locale-coding-system: utf-8-unix
Major mode: Emacs-Lisp
Minor modes in effect:
global-magit-file-mode: t
magit-file-mode: t
global-git-commit-mode: t
async-bytecomp-package-mode: t
shell-dirtrack-mode: t
bug-reference-prog-mode: t
diff-hl-mode: t
desktop-save-mode: t
which-function-mode: t
color-outline-mode: t
hi-lock-mode: t
info-pretty-mode: t
wucuo-mode: t
yas-global-mode: t
yas-minor-mode: t
minibuffer-electric-default-mode: t
flymake-mode: t
minions-mode: t
eyebrowse-mode: t
savehist-mode: t
global-hl-todo-mode: t
hl-todo-mode: t
global-highlight-parentheses-mode: t
highlight-parentheses-mode: t
rainbow-delimiters-mode: t
electric-pair-mode: t
winner-mode: t
aggressive-indent-mode: t
recentf-mode: t
which-key-mode: t
general-override-mode: t
outline-minor-mode: t
counsel-mode: t
ivy-mode: t
company-mode: t
override-global-mode: t
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
electric-quote-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
hs-minor-mode: t
Load-path shadows:
/Users/yuan/.emacs.d/package/jsonrpc-1.0.12/jsonrpc hides /Applications/Emacs.app/Contents/Resources/lisp/jsonrpc
/Users/yuan/.emacs.d/package/xref-1.0.1/xref hides /Applications/Emacs.app/Contents/Resources/lisp/progmodes/xref
/Users/yuan/.emacs.d/package/project-0.5.0/project hides /Applications/Emacs.app/Contents/Resources/lisp/progmodes/project
/Users/yuan/.emacs.d/package/faceup-20170925.1946/faceup hides /Applications/Emacs.app/Contents/Resources/lisp/emacs-lisp/faceup
/Users/yuan/.emacs.d/package/eldoc-1.0.0/eldoc hides /Applications/Emacs.app/Contents/Resources/lisp/emacs-lisp/eldoc
/Applications/Emacs.app/Contents/Resources/lisp/mail/metamail hides /Applications/Emacs.app/Contents/Resources/lisp/obsolete/metamail
/Applications/Emacs.app/Contents/Resources/lisp/sb-image hides /Applications/Emacs.app/Contents/Resources/lisp/obsolete/sb-image
Features:
(shadow sort mail-extr emacsbug sendmail magit-extras
magit-patch-changelog magit-patch magit-bookmark magit-submodule
magit-obsolete magit-blame magit-stash magit-reflog magit-bisect
magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
magit-repos magit-apply magit-wip magit-log magit-diff smerge-mode diff
magit-core magit-autorevert autorevert magit-margin magit-transient
magit-process magit-mode git-commit transient magit-git magit-section
magit-utils crm log-edit message rfc822 mml mml-sec epa derived epg
epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode
mailabbrev mail-utils gmm-utils mailheader pcvs-util with-editor
async-bytecomp shell server add-log bug-reference vc-git vc-bzr vc-src
vc-sccs vc-svn vc-cvs vc-rcs bookmark text-property-search checkdoc
hideshow diff-hl vc-dir vc vc-dispatcher diff-mode company-oddmuse
company-keywords company-etags etags fileloop company-gtags
company-dabbrev-code company-dabbrev company-files company-capf
company-cmake company-xcode company-clang company-semantic company-eclim
company-template company-bbdb desktop frameset luna-general-config
which-func cus-load agda2 jka-compr cyberpunk-theme light-theme
theme-util sidebar valign htmlize cl luna-publish rss-export ox-cjk-html
ox-odt rng-loc rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn
nxml-parse nxml-ns nxml-enc xmltok nxml-util ox-latex ox-icalendar
ox-html table ox-ascii ox-publish ox org-element avl-tree generator
outline+ ghelp ghelp-eglot ghelp-helpful ghelp-builtin quanjiao
commentary color-outline hi-lock info+ pause utility transform
org-download org-attach org-id url-http url url-proxy url-privacy
url-expand url-methods url-history mailcap url-auth mail-parse rfc2231
rfc2047 rfc2045 mm-util ietf-drums mail-prsvr url-cookie url-domsuf
url-gw nsm rmc puny async olivetti dired-x ivy-xref wucuo yasnippet
minibuf-eldef eglot array filenotify jsonrpc ert pp ewoc debug
flymake-proc flymake warnings url-util flycheck flyspell ispell isolate
inline expand-region text-mode-expansions the-org-mode-expansions
er-basic-expansions thingatpt expand-region-core expand-region-custom
ws-butler minions eyebrowse savehist buffer-move windmove hl-todo
highlight-parentheses rainbow-delimiters elec-pair winner
aggressive-indent lisp-mnt recentf-ext recentf tree-widget wid-edit
which-key general helpful imenu trace edebug backtrace info-look f
dash-functional help-fns radix-tree elisp-refs s loop dash org ob
ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-footnote org-src
ob-comint org-pcomplete pcomplete org-list org-faces org-entities
time-date noutline outline org-version ob-emacs-lisp ob-core ob-eval
org-table ol org-keys org-compat org-macs org-loaddefs format-spec
find-func cal-menu calendar cal-loaddefs counsel xdg advice xref project
dired dired-loaddefs compile comint ansi-color swiper cl-extra help-mode
ivy delsel ring ivy-faces ivy-overlay colir color company pcase
use-package use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key use-package-core finder-inf tex-site
edmacro kmacro proof-site proof-autoloads info cowboy package easymenu
browse-url url-handlers url-parse auth-source cl-seq eieio eieio-core
cl-macs eieio-loaddefs password-cache json subr-x map url-vars
cl-loaddefs cl-lib lunary lunary-ui easy-mmode luna-local luna-f rx seq
byte-opt gv bytecomp byte-compile cconv tooltip cus-start eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind kqueue
cocoa ns lcms2 multi-tty make-network-process emacs)
Memory information:
((conses 16 133108 66388)
(symbols 48 10974 7)
(strings 32 38509 14005)
(string-bytes 1 1141424)
(vectors 16 20975)
(vector-slots 8 273883 72414)
(floats 8 81 468)
(intervals 56 1667 452)
(buffers 1000 26))
[-- Attachment #1.2: Type: text/html, Size: 9905 bytes --]
[-- Attachment #2: doc-view.patch --]
[-- Type: application/octet-stream, Size: 6628 bytes --]
From 1dced88a90a5cf3e940747d2958b02b95ea3491c Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Wed, 8 Jul 2020 15:21:48 -0400
Subject: [PATCH] Remove imagemagick code in doc-view and add centering
commands
The problem with old imagemagick code is that, doc-view checks for
imagemagick and only rescales the image if imagemagic is present.
Now that we have natice rescaling, we want to rescale image regardless.
* lisp/doc-view.el (doc-view-mode-map): Add binding for centering
commands.
(doc-view-mode-p, doc-view-enlarge, doc-view-scale-reset,
doc-view-insert-image): Remove imagemagick code.
(doc-view--auto-center-horizontally,
doc-view--auto-center-vertically): New variables.
(doc-view-toggle-auto-center-page-horizontally,
doc-view-toggle-auto-center-page-vertically,
doc-view-auto-center,
doc-view-center-page-horizontally,
doc-view-center-page-vertically): New functions.
---
lisp/doc-view.el | 79 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 67 insertions(+), 12 deletions(-)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index de342f1519..db0e1de233 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -435,6 +435,11 @@ 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)
+ (define-key map (kbd "c H") 'doc-view-toggle-auto-center-page-horizontally)
+ (define-key map (kbd "c V") 'doc-view-toggle-auto-center-page-vertically)
;; Searching
(define-key map (kbd "C-s") 'doc-view-search)
(define-key map (kbd "<find>") 'doc-view-search)
@@ -740,8 +745,7 @@ doc-view-mode-p
Document types are symbols like `dvi', `ps', `pdf', or `odf' (any
OpenDocument format)."
(and (display-graphic-p)
- (or (image-type-available-p 'imagemagick)
- (image-type-available-p 'png))
+ (image-type-available-p 'png)
(cond
((eq type 'dvi)
(and (doc-view-mode-p 'pdf)
@@ -769,10 +773,7 @@ doc-view-shrink-factor
(defun doc-view-enlarge (factor)
"Enlarge the document by FACTOR."
(interactive (list doc-view-shrink-factor))
- (if (and doc-view-scale-internally
- (eq (plist-get (cdr (doc-view-current-image)) :type)
- 'imagemagick))
- ;; ImageMagick supports on-the-fly-rescaling.
+ (if doc-view-scale-internally
(let ((new (ceiling (* factor doc-view-image-width))))
(unless (equal new doc-view-image-width)
(setq-local doc-view-image-width new)
@@ -792,9 +793,7 @@ doc-view-shrink
(defun doc-view-scale-reset ()
"Reset the document size/zoom level to the initial one."
(interactive)
- (if (and doc-view-scale-internally
- (eq (plist-get (cdr (doc-view-current-image)) :type)
- 'imagemagick))
+ (if doc-view-scale-internally
(progn
(kill-local-variable 'doc-view-image-width)
(doc-view-insert-image
@@ -927,6 +926,63 @@ doc-view-fit-window-to-page
(when new-frame-params
(modify-frame-parameters (selected-frame) new-frame-params))))
+(defvar-local doc-view--auto-center-horizontally nil
+ "If non-nil, automatically center page horizontally.")
+
+(defvar-local doc-view--auto-center-vertically nil
+ "If non-nil, automatically center page vertically.")
+
+(defun doc-view-toggle-auto-center-page-horizontally ()
+ "Toggle whether to automatically center page horizontally."
+ (interactive)
+ (setq doc-view--auto-center-horizontally
+ (not doc-view--auto-center-horizontally))
+ (message "Auto center horizontally: %s"
+ (if doc-view--auto-center-horizontally
+ "on" "off")))
+
+(defun doc-view-toggle-auto-center-page-vertically ()
+ "Toggle whether to automatically center page vertically."
+ (interactive)
+ (setq doc-view--auto-center-vertically
+ (not doc-view--auto-center-vertically))
+ (message "Auto center vertically: %s"
+ (if doc-view--auto-center-vertically
+ "on" "off")))
+
+(defun doc-view-auto-center ()
+ "Automatically center page."
+ (when doc-view--auto-center-horizontally
+ (doc-view-center-page-horizontally))
+ (when doc-view--auto-center-vertically
+ (doc-view-center-page-vertically)))
+
+(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."
@@ -1393,12 +1449,11 @@ doc-view-insert-image
;; Only insert the image if the buffer is visible.
(when (window-live-p (overlay-get ol 'window))
(let* ((image (if (and file (file-readable-p file))
- (if (not (and doc-view-scale-internally
- (fboundp 'imagemagick-types)))
+ (if (not doc-view-scale-internally)
(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))))
+ (apply #'create-image file doc-view--image-type nil args))))
(slice (doc-view-current-slice))
(img-width (and image (car (image-size image))))
(displayed-img-width (if (and image slice)
--
2.27.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
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
0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-05 15:13 UTC (permalink / raw)
To: Fu, Yuan; +Cc: 42272
"Fu, Yuan" <ykf5041@psu.edu> writes:
> In Emacs 27, doc-view doesn’t to image rescaling if imagemagick is not
> present. However, since we have native image rescaling now, we want
> to rescale regardless of imagemagick. I also added convenient
> centering commands to doc-view.el. Note that the patch is made on
> Emacs master branch.
The imagemagick fixes look good to me, and the new functionality, too.
But this should probably be done in two separate patches, and the patch
with the new functionality also needs to be documented in the Document
View node in the misc.texi manual. (And it also needs an etc/NEWS
entry.)
Can you do the patch splitting and documentation additions and resubmit?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
2020-08-05 15:13 ` Lars Ingebrigtsen
@ 2020-08-07 1:29 ` Yuan Fu
2020-08-07 7:10 ` Lars Ingebrigtsen
0 siblings, 1 reply; 9+ messages in thread
From: Yuan Fu @ 2020-08-07 1:29 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 42272
> On Aug 5, 2020, at 11:13 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> "Fu, Yuan" <ykf5041@psu.edu> writes:
>
>> In Emacs 27, doc-view doesn’t to image rescaling if imagemagick is not
>> present. However, since we have native image rescaling now, we want
>> to rescale regardless of imagemagick. I also added convenient
>> centering commands to doc-view.el. Note that the patch is made on
>> Emacs master branch.
>
> The imagemagick fixes look good to me, and the new functionality, too.
> But this should probably be done in two separate patches, and the patch
> with the new functionality also needs to be documented in the Document
> View node in the misc.texi manual. (And it also needs an etc/NEWS
> entry.)
>
> Can you do the patch splitting and documentation additions and resubmit?
>
Sure! However, I’ll be busy for a couple months so I need to find time to do it.
Yuan
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
2020-08-07 1:29 ` Yuan Fu
@ 2020-08-07 7:10 ` Lars Ingebrigtsen
2020-08-13 19:34 ` Fu, Yuan
0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-07 7:10 UTC (permalink / raw)
To: Yuan Fu; +Cc: 42272
Yuan Fu <ykf5041@psu.edu> writes:
>> Can you do the patch splitting and documentation additions and resubmit?
>>
>
> Sure! However, I’ll be busy for a couple months so I need to find time
> to do it.
Great; looking forward to it.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
2020-08-07 7:10 ` Lars Ingebrigtsen
@ 2020-08-13 19:34 ` Fu, Yuan
2020-08-14 11:53 ` Lars Ingebrigtsen
0 siblings, 1 reply; 9+ messages in thread
From: Fu, Yuan @ 2020-08-13 19:34 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 42272@debbugs.gnu.org
[-- Attachment #1.1: Type: text/plain, Size: 372 bytes --]
> On Aug 7, 2020, at 3:10 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Yuan Fu <ykf5041@psu.edu> writes:
>
>>> Can you do the patch splitting and documentation additions and resubmit?
>>>
>>
>> Sure! However, I’ll be busy for a couple months so I need to find time
>> to do it.
>
> Great; looking forward to it.
Here is the fix patch:
Yuan
[-- Attachment #1.2: Type: text/html, Size: 885 bytes --]
[-- Attachment #2: doc-view-fix.patch --]
[-- Type: application/octet-stream, Size: 2886 bytes --]
From e7c62a8a7759f86be189e52c50d780b875ab7853 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Thu, 13 Aug 2020 15:03:14 -0400
Subject: [PATCH] Remove imagemagick checks in doc-view.el
The problem with old imagemagick code is that, doc-view checks for
imagemagick and only rescales the image if it is present. Now that we
have native re-scaling and don't compile with imagemagic by default,
we want to rescale image regardless of imagemagic.
* lisp/doc-view.el (doc-view-mode-p, doc-view-enlarge,
doc-view-scale-reset, doc-view-insert-image): Remove checks for
imagemagick.
---
lisp/doc-view.el | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index de342f1519..3e2b244326 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -740,8 +740,7 @@ doc-view-mode-p
Document types are symbols like `dvi', `ps', `pdf', or `odf' (any
OpenDocument format)."
(and (display-graphic-p)
- (or (image-type-available-p 'imagemagick)
- (image-type-available-p 'png))
+ (image-type-available-p 'png)
(cond
((eq type 'dvi)
(and (doc-view-mode-p 'pdf)
@@ -769,10 +768,7 @@ doc-view-shrink-factor
(defun doc-view-enlarge (factor)
"Enlarge the document by FACTOR."
(interactive (list doc-view-shrink-factor))
- (if (and doc-view-scale-internally
- (eq (plist-get (cdr (doc-view-current-image)) :type)
- 'imagemagick))
- ;; ImageMagick supports on-the-fly-rescaling.
+ (if doc-view-scale-internally
(let ((new (ceiling (* factor doc-view-image-width))))
(unless (equal new doc-view-image-width)
(setq-local doc-view-image-width new)
@@ -792,9 +788,7 @@ doc-view-shrink
(defun doc-view-scale-reset ()
"Reset the document size/zoom level to the initial one."
(interactive)
- (if (and doc-view-scale-internally
- (eq (plist-get (cdr (doc-view-current-image)) :type)
- 'imagemagick))
+ (if doc-view-scale-internally
(progn
(kill-local-variable 'doc-view-image-width)
(doc-view-insert-image
@@ -1393,12 +1387,11 @@ doc-view-insert-image
;; Only insert the image if the buffer is visible.
(when (window-live-p (overlay-get ol 'window))
(let* ((image (if (and file (file-readable-p file))
- (if (not (and doc-view-scale-internally
- (fboundp 'imagemagick-types)))
+ (if (not doc-view-scale-internally)
(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))))
+ (apply #'create-image file doc-view--image-type nil args))))
(slice (doc-view-current-slice))
(img-width (and image (car (image-size image))))
(displayed-img-width (if (and image slice)
--
2.27.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
2020-08-13 19:34 ` Fu, Yuan
@ 2020-08-14 11:53 ` Lars Ingebrigtsen
2020-08-14 15:02 ` Yuan Fu
0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-14 11:53 UTC (permalink / raw)
To: Fu, Yuan; +Cc: 42272@debbugs.gnu.org
"Fu, Yuan" <ykf5041@psu.edu> writes:
> Here is the fix patch:
Thanks; applied to Emacs 28.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#42272: 27.0.91; [PATCH] Fix doc-view rescale
2020-08-14 11:53 ` Lars Ingebrigtsen
@ 2020-08-14 15:02 ` Yuan Fu
2020-08-14 15:43 ` Lars Ingebrigtsen
0 siblings, 1 reply; 9+ messages in thread
From: Yuan Fu @ 2020-08-14 15:02 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 42272@debbugs.gnu.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
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-08-14 16:39 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2020-08-14 15:43 ` Lars Ingebrigtsen
2020-08-14 16:39 ` Yuan Fu
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.