From: sho nakatani <lay.sakura@gmail.com>
To: Tassilo Horn <tassilo@member.fsf.org>
Cc: 8364@debbugs.gnu.org
Subject: bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el
Date: Thu, 31 Mar 2011 00:49:47 +0900 [thread overview]
Message-ID: <AANLkTinLYR9MZA1FELeZxsZG4o9xyRX_ACbWw+QD_7YP@mail.gmail.com> (raw)
In-Reply-To: <871v1owscz.fsf@member.fsf.org>
[-- Attachment #1: Type: text/plain, Size: 524 bytes --]
Hi!
I finished writing the new patch.
It supports fitting image to window in DocViewMode.
It works even if you set a slices.
Thank you for your advice.
I checked the point.
> I can confirm that ghostscript sometimes has issues with fonts.
> However, in that case it would be awkward if fitting works without
> slice, but fails with slice...
Now it works even with PDF/PS in Japanese!
I found the cause of previous problem in a code I edited.
Please test it and hopefully tell me good results!
Thanks,
--
Sho Nakatani
[-- Attachment #2: doc-view-fit-page-to-window-with-slice-support.patch --]
[-- Type: text/x-patch, Size: 4340 bytes --]
=== modified file 'lisp/doc-view.el'
--- old/lisp/doc-view.el 2011-01-25 04:08:28 +0000
+++ new/lisp/doc-view.el 2011-03-30 15:32:54 +0000
@@ -327,6 +327,10 @@
;; Zoom in/out.
(define-key map "+" 'doc-view-enlarge)
(define-key map "-" 'doc-view-shrink)
+ ;; Fit the image to the window
+ (define-key map "W" 'doc-view-fit-width-to-window)
+ (define-key map "H" 'doc-view-fit-height-to-window)
+ (define-key map "P" 'doc-view-fit-page-to-window)
;; Killing the buffer (and the process)
(define-key map (kbd "k") 'doc-view-kill-proc-and-buffer)
(define-key map (kbd "K") 'doc-view-kill-proc)
@@ -665,6 +669,78 @@
(interactive (list doc-view-shrink-factor))
(doc-view-enlarge (/ 1.0 factor)))
+(defun doc-view-fit-width-to-window ()
+ "Fit the image width to the window width."
+ (interactive)
+ (let ((win-width (- (nth 2 (window-inside-pixel-edges))
+ (nth 0 (window-inside-pixel-edges))))
+ (slice (doc-view-current-slice)))
+ (if (not slice)
+ (let ((img-width (car (image-display-size
+ (image-get-display-property) t))))
+ (doc-view-enlarge (/ (float win-width) (float img-width))))
+
+ ;; If slice is set
+ (let* ((slice-width (nth 2 slice))
+ (scale-factor (/ (float win-width) (float slice-width)))
+ (new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice)))
+
+ (doc-view-enlarge scale-factor)
+ (setf (doc-view-current-slice) new-slice)
+ (doc-view-goto-page (doc-view-current-page))))))
+
+(defun doc-view-fit-height-to-window ()
+ "Fit the image height to the window height."
+ (interactive)
+ (let ((win-height (- (nth 3 (window-inside-pixel-edges))
+ (nth 1 (window-inside-pixel-edges))))
+ (slice (doc-view-current-slice)))
+ (if (not slice)
+ (let ((img-height (cdr (image-display-size
+ (image-get-display-property) t))))
+ ;; When users call 'doc-view-fit-height-to-window',
+ ;; they might want to go to next page by typing SPC
+ ;; ONLY once. So I used '(- win-height 1)' instead of
+ ;; 'win-height'
+ (doc-view-enlarge (/ (float (- win-height 1)) (float img-height))))
+
+ ;; If slice is set
+ (let* ((slice-height (nth 3 slice))
+ (scale-factor (/ (float (- win-height 1)) (float slice-height)))
+ (new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice)))
+
+ (doc-view-enlarge scale-factor)
+ (setf (doc-view-current-slice) new-slice)
+ (doc-view-goto-page (doc-view-current-page))))))
+
+(defun doc-view-fit-page-to-window ()
+ "Fit the image to the window.
+More specifically, this function enlarges image by:
+
+min {(window-width / image-width), (window-height / image-height)} times."
+ (interactive)
+ (let ((win-width (- (nth 2 (window-inside-pixel-edges))
+ (nth 0 (window-inside-pixel-edges))))
+ (win-height (- (nth 3 (window-inside-pixel-edges))
+ (nth 1 (window-inside-pixel-edges))))
+ (slice (doc-view-current-slice)))
+ (if (not slice)
+ (let ((img-width (car (image-display-size
+ (image-get-display-property) t)))
+ (img-height (cdr (image-display-size
+ (image-get-display-property) t))))
+ (doc-view-enlarge (min (/ (float win-width) (float img-width))
+ (/ (float (- win-height 1)) (float img-height)))))
+ ;; If slice is set
+ (let* ((slice-width (nth 2 slice))
+ (slice-height (nth 3 slice))
+ (scale-factor (min (/ (float win-width) (float slice-width))
+ (/ (float (- win-height 1)) (float slice-height))))
+ (new-slice (mapcar (lambda (x) (ceiling (* scale-factor x))) slice)))
+ (doc-view-enlarge scale-factor)
+ (setf (doc-view-current-slice) new-slice)
+ (doc-view-goto-page (doc-view-current-page))))))
+
(defun doc-view-reconvert-doc ()
"Reconvert the current document.
Should be invoked when the cached images aren't up-to-date."
next prev parent reply other threads:[~2011-03-30 15:49 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-28 10:08 bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el Tassilo Horn
[not found] ` <handler.8364.B.130130692430672.ack@debbugs.gnu.org>
2011-03-28 10:38 ` bug#8364: Acknowledgement (24.0.9999; PATCH: Fit to width/height/page for doc-view.el) Tassilo Horn
2011-03-28 14:36 ` bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el Stefan Monnier
2011-03-28 14:56 ` sho nakatani
2011-03-28 15:17 ` Stefan Monnier
2011-03-29 9:32 ` joakim
2011-03-28 15:28 ` Tassilo Horn
2011-03-28 15:58 ` sho nakatani
2011-03-28 17:35 ` Tassilo Horn
2011-03-30 9:10 ` sho nakatani
2011-03-30 10:20 ` Tassilo Horn
[not found] ` <AANLkTinuF6KanSo5XuTQOm+G-+qHzS8QM9zMy3S73-_g@mail.gmail.com>
2011-03-30 13:18 ` Tassilo Horn
2011-03-30 14:35 ` sho nakatani
2011-03-30 15:17 ` Tassilo Horn
2011-03-30 15:49 ` sho nakatani [this message]
2011-03-30 17:07 ` Tassilo Horn
2011-03-30 17:13 ` sho nakatani
2011-03-30 14:42 ` Stefan Monnier
2011-03-30 15:08 ` Tassilo Horn
2011-03-30 21:07 ` Stefan Monnier
2011-03-31 6:32 ` Tassilo Horn
2011-03-31 6:57 ` sho nakatani
2011-03-31 7:47 ` Tassilo Horn
2011-04-08 16:18 ` Chong Yidong
2011-04-08 20:12 ` Tassilo Horn
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTinLYR9MZA1FELeZxsZG4o9xyRX_ACbWw+QD_7YP@mail.gmail.com \
--to=lay.sakura@gmail.com \
--cc=8364@debbugs.gnu.org \
--cc=tassilo@member.fsf.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 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.