]> git.eshelyaron.com Git - emacs.git/commitdiff
Add support for `ch' and `cw' dimension specifiers for images
authorZajcev Evgeny <zevlg@yandex.ru>
Thu, 21 Mar 2024 14:47:29 +0000 (17:47 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 2 Apr 2024 13:27:46 +0000 (15:27 +0200)
* 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
src/dispextern.h
src/image.c

index 42927c6dd56717b696dfd29e610dd3214760d7da..7da73c40cf6ef978eeed104427fe84260e12a6c0 100644 (file)
@@ -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
index 1c3232fae3dc132a5935ed4c9bc3e989d9a0d92d..f29377f359678e3646174b8c2d8a67d6c19895be 100644 (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'.  */
index 41d72964631ba708974e213bd0312a2630511693..216bdc1ee66b647a8ab014146829b83cbf995423 100644 (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");