all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Evgeny Zajcev <lg.zevlg@gmail.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: [PATCH] Add support for `ch' and `cw' dimension specifiers for the image
Date: Thu, 21 Mar 2024 17:53:09 +0300	[thread overview]
Message-ID: <CAO=W_ZqD8E3dJ8u8wvWrpf-74XBDw=jUJWydnR-1gYioJmRNOQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1994 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2454 bytes --]

             reply	other threads:[~2024-03-21 14:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21 14:53 Evgeny Zajcev [this message]
2024-03-21 16:57 ` [PATCH] Add support for `ch' and `cw' dimension specifiers for the image Eli Zaretskii
2024-03-21 19:14   ` Evgeny Zajcev
2024-03-28 10:06     ` Eli Zaretskii
2024-03-28 10:50       ` Evgeny Zajcev
2024-03-28 11:29         ` Evgeny Zajcev
2024-03-31  8:44           ` Eli Zaretskii
2024-04-01  9:43             ` Evgeny Zajcev
2024-04-01 11:42               ` Eli Zaretskii
2024-04-01 23:02                 ` lg.zevlg
2024-04-01 23:06                   ` lg.zevlg
2024-03-28 11:41         ` Alan Third
2024-03-28 19:34           ` Evgeny Zajcev
2024-03-29  9:50             ` Alan Third
2024-03-29 10:52               ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to='CAO=W_ZqD8E3dJ8u8wvWrpf-74XBDw=jUJWydnR-1gYioJmRNOQ@mail.gmail.com' \
    --to=lg.zevlg@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.