all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Add support for `ch' and `cw' dimension specifiers for the image
@ 2024-03-21 14:53 Evgeny Zajcev
  2024-03-21 16:57 ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Evgeny Zajcev @ 2024-03-21 14:53 UTC (permalink / raw)
  To: emacs-devel

[-- 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 --]

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

end of thread, other threads:[~2024-04-01 23:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-21 14:53 [PATCH] Add support for `ch' and `cw' dimension specifiers for the image Evgeny Zajcev
2024-03-21 16:57 ` 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

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.