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: [PATCH] Add support for `ch' and `cw' dimension specifiers for the image Date: Thu, 21 Mar 2024 17:53:09 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000054840106142cde58" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15451"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 21 15:54:15 2024 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 1rnJo6-0003pl-Nt for ged-emacs-devel@m.gmane-mx.org; Thu, 21 Mar 2024 15:54:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnJnM-0000dv-Td; Thu, 21 Mar 2024 10:53:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rnJnK-0000dc-Mo for emacs-devel@gnu.org; Thu, 21 Mar 2024 10:53:26 -0400 Original-Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rnJnJ-00008B-0n for emacs-devel@gnu.org; Thu, 21 Mar 2024 10:53:26 -0400 Original-Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5c229dabbb6so620179a12.0 for ; Thu, 21 Mar 2024 07:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711032801; x=1711637601; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Imw2qAqg8qKBuenDY4BgqfGRrMeH0W07cvvBbpDjdYw=; b=MPbLGJPscC+xEEHOHQKK/7UnuHpo8f1RyUKu6NFrgCbYeGudbTj+0RqF8wVR0asV1I Pi7DjssOahqAMYr49H+FCPhTELU4MwcjVGfeMLqZ9exrmz5Zyz1BS3pIF02pv97A2WT9 Srx+kfX6ACs68b7+C0S4DGaM8U8dO7GJlcKjPhulyit8Ajw4mSqXIlMiEjIjz+fPVMPK V4ufhBy4TrxOG9sC+Xov5j09S0slqs58phX3BAKOd69C1V/Oee1lCQ3RHtspWN2EaoDd L+eVGQHByzQ9UdBFCRIkdPNXajNh4a7J+Fmjcmkf3Y2QbksECX6MuIGRyyYPFf/DcCxW LToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032801; x=1711637601; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Imw2qAqg8qKBuenDY4BgqfGRrMeH0W07cvvBbpDjdYw=; b=pne3aayy/V00qvTTpn4b6X2z6oOQ8IRQDn+YeWSvl5byeFVKdI0XOm9rIek9QxgqIA L65eK+DbF/KCMxcI94IxxjKdprgTQU23NsMQfJip1deubiCcpWeRIa+eymlJd8CrtmaU OdlxF6q8EbhTnrtCqyKkyIPrMT/uYd7jxhIBJh4ra6NJW3ALLRtT75eEL00FSBfGNd6G IKO3K2ijzuR5GRnjJYmuKPn/NwioI1zuxO/+nN0t5eOa/rXtc7Qrco4xOCm7fHFOTPkH ONVttZl7kt63YIcwFY38ozVanOp7xH3w/Ux5CkMVmHl9JNhrbXYnnrMsFaUf6DE1+qfg Tujw== X-Gm-Message-State: AOJu0Yyv3X8OgsYXfgL8wFkv3Jg/8y+9zWaZ1zF2JRkI3Id8DbqZx3qB MnnhnO4DUVc/gBxmHm2xuRI0Ko1kbMyPyd08Ufm9m0Ww5rYBk3fwYxvDrPmkycek6kEVAM7A+21 1GElEOYmwST4qYrAZ/0bnuflEZWy7WPC4oY0= X-Google-Smtp-Source: AGHT+IFzoyWnNrgQ8jj5EehwUBpdMs9f2N+Uglres010p0/+hz73bt/m96/WwnR1dALH5Tm5XLsAAHKydptRvNFUciU= X-Received: by 2002:a17:90a:9e7:b0:29a:6c13:f0a with SMTP id 94-20020a17090a09e700b0029a6c130f0amr7866977pjo.16.1711032801458; Thu, 21 Mar 2024 07:53:21 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=lg.zevlg@gmail.com; helo=mail-pg1-x533.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.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317226 Archived-At: --00000000000054840106142cde58 Content-Type: text/plain; charset="UTF-8" Motivation: It is essential to have functionality where image size adjusts automatically to the display conditions. Right now we have `em' element to specify image size relative to the font size. However, this is not enough for the grain control of how the image is displayed. Because for the same font, but different font sizes, ratio of font height to font size and ratio of average font width to font size **differs**. Making it impossible to have the same image to look the same for different font sizes of the same font. Here is an example. I need an image which occupies 2 chars, but in the same time its height must not exceed line height: (defun my-em-width-ratio () (let ((info (font-info (face-font 'default)))) ;; avg-width / pixel-size (/ (float (aref info 11)) (aref info 2)))) (defun my-em-height-ratio () (let ((info (font-info (face-font 'default)))) ;; height / pixel-size (/ (float (aref info 3)) (aref info 2)))) (list 'image :type 'svg :file "file.svg" :scale 1.0 :ascent 'center :width (cons (* 2 (my-em-width-ratio)) 'em) :max-height (cons (* 1 (my-em-height-ratio)) 'em)) Note that `em' means font size and not the font height, but for some fonts font size and font height differs. This works very well. However, if I execute `M-x text-scale-decrease RET' or `M-x text-scale-increase RET' image starts looking differently, not fitting into 2 chars width. Because font ratios changes. Before scaling: (my-em-width-ratio) => 0.5111111111111111 (my-em-height-ratio) => 1.0666666666666667 After scaling: (my-em-width-ratio) => 0.5135135135135135 (my-em-height-ratio) => 1.054054054054054 With applied patch and image specified as: (list 'image :type 'svg :file "file.svg" :scale 1.0 :ascent 'center :width '(2 . cw) :max-height '(1 . ch)) Image looks the same and occupies exactly the same amount of characters for different font sizes of the same font. Thanks. -- lg --00000000000054840106142cde58 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Motivation:

It is essential to have functionality w= here image size adjusts
automatically to the display conditions.=C2=A0 R= ight now we have `em'
element to specify image size relative to the = font size.=C2=A0 However,
this is not enough for the grain control of ho= w the image is displayed.
Because for the same font, but different font = sizes, ratio of font
height to font size and ratio of average font width= to font size
**differs**.=C2=A0 Making it impossible to have the same i= mage to look the same
for different font sizes of the same font.

= Here is an example.=C2=A0 I need an image which occupies 2 chars, but inthe same time its height must not exceed line height:

=C2=A0 (defun= my-em-width-ratio ()
=C2=A0 =C2=A0 (let ((info (font-info (face-font &#= 39;default))))
=C2=A0 =C2=A0 =C2=A0 ;; avg-width / pixel-size
=C2=A0 = =C2=A0 =C2=A0 (/ (float (aref info 11)) (aref info 2))))

=C2=A0 (def= un my-em-height-ratio ()
=C2=A0 =C2=A0 (let ((info (font-info (face-font= 'default))))
=C2=A0 =C2=A0 =C2=A0 ;; height / pixel-size
=C2=A0 = =C2=A0 =C2=A0 (/ (float (aref info 3)) (aref info 2))))

=C2=A0 (list= 'image :type 'svg :file "file.svg" :scale 1.0 :ascent &#= 39;center
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0:width (cons (* 2 (my-em-wid= th-ratio)) 'em)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0:max-height (cons = (* 1 (my-em-height-ratio)) 'em))

Note that `em' means font s= ize and not the font height, but for some
fonts font size and font heigh= t differs.

This works very well.=C2=A0 However, if I execute `M-x te= xt-scale-decrease
RET' or `M-x text-scale-increase RET' image st= arts looking
differently, not fitting into 2 chars width.=C2=A0 Because = font ratios
changes.

Before scaling:
=C2=A0 (my-em-width-ratio= ) =C2=A0=3D> 0.5111111111111111
=C2=A0 (my-em-height-ratio) =3D> 1= .0666666666666667

After scaling:
=C2=A0 (my-em-width-ratio) =C2= =A0=3D> 0.5135135135135135
=C2=A0 (my-em-height-ratio) =3D> 1.0540= 54054054054

With applied patch and image specified as:

=C2=A0= (list 'image :type 'svg :file "file.svg" :scale 1.0 :asc= ent 'center
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0:width '(2 . cw)=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0:max-height '(1 . ch))

Image= looks the same and occupies exactly the same amount of
characters for d= ifferent font sizes of the same font.

Thanks.

--
lg
--00000000000054840106142cde58--