[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#8364: 24.0.9999; PATCH: Fit to width/height/page for doc-view.el

From: sho nakatani
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


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',
    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
    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.

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

      ;; 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
                                        ;by the time all pages are converted
===CODE END===

2011/3/29 Tassilo Horn <address@hidden>:
> sho nakatani <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]