From d16d2cbe39d38440d7004411e5a4bb1f741f0d07 Mon Sep 17 00:00:00 2001 From: Zajcev Evgeny Date: Thu, 21 Mar 2024 17:47:29 +0300 Subject: [PATCH] Add support for `ch' and `cw' dimension specifiers for images * src/image.c (image_get_dimension, lookup_image): Handle `ch' and `cw' dimension specifiers in addition to `em'. * src/dispextern.h: Add new members `face_font_height' and `face_font_width' to `struct image'. * doc/lispref/display.texi (Image Descriptors): Document `ch' and `cw'. (cherry picked from commit 61d70186a4a80d0ffc0aaef224e514ff9cac0372) --- doc/lispref/display.texi | 7 +++++-- src/dispextern.h | 5 +++++ src/image.c | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 42927c6dd56..7da73c40cf6 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5816,8 +5816,11 @@ either an integer, which represents the dimension in pixels, or a pair 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 1c3232fae3d..f29377f3596 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3186,6 +3186,11 @@ struct image 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 41d72964631..216bdc1ee66 100644 --- a/src/image.c +++ b/src/image.c @@ -2558,9 +2558,20 @@ 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))) + { + Lisp_Object dim = CDR (value); + if (EQ (Qem, dim)) + return scale_image_size (img->face_font_size, + 1, XFLOATINT (CAR (value))); + if (EQ (Qch, dim)) + return scale_image_size (img->face_font_height, + 1, XFLOATINT (CAR (value))); + if (EQ (Qcw, dim)) + return scale_image_size (img->face_font_width, + 1, XFLOATINT (CAR (value))); + } return -1; } @@ -3384,6 +3395,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); @@ -12794,6 +12807,8 @@ non-numeric, there is no explicit limit on the size of images. */); DEFSYM (QCmax_height, ":max-height"); DEFSYM (Qem, "em"); + DEFSYM (Qch, "ch"); + DEFSYM (Qcw, "cw"); #ifdef HAVE_NATIVE_TRANSFORMS DEFSYM (Qscale, "scale"); -- 2.39.5