emacs-devel
[Top][All Lists]
Advanced

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

Re: What is `image-compute-scaling-factor' for?


From: Evgeny Zajcev
Subject: Re: What is `image-compute-scaling-factor' for?
Date: Thu, 24 Dec 2020 20:12:08 +0300



чт, 24 дек. 2020 г. в 17:46, Eli Zaretskii <eliz@gnu.org>:
> From: Evgeny Zajcev <lg.zevlg@gmail.com>
> Date: Thu, 24 Dec 2020 13:52:21 +0300
> Cc: emacs-devel <emacs-devel@gnu.org>
>
>  Doesn't the doc string of create-image (which does the scaling) answer your question?
>
> Sorry, I don't understand it, why 10 pixels? In my case `auto' creates very large images (i.e.
> (frame-char-width) ==> 30), so scaling factor is 3.  This creates very large images by default.
>
> I know I can set `image-scaling-factor` to whatever I need.  However I want to understand the default
> behaviour decision, why 10 pixels is considered as "typical character" width?
>
> I think, by default `create-image' should create images that look good when inserted into buffer, that is *not*
> what I get by default.

See bug#22172.  And if that doesn't explain it, I hope Lars (who wrote
that code) could elaborate.

Lars, could you please elaborate the logic in the `image-compute-scaling-factor'.  As I understand, it means "the larger font you have, the larger image you get"?  But why?  I use large fonts (say 30 pixels in width), in 1920x1080 screen, and I'm totally ok with scale factor 1 for images, but `auto' image-scaling-factor gives me 3 as default scale.  This results in very large images.

Also, the problem with `image-compute-scaling-factor' is that it returns different scale factors for `auto` in different window configurations, because `(/ (window-width nil t) (window-width))` is not always the same

For better `auto' scaling we should consider the physical size of the display and its resolution (that is called DPI I think?) not the size of the font.
But probably this info is not always available.  If we have that DPI info, we can then calculate `auto' scale factor using "typical DPI" (where images looks ok).
Something like:

  (defun image-compute-scaling-factor (scaling)
    (cond
     ((numberp scaling) scaling)
     ((eq scaling 'auto)
      (let* ((mm-height (when (display-graphic-p)
                          (display-mm-height)))
             (dpi (if mm-height
                      (round (/ (display-pixel-height)
                                (/ mm-height 25.4)))
                    ;; DPI is unavailable, use typical DPI
                    72)))
        ;; If we assume that a typical DPI is less then 100, then we should
        ;; scale all images according to how current display DPI is larger,
        ;; then typical DPI.  But don't scale images down.
        (if (< dpi 100)
            1
          (/ (float dpi) 100))))
     (t
      (error "Invalid scaling factor %s" scaling))))

What do you think?

Thanks

--
lg

reply via email to

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