unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "James N. V. Cash" <james.nvc@gmail.com>
To: emacs-devel@gnu.org
Subject: [PATCH] avoid hard-coded assumptions in image scaling
Date: Sun, 02 May 2021 16:18:30 -0400	[thread overview]
Message-ID: <87eeeoopnt.fsf@gmail.com> (raw)


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



             reply	other threads:[~2021-05-02 20:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-02 20:18 James N. V. Cash [this message]
2021-05-02 20:51 ` Lars Ingebrigtsen
2021-05-02 20:56   ` James N. V. Cash

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eeeoopnt.fsf@gmail.com \
    --to=james.nvc@gmail.com \
    --cc=emacs-devel@gnu.org \
    --subject='Re: [PATCH] avoid hard-coded assumptions in image scaling' \
    /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

unofficial mirror of emacs-devel@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/emacs-devel/0 emacs-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 emacs-devel emacs-devel/ https://yhetil.org/emacs-devel \
		emacs-devel@gnu.org
	public-inbox-index emacs-devel

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.devel
	nntp://news.gmane.io/gmane.emacs.devel


code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs.git

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git