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'.
This commit is contained in:
Zajcev Evgeny 2024-03-21 17:47:29 +03:00 committed by Eli Zaretskii
parent 7f377407b4
commit 61d70186a4
3 changed files with 27 additions and 4 deletions

View file

@ -5788,8 +5788,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

View file

@ -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'. */

View file

@ -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");