From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: Using more and/or better icons in Emacs Date: Thu, 15 Apr 2021 16:37:43 +0100 Message-ID: References: <834kg91hyp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="//8a7mgQfDDPX/g3" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12743"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, stefan@marxist.se, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 15 17:39:42 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lX45l-0003C3-W4 for ged-emacs-devel@m.gmane-mx.org; Thu, 15 Apr 2021 17:39:42 +0200 Original-Received: from localhost ([::1]:51980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lX45k-0003oe-Uc for ged-emacs-devel@m.gmane-mx.org; Thu, 15 Apr 2021 11:39:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lX44E-0002ok-AK for emacs-devel@gnu.org; Thu, 15 Apr 2021 11:38:08 -0400 Original-Received: from outbound.soverin.net ([116.202.65.218]:51695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lX449-0006NF-NG; Thu, 15 Apr 2021 11:38:05 -0400 Original-Received: from smtp.soverin.net (unknown [10.10.3.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 6107260232; Thu, 15 Apr 2021 15:37:48 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.142]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1618501067; bh=DMUg6NnrmBWHQEg+tv2uwhVVs5q4684LGGutFhmK3fE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N58tY4OFVl7eD6gM+R1QB9E5Ya1Ny6e8fHF+BvO4nLoSYw9sMhK31JH2AvMG1dboJ rSyJCCADDfhWtAYK7H2jnC2KDv76jeYK23I6Wf5P6h4sgYwSzy/UjzUrfLqAHHlJ/D 6hN3C/F3UtOyIj+FuQIvAGnORgDI3Wbrc4qpeMuLWiHvQ3wXzOGCR/Zea9Wa4I1sgT 7sMkZkQNkxBG+WU6LVeKbFW3U6GG8Z7iAhSEdsJnj9mLPH/jsfV19IECKQOjmDQAm1 r+dMAVsJdGI/26TPIdJcA+HQzjrqwbYbb/74Ws6UMaKq6OBmEja1bKi7NwRuJ1WytV RUjwRJ8b43QrA== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 7B518202BCB1F2; Thu, 15 Apr 2021 16:37:43 +0100 (BST) Mail-Followup-To: Alan Third , Eli Zaretskii , stefan@marxist.se, dgutov@yandex.ru, emacs-devel@gnu.org Content-Disposition: inline In-Reply-To: <834kg91hyp.fsf@gnu.org> Received-SPF: pass client-ip=116.202.65.218; envelope-from=alan@idiocy.org; helo=outbound.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268099 Archived-At: --//8a7mgQfDDPX/g3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 14, 2021 at 09:46:38AM +0300, Eli Zaretskii wrote: > > Date: Tue, 13 Apr 2021 20:50:12 +0100 > > From: Alan Third > > Cc: emacs-devel@gnu.org, Dmitry Gutov > > > > > Your patch LGTM, but I guess it would need documentation and a NEWS entry. > > > Thanks again for working on this! > > > > Thanks. I've attached a version with documentation. I think it's good > > enough but would appreciate someone else double checking it makes sense. > > Thanks, a few minor nits below. Thanks. Hopefully the attached solves the problems, and Stefan's comments too. -- Alan Third --//8a7mgQfDDPX/g3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-Allow-use-of-em-in-image-spec-sizes.patch" >From 362ad64a9ab04709993d330bee120eeb04b7d767 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Mon, 12 Apr 2021 20:30:12 +0100 Subject: [PATCH v3] Allow use of em in image spec sizes * src/image.c (image_get_dimension): New function. (compute_image_size): Use image_get_dimension to set the sizes, and pass in the image struct instead of just the spec. (image_set_transform): (imagemagick_load_image): (svg_load_image): Use the image instead of the spec in compute_image_size. (syms_of_image): Add 'em' as a symbol. --- doc/lispref/display.texi | 10 +++++++ etc/NEWS | 7 +++++ src/image.c | 58 ++++++++++++++++++++++++++++------------ 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 68d7e827d2..4082bb50d9 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5289,6 +5289,16 @@ Image Descriptors and values, including at least the pair @code{:type @var{type}} that specifies the image type. + Image descriptors which define image dimensions, @code{:width}, +@code{:height}, @code{:max-width} and @code{:max-height}, may take +either an integer, which represents the dimension in pixels, or a pair +@code{(@var{value} . 'em)}, where @var{value} is the dimension's +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. + The following is a list of properties that are meaningful for all image types (there are also properties which are meaningful only for certain image types, as documented in the following subsections): diff --git a/etc/NEWS b/etc/NEWS index d3a8748ded..88863e1a55 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1532,6 +1532,13 @@ will match the font size in use where it is embedded. This feature relies on librsvg 2.48 or above being available. ++++ +*** Image properties support 'em' sizes. Size image properties, for +example ':height', ':max-height', etc., can be given a cons of the +form '(SIZE . em)', where SIZE is an integer or float which is +multiplied by the font size to calculate the image size, and em is a +symbol. + ** EWW +++ diff --git a/src/image.c b/src/image.c index 6fe0b23f73..1619886f5a 100644 --- a/src/image.c +++ b/src/image.c @@ -1987,46 +1987,68 @@ scale_image_size (int size, size_t divisor, size_t multiplier) return INT_MAX; } +/* Return a size, in pixels, from the value specified by SYMBOL, which + may be an integer or a pair of the form (VALUE . 'em) where VALUE + is a float that is multiplied by the font size to get the final + dimension. + + If the value doesn't exist in the image spec, or is invalid, return + -1. +*/ +static int +image_get_dimension (struct image *img, Lisp_Object symbol) +{ + Lisp_Object value = image_spec_value (img->spec, symbol, NULL); + + if (FIXNATP (value)) + return min (XFIXNAT (value), INT_MAX); + if (CONSP (value) && NUMBERP (CAR (value)) && EQ (Qem, CDR (value))) + return min (img->face_font_size * XFLOATINT (CAR (value)), INT_MAX); + + return -1; +} + /* Compute the desired size of an image with native size WIDTH x HEIGHT. Use SPEC to deduce the size. Store the desired size into *D_WIDTH x *D_HEIGHT. Store -1 x -1 if the native size is OK. */ static void compute_image_size (size_t width, size_t height, - Lisp_Object spec, + struct image *img, int *d_width, int *d_height) { Lisp_Object value; + int int_value; int desired_width = -1, desired_height = -1, max_width = -1, max_height = -1; double scale = 1; - value = image_spec_value (spec, QCscale, NULL); + value = image_spec_value (img->spec, QCscale, NULL); if (NUMBERP (value)) scale = XFLOATINT (value); - value = image_spec_value (spec, QCmax_width, NULL); - if (FIXNATP (value)) - max_width = min (XFIXNAT (value), INT_MAX); + int_value = image_get_dimension (img, QCmax_width); + if (int_value >= 0) + max_width = int_value; - value = image_spec_value (spec, QCmax_height, NULL); - if (FIXNATP (value)) - max_height = min (XFIXNAT (value), INT_MAX); + int_value = image_get_dimension (img, QCmax_height); + if (int_value >= 0) + max_height = int_value; /* If width and/or height is set in the display spec assume we want to scale to those values. If either h or w is unspecified, the unspecified should be calculated from the specified to preserve aspect ratio. */ - value = image_spec_value (spec, QCwidth, NULL); - if (FIXNATP (value)) + int_value = image_get_dimension (img, QCwidth); + if (int_value >= 0) { - desired_width = min (XFIXNAT (value) * scale, INT_MAX); + desired_width = int_value; /* :width overrides :max-width. */ max_width = -1; } - value = image_spec_value (spec, QCheight, NULL); - if (FIXNATP (value)) + int_value = image_get_dimension (img, QCheight); + if (int_value >= 0) { - desired_height = min (XFIXNAT (value) * scale, INT_MAX); + desired_height = int_value; /* :height overrides :max-height. */ max_height = -1; } @@ -2216,7 +2238,7 @@ image_set_transform (struct frame *f, struct image *img) } else #endif - compute_image_size (img->width, img->height, img->spec, &width, &height); + compute_image_size (img->width, img->height, img, &width, &height); /* Determine rotation. */ double rotation = 0.0; @@ -9210,7 +9232,7 @@ imagemagick_load_image (struct frame *f, struct image *img, compute_image_size (MagickGetImageWidth (image_wand), MagickGetImageHeight (image_wand), - img->spec, &desired_width, &desired_height); + img, &desired_width, &desired_height); if (desired_width != -1 && desired_height != -1) { @@ -10068,7 +10090,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, viewbox_height = dimension_data.height; } - compute_image_size (viewbox_width, viewbox_height, img->spec, + compute_image_size (viewbox_width, viewbox_height, img, &width, &height); width *= FRAME_SCALE_FACTOR (f); @@ -10777,6 +10799,8 @@ syms_of_image (void) DEFSYM (QCmax_width, ":max-width"); DEFSYM (QCmax_height, ":max-height"); + DEFSYM (Qem, "em"); + #ifdef HAVE_NATIVE_TRANSFORMS DEFSYM (Qscale, "scale"); DEFSYM (Qrotate, "rotate"); -- 2.29.2 --//8a7mgQfDDPX/g3--