From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Evgeny Zajcev Newsgroups: gmane.emacs.devel Subject: Re: What is `image-compute-scaling-factor' for? Date: Thu, 24 Dec 2020 20:12:08 +0300 Message-ID: References: <63B86086-94CB-4E10-9F62-E3F0C563FFB5@gnu.org> <83wnx7ntxe.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000014295205b738e918" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12094"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Eli Zaretskii , Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 24 18:13:48 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksUBQ-0002yU-3M for ged-emacs-devel@m.gmane-mx.org; Thu, 24 Dec 2020 18:13:48 +0100 Original-Received: from localhost ([::1]:60116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksUBO-0002M7-Vu for ged-emacs-devel@m.gmane-mx.org; Thu, 24 Dec 2020 12:13:47 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksUAA-0001ar-QM for emacs-devel@gnu.org; Thu, 24 Dec 2020 12:12:32 -0500 Original-Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]:41051) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ksUA3-000683-Os; Thu, 24 Dec 2020 12:12:28 -0500 Original-Received: by mail-lf1-x133.google.com with SMTP id s26so5899986lfc.8; Thu, 24 Dec 2020 09:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rz+Oddcm8i/kVSW8BVjh2fDFkrfG9ct/NFih5+djfUQ=; b=DVtXUr3N71U2QF0yuCzxvi9q9/uzgZcG2JteHiwqJjFbU7Ua2PDJb/NpbAzJifNO7y eWk86A0dPXkux/1tbMKpeM3+QkAV1OA7B8X3PksuX8HtSzTGc1swLmRAhTpvXigSkDRF zUjyAOJneVHeuBBU8SmfJq0Tk1BgQdnhGk6V+qkZZh4x/qi9gxN7INKGz/92ACYydtIL E1XDvTRnj9hPkrRwIiBDjbkILIcKnccsSDXzxhsFKllCTuCotC7d/rkb8wOySX5EY6Yx BD5cjIb4WNK7V2dFes4Wqsl0Xr0hrxqQkLMn/ctUZffvgSwrakpwuBKKpGasdkxMvMHf 0lFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rz+Oddcm8i/kVSW8BVjh2fDFkrfG9ct/NFih5+djfUQ=; b=tWyv1IznsL+ocU3INbP0LZmrQh2CZ1npa5TPEZo6k0qQnLTwIhnsKsoCkEKIPsgltg xJzY7YUb8+bSr9JopYmeaE88LNcbspCN1f5NRd2zSM+CRVyF65yCrn5pKa7q/cVWGrQH eFMUKMiaRJCxjUaJrOonBIRTa7wfz7qjLmKXVdsdiBhPQ20afWBFqdXyEFPoMK8lJIkB zFKMr3GgkvJkurasNviVuwK4LXl08EUcBopkOCtLxIEdF/IhsBRqGvGKZlk7EdJzauuK fHI47sv6C37qumOnNi+24cf8y6KMTaIxfapH+1TSZQBQxvneinC8GcRwC2/OTPm+EYeg Eglg== X-Gm-Message-State: AOAM532dMtWVvJdPQ+n/u9ceqTpGSR7tqHiMT4y/P+bYaVPbEPsem+UN Ed8soJxvQJ/UwgEWbQMHbuf00OuhtGG96TAQpLEtr04ZqBI= X-Google-Smtp-Source: ABdhPJw1Adma4VPgoY+5S10dXVJ33l6YHu7U80LA6twaCjPlXmJslov9V7w748qJdV49wVTJCcp4KFFcfzeuzSjfhqs= X-Received: by 2002:a05:651c:1282:: with SMTP id 2mr13822881ljc.383.1608829940016; Thu, 24 Dec 2020 09:12:20 -0800 (PST) In-Reply-To: <83wnx7ntxe.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=lg.zevlg@gmail.com; helo=mail-lf1-x133.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:261695 Archived-At: --00000000000014295205b738e918 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =D1=87=D1=82, 24 =D0=B4=D0=B5=D0=BA. 2020 =D0=B3. =D0=B2 17:46, Eli Zaretsk= ii : > > From: Evgeny Zajcev > > Date: Thu, 24 Dec 2020 13:52:21 +0300 > > Cc: emacs-devel > > > > 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) =3D=3D> 30), so scaling factor is 3. This creates v= ery > 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 --=20 lg --00000000000014295205b738e918 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
=D1=87=D1=82, 24 =D0=B4=D0=B5=D0=BA. = 2020 =D0=B3. =D0=B2 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>
>
>=C2=A0 Doesn't the doc string of create-image (which does the scali= ng) 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) =3D=3D> 30), so scaling factor is 3.=C2=A0 This = creates very large images by default.
>
> I know I can set `image-scaling-factor` to whatever I need.=C2=A0 Howe= ver I want to understand the default
> behaviour decision, why 10 pixels is considered as "typical chara= cter" 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.=C2=A0 And if that doesn't explain it, I hope Lars (who w= rote
that code) could elaborate.

Lars, could= you please elaborate the logic in the `image-compute-scaling-factor'.= =C2=A0 As I understand, it means "the larger font you have, the larger= image you get"?=C2=A0 But why?=C2=A0 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 scal= e.=C2=A0 This results in very large images.

Al= so, the problem with `image-compute-scaling-factor' is that it returns = different scale factors for `auto` in different window configurations, beca= use `(/ (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 thin= k?) not the size of the font.
But probably this info is not alway= s available.=C2=A0 If we have that DPI info, we can then calculate `auto= 9; scale factor using "typical DPI" (where images looks ok).
<= /div>
Something like:

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

=
What do you think?

Thanks

--
lg
=
--00000000000014295205b738e918--