From 449e860fdec65e92ebca50e99a21afc9ea9c4206 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 the image * src/frame.c (image_get_dimension): Handle `ch' and `cw' dimension specifiers in addition to `em' --- 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 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..341fb3ac077 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..244a694a52b 100644 --- a/src/image.c +++ b/src/image.c @@ -2557,9 +2557,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; } @@ -3383,6 +3394,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 +12773,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