all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] avoid hard-coded assumptions in image scaling
@ 2021-05-02 20:18 James N. V. Cash
  2021-05-02 20:51 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: James N. V. Cash @ 2021-05-02 20:18 UTC (permalink / raw)
  To: emacs-devel


In image-compute-scaling-factor in images.el, it currently hard-codes
the assumption that the average character width is 10 pixels. Since
`frame-char-width` gives this information though, it seems like it's less
error-prone to use that function instead of assuming.

---
 lisp/image.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lisp/image.el b/lisp/image.el
index 610d020aab..8a9cfec841 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -561,12 +561,11 @@ image-compute-scaling-factor
    ((numberp scaling) scaling)
    ((eq scaling 'auto)
     (let ((width (/ (float (window-width nil t)) (window-width))))
-      ;; If we assume that a typical character is 10 pixels in width,
-      ;; then we should scale all images according to how wide they
-      ;; are.  But don't scale images down.
-      (if (< width 10)
+      ;; We should scale all images according to how wide they are.
+      ;; But don't scale images down.
+      (if (< width (frame-char-width))
           1
-        (/ (float width) 10))))
+        (/ (float width) (frame-char-width)))))
    (t
     (error "Invalid scaling factor %s" scaling))))

--
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] avoid hard-coded assumptions in image scaling
  2021-05-02 20:18 [PATCH] avoid hard-coded assumptions in image scaling James N. V. Cash
@ 2021-05-02 20:51 ` Lars Ingebrigtsen
  2021-05-02 20:56   ` James N. V. Cash
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-02 20:51 UTC (permalink / raw)
  To: James N. V. Cash; +Cc: emacs-devel

"James N. V. Cash" <james.nvc@gmail.com> writes:

> In image-compute-scaling-factor in images.el, it currently hard-codes
> the assumption that the average character width is 10 pixels. Since
> `frame-char-width` gives this information though, it seems like it's less
> error-prone to use that function instead of assuming.

[...]

> +      ;; We should scale all images according to how wide they are.
> +      ;; But don't scale images down.
> +      (if (< width (frame-char-width))
>            1
> -        (/ (float width) 10))))
> +        (/ (float width) (frame-char-width)))))

The point of the heuristic here is that we want to scale images up on
HiDPI screens, so the current code gives me a scaling factor of 2.3.
(I've got a 14" 4K screen.)

(frame-char-width)
=> 23

With your patch, it'll return 1, of course, which is exactly the
opposite of what we want.

(The function could just have used (frame-char-width) divided by ten, I
guess, instead of computing it itself.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] avoid hard-coded assumptions in image scaling
  2021-05-02 20:51 ` Lars Ingebrigtsen
@ 2021-05-02 20:56   ` James N. V. Cash
  0 siblings, 0 replies; 3+ messages in thread
From: James N. V. Cash @ 2021-05-02 20:56 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> The point of the heuristic here is that we want to scale images up on
> HiDPI screens, so the current code gives me a scaling factor of 2.3.
> (I've got a 14" 4K screen.)

Oh, okay, that makes sense! I'm trying to track down why I've been
seeing unexpected svg rendering issues on a 4k screen and came across
this in the process.

Sorry for the incorrect patch then!



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-02 20:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-02 20:18 [PATCH] avoid hard-coded assumptions in image scaling James N. V. Cash
2021-05-02 20:51 ` Lars Ingebrigtsen
2021-05-02 20:56   ` James N. V. Cash

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.