From: Evgeny Zajcev <lg.zevlg@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Add support for `ch' and `cw' dimension specifiers for the image
Date: Thu, 21 Mar 2024 22:14:51 +0300 [thread overview]
Message-ID: <CAO=W_ZrhnFSod6rv+Z+g=0eLXjkJ=gudFkxG-Jn0VsLmRt-_1g@mail.gmail.com> (raw)
In-Reply-To: <86sf0j1q0c.fsf@gnu.org>
[-- Attachment #1.1: Type: text/plain, Size: 415 bytes --]
чт, 21 мар. 2024 г. в 19:57, Eli Zaretskii <eliz@gnu.org>:
> > From: Evgeny Zajcev <lg.zevlg@gmail.com>
> > Date: Thu, 21 Mar 2024 17:53:09 +0300
> >
> > 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))
>
> ENOPATCH
>
:)) sorry, here it is
--
lg
[-- Attachment #1.2: Type: text/html, Size: 1007 bytes --]
[-- Attachment #2: 0001-Add-support-for-ch-and-cw-dimension-specifiers-for-t.patch --]
[-- Type: text/x-patch, Size: 3713 bytes --]
From b13bae3e21c6f8f503e7cbd00003694813acdaca Mon Sep 17 00:00:00 2001
From: Zajcev Evgeny <zevlg@yandex.ru>
Date: Thu, 21 Mar 2024 17:47:29 +0300
Subject: [PATCH] Add support for `ch' and `cw' dimension specifiers for the
image
---
doc/lispref/display.texi | 7 +++++--
src/dispextern.h | 5 +++++
src/image.c | 19 ++++++++++++++++---
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 4dbb4afb20d..73671a21e7f 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -5788,8 +5788,11 @@ Image Descriptors
length in @dfn{ems}@footnote{In typography an em is a distance
equivalent to the height of the type. For example when using 12 point
type 1 em is equal to 12 points. Its use ensures distances and type
-remain proportional.}. One em is equivalent to the height of the font
-and @var{value} may be an integer or a float.
+remain proportional.}. One em is equivalent to the size of the font
+and @var{value} may be an integer or a float. Also, dimension can be
+specified in @code{(@var{value} . ch)} and @code{(@var{value} . cw)}
+forms, where @code{ch} means height of the canonical character and
+@code{cw} means width of the canonical character.
The following is a list of properties that are meaningful for all
image types (there are also properties which are meaningful only for
diff --git a/src/dispextern.h b/src/dispextern.h
index 3a4d6095f73..462b370b810 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3176,6 +3176,11 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo)
int face_font_size;
char *face_font_family;
+ /* Details of the font used to calculate image size relative to the
+ canonical character size, with `ch' and `cw' specifiers. */
+ int face_font_height;
+ int face_font_width;
+
/* True if this image has a `transparent' background -- that is, is
uses an image mask. The accessor macro for this is
`IMAGE_BACKGROUND_TRANSPARENT'. */
diff --git a/src/image.c b/src/image.c
index 9a465f0b180..eb0460759f0 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2557,9 +2557,18 @@ image_get_dimension (struct image *img, Lisp_Object symbol)
if (FIXNATP (value))
return min (XFIXNAT (value), INT_MAX);
- if (CONSP (value) && NUMBERP (CAR (value)) && EQ (Qem, CDR (value)))
- return scale_image_size (img->face_font_size, 1, XFLOATINT (CAR (value)));
-
+ if (CONSP (value) && NUMBERP (CAR (value)))
+ {
+ if (EQ (Qem, CDR (value)))
+ return scale_image_size (img->face_font_size,
+ 1, XFLOATINT (CAR (value)));
+ if (EQ (Qch, CDR (value)))
+ return scale_image_size (img->face_font_height,
+ 1, XFLOATINT (CAR (value)));
+ if (EQ (Qcw, CDR (value)))
+ return scale_image_size (img->face_font_width,
+ 1, XFLOATINT (CAR (value)));
+ }
return -1;
}
@@ -3383,6 +3392,8 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id)
img->face_foreground = foreground;
img->face_background = background;
img->face_font_size = font_size;
+ img->face_font_height = face->font->height;
+ img->face_font_width = face->font->average_width;
img->face_font_family = xmalloc (strlen (font_family) + 1);
strcpy (img->face_font_family, font_family);
img->load_failed_p = ! img->type->load_img (f, img);
@@ -12760,6 +12771,8 @@ syms_of_image (void)
DEFSYM (QCmax_height, ":max-height");
DEFSYM (Qem, "em");
+ DEFSYM (Qch, "ch");
+ DEFSYM (Qcw, "cw");
#ifdef HAVE_NATIVE_TRANSFORMS
DEFSYM (Qscale, "scale");
--
2.25.1
next prev parent reply other threads:[~2024-03-21 19:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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_ZrhnFSod6rv+Z+g=0eLXjkJ=gudFkxG-Jn0VsLmRt-_1g@mail.gmail.com' \
--to=lg.zevlg@gmail.com \
--cc=eliz@gnu.org \
--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.