all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: sho nakatani <lay.sakura@gmail.com>
To: 8364@debbugs.gnu.org
Cc: Tassilo Horn <tassilo@member.fsf.org>
Subject: bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el
Date: Wed, 30 Mar 2011 18:10:05 +0900	[thread overview]
Message-ID: <AANLkTik5Qup87dcfP91ew0fCqTm40Gm_6gHWBWeWWaCF@mail.gmail.com> (raw)
In-Reply-To: <87hbanw3ll.fsf@member.fsf.org>

Hi!

I'm trying to add `fit-slice-to-window' feature in doc-view.el.

Here, `slice' is a part of region of an image.
If you set a slice  on an image in DocViewMode, the region outside the
slice will disappear.
Slice is originally defined in image-mode.el, which doc-view.el requires.

Now I encounter a problem.
I wrote `doc-view-fit-slice-width-to-window' function below but it
doesn't work good.
Just copy and paste the code to lisp/image-mode.el and evaluate it to test.

What I want to implement is:

1. Calculate the scale factor to make the slice fit to window from
slice size and window size.
2. Enlarge the image by the scale factor.
3. Set new slice to the image.

The problem is:

*   I don't know how to reflect a new slice to an image.
    I tried a lot of sequences of `enlarge', `set slice', `reconvert',
`redisplay'.
    But all of the trials ended up failure..
    Here's what I have understood from the code.

    Usually, `doc-view-set-slice' is called to set a slice, in which
`doc-view-goto-page' is called internally to
    redisplay the image.
    However, just calling `doc-view-set-slice' is not enough here
because the image should reconverted
    after it is enlarged. So I set the scale factor to `doc-view-resolution'
    and then called `doc-view-reconvert-doc' (this is what
"(doc-view-enlarge factor)" does).
    So currently I set both new slice and new scale and then call
`doc-view-reconvert-doc'.
    However, `doc-view-reconvert-doc' doesn't call
`doc-view-goto-page' to redisplay the image by the time
    all of the pages are converted.

I'm waiting for your help.
Thanks.

===CODE===
(defun doc-view-fit-slice-width-to-window ()
  (interactive)
  (let ((slice (doc-view-current-slice)))
    (if (null slice)
        (doc-view-fit-width-to-window)

      ;; If slice is set
      (let* ((slice-width (nth 2 slice))
             (win-width (- (nth 2 (window-inside-pixel-edges))
                           (nth 0 (window-inside-pixel-edges))))
             (scale-factor (/ (float win-width) (float slice-width)))
             (new-slice (mapcar (lambda (x) (* scale-factor x)) slice)))

        (set (make-local-variable 'doc-view-resolution)
             (ceiling (* scale-factor doc-view-resolution))) ;Set new
size for image.
        (setf (doc-view-current-slice) nil) ;Set slice.
        (doc-view-reconvert-doc)        ;First, cache file is deleted.
                                        ;Then, new file with new scale
is created.
                                        ;Finally, the new file is
displayed with THE SAME SLICE AS BEFORE
                                        ;by the time all pages are converted
))))
===CODE END===


2011/3/29 Tassilo Horn <tassilo@member.fsf.org>:
> sho nakatani <lay.sakura@gmail.com> writes:
>
> Hi Nakatani,
>
>> I tried the slice feature first. It is GREAT!
>
> Good to hear.
>
>> I want to implement `fit-slice-to-window' feature!
>> I have not touched the feature yet, so it is possible I will encounter
>> big problems (for me!).
>
> Feel free to ask if you encounter problems, preferably on the
> emacs-devel list.
>
>> Please be patient and wait for the new feature.
>
> You have all the time you need.  The "copyright dance" takes at least
> two weeks, anyway. ;-)
>
> Bye,
> Tassilo
>



-- 
Sho Nakatani





  reply	other threads:[~2011-03-30  9:10 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 [this message]
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
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=AANLkTik5Qup87dcfP91ew0fCqTm40Gm_6gHWBWeWWaCF@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.