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.bugs Subject: bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets Date: Mon, 15 Mar 2021 21:34:24 +0000 Message-ID: References: <83a6r9mwgk.fsf@gnu.org> <8335x1mpdk.fsf@gnu.org> <83o8flfu4l.fsf@gnu.org> <83im5tfr6t.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Ph3uCkv/6bY85x+4" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18975"; mail-complaints-to="usenet@ciao.gmane.io" Cc: stefan@marxist.se, 47074@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 15 22:35:18 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1lLurt-0004lL-JB for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Mar 2021 22:35:17 +0100 Original-Received: from localhost ([::1]:53356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLurs-0005v8-ID for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Mar 2021 17:35:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLurf-0005tP-OL for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2021 17:35:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54096) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLurd-0000xn-QH for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2021 17:35:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lLurd-0001od-NQ for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2021 17:35:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Mar 2021 21:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47074 X-GNU-PR-Package: emacs Original-Received: via spool by 47074-submit@debbugs.gnu.org id=B47074.16158440806948 (code B ref 47074); Mon, 15 Mar 2021 21:35:01 +0000 Original-Received: (at 47074) by debbugs.gnu.org; 15 Mar 2021 21:34:40 +0000 Original-Received: from localhost ([127.0.0.1]:37409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLurH-0001nz-Jh for submit@debbugs.gnu.org; Mon, 15 Mar 2021 17:34:40 -0400 Original-Received: from outbound.soverin.net ([116.202.65.218]:35993) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLurE-0001nj-Ql for 47074@debbugs.gnu.org; Mon, 15 Mar 2021 17:34:38 -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 A50D2600D0; Mon, 15 Mar 2021 21:34:30 +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=1615844069; bh=KFTvPDLjrRIxkcRZehr2s3vTWPloakxZcarKhTYKhVI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NC6B561x/pbUcHXRgrfrCMZODWcqU62G3WKibKx18xyyNomOKtJ4AKvhqhMi2lI4U iaOTHUhVlX8SfmCb7HB+PSm3CjSn36OG/tNkKXkfLzVeJdeRE+uY6ulVLa3ilo1EfF lBvg/lXdfFlZXbxBzAomY3Rjf1+61eYmFY02qrtEHPZrKEw4DxAM1/lOjsjUPGiIEM N0rr1Ov4aXm4tsfWg1x4wzm33YEeV+FeVfcebmcbCNw80mJI/w9JMQRZluqI8hjKLu DxnfhSojbNMd0gvyadViYhfCs1yv9DPICnLxBFofnmWTl1f+Xl7f7s+zoQi3g2eruQ u5h5+/tGDWy2w== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 66A4F202AFCD82; Mon, 15 Mar 2021 21:34:24 +0000 (GMT) Mail-Followup-To: Alan Third , Eli Zaretskii , stefan@marxist.se, 47074@debbugs.gnu.org Content-Disposition: inline In-Reply-To: <83im5tfr6t.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:202434 Archived-At: --Ph3uCkv/6bY85x+4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Mar 14, 2021 at 09:52:58PM +0200, Eli Zaretskii wrote: > > Date: Sun, 14 Mar 2021 19:37:33 +0000 > > From: Alan Third > > Cc: Stefan Kangas , 47074@debbugs.gnu.org > > > > > The only question I have is what will happen if librsvg is older than > > > 2.48? > > > > It will work exactly as it works at the moment. The font size will be > > set to the librsvg default, which I think is 16 pixels, so the images > > will default to 16 pixels high. > > Then that's fine, I think. Thanks for doing this. Here's my final patch, then. Again Stefan's patch is required first. I'm somewhat tempted to add a :css image attribute for SVG files to allow the user to over-ride the default css, but I can do that later. -- Alan Third --Ph3uCkv/6bY85x+4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Set-CSS-for-SVG-files.patch" >From 50d2b5968f25ff0c1915db324669f56ff035416c Mon Sep 17 00:00:00 2001 From: Alan Third Date: Mon, 15 Mar 2021 21:30:43 +0000 Subject: [PATCH] Set CSS for SVG files * etc/images/ui/checkbox-checked.svg: * etc/images/ui/checkbox-mixed.svg: * etc/images/ui/checkbox.svg: * etc/images/ui/radio-checked.svg: * etc/images/ui/radio-mixed.svg: * etc/images/ui/radio.svg: Set height to match the font size. * src/dispextern.h (struct image): Add font details required for the CSS. * src/image.c (free_image): Free the font family string. (search_image_cache): (uncache_image): Make image caching understand the font details. (lookup_image): Handle the font details when generating the image and looking up the cache. (svg_css_length_to_pixels): Handle 'em' when we know the font size. (svg_load_image): Generate the CSS and apply it to the SVG. --- etc/images/ui/checkbox-checked.svg | 2 +- etc/images/ui/checkbox-mixed.svg | 2 +- etc/images/ui/checkbox.svg | 2 +- etc/images/ui/radio-checked.svg | 2 +- etc/images/ui/radio-mixed.svg | 2 +- etc/images/ui/radio.svg | 2 +- src/dispextern.h | 5 +++ src/image.c | 64 +++++++++++++++++++++++------- 8 files changed, 60 insertions(+), 21 deletions(-) diff --git a/etc/images/ui/checkbox-checked.svg b/etc/images/ui/checkbox-checked.svg index 6fefd5569e..b84dde1c3a 100644 --- a/etc/images/ui/checkbox-checked.svg +++ b/etc/images/ui/checkbox-checked.svg @@ -1,4 +1,4 @@ - + diff --git a/etc/images/ui/checkbox-mixed.svg b/etc/images/ui/checkbox-mixed.svg index 13bccaa7ce..647a0ccf9b 100644 --- a/etc/images/ui/checkbox-mixed.svg +++ b/etc/images/ui/checkbox-mixed.svg @@ -1,4 +1,4 @@ - + diff --git a/etc/images/ui/checkbox.svg b/etc/images/ui/checkbox.svg index 18cd25b43f..7cc1516220 100644 --- a/etc/images/ui/checkbox.svg +++ b/etc/images/ui/checkbox.svg @@ -1,3 +1,3 @@ - + diff --git a/etc/images/ui/radio-checked.svg b/etc/images/ui/radio-checked.svg index db711841cf..5354324c34 100644 --- a/etc/images/ui/radio-checked.svg +++ b/etc/images/ui/radio-checked.svg @@ -1,4 +1,4 @@ - + diff --git a/etc/images/ui/radio-mixed.svg b/etc/images/ui/radio-mixed.svg index 5a8be0cf65..e2a6fcae57 100644 --- a/etc/images/ui/radio-mixed.svg +++ b/etc/images/ui/radio-mixed.svg @@ -1,4 +1,4 @@ - + diff --git a/etc/images/ui/radio.svg b/etc/images/ui/radio.svg index 0d649c99cd..2593a78610 100644 --- a/etc/images/ui/radio.svg +++ b/etc/images/ui/radio.svg @@ -1,3 +1,3 @@ - + diff --git a/src/dispextern.h b/src/dispextern.h index f4e872644d..a2ebd04f23 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3066,6 +3066,11 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo) is created. */ unsigned long face_foreground, face_background; + /* Details of the font, only really relevant for types like SVG that + allow us to draw text. */ + int face_font_size; + char *face_font_family; + /* 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 b85418c690..3d504effa6 100644 --- a/src/image.c +++ b/src/image.c @@ -1207,6 +1207,7 @@ free_image (struct frame *f, struct image *img) /* Free resources, then free IMG. */ img->type->free_img (f, img); + xfree (img->face_font_family); xfree (img); } } @@ -1605,7 +1606,7 @@ make_image_cache (void) static struct image * search_image_cache (struct frame *f, Lisp_Object spec, EMACS_UINT hash, unsigned long foreground, unsigned long background, - bool ignore_colors) + int font_size, char *font_family, bool ignore_colors) { struct image *img; struct image_cache *c = FRAME_IMAGE_CACHE (f); @@ -1629,7 +1630,10 @@ search_image_cache (struct frame *f, Lisp_Object spec, EMACS_UINT hash, if (img->hash == hash && !NILP (Fequal (img->spec, spec)) && (ignore_colors || (img->face_foreground == foreground - && img->face_background == background))) + && img->face_background == background + && img->face_font_size == font_size + && (font_family + &&!strcmp (font_family, img->face_font_family))))) break; return img; } @@ -1647,7 +1651,7 @@ uncache_image (struct frame *f, Lisp_Object spec) can have multiple copies of an image with the same spec. We want to remove them all to ensure the user doesn't see an old version of the image when the face changes. */ - while ((img = search_image_cache (f, spec, hash, 0, 0, true))) + while ((img = search_image_cache (f, spec, hash, 0, 0, 0, NULL, true))) { free_image (f, img); /* As display glyphs may still be referring to the image ID, we @@ -2419,6 +2423,8 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id) struct face *face = FACE_FROM_ID (f, face_id); unsigned long foreground = FACE_COLOR_TO_PIXEL (face->foreground, f); unsigned long background = FACE_COLOR_TO_PIXEL (face->background, f); + int font_size = face->font->pixel_size; + char *font_family = SSDATA (face->lface[LFACE_FAMILY_INDEX]); /* F must be a window-system frame, and SPEC must be a valid image specification. */ @@ -2427,7 +2433,8 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id) /* Look up SPEC in the hash table of the image cache. */ hash = sxhash (spec); - img = search_image_cache (f, spec, hash, foreground, background, false); + img = search_image_cache (f, spec, hash, foreground, background, + font_size, font_family, false); if (img && img->load_failed_p) { free_image (f, img); @@ -2442,6 +2449,9 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id) cache_image (f, img); img->face_foreground = foreground; img->face_background = background; + img->face_font_size = font_size; + img->face_font_family = malloc (strlen (font_family) + 1); + strcpy (img->face_font_family, font_family); img->load_failed_p = ! img->type->load_img (f, img); /* If we can't load the image, and we don't have a width and @@ -9846,7 +9856,7 @@ svg_load (struct frame *f, struct image *img) #if LIBRSVG_CHECK_VERSION (2, 46, 0) static double -svg_css_length_to_pixels (RsvgLength length, double dpi) +svg_css_length_to_pixels (RsvgLength length, double dpi, int font_size) { double value = length.length; @@ -9874,9 +9884,16 @@ svg_css_length_to_pixels (RsvgLength length, double dpi) case RSVG_UNIT_IN: value *= dpi; break; +#if LIBRSVG_CHECK_VERSION (2, 48, 0) + /* We don't know exactly what font size is used on older librsvg + versions. */ + case RSVG_UNIT_EM: + value *= font_size; + break; +#endif default: - /* Probably one of em, ex, or %. We can't know what the pixel - value is without more information. */ + /* Probably ex or %. We can't know what the pixel value is + without more information. */ value = 0; } @@ -9931,6 +9948,16 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, FRAME_DISPLAY_INFO (f)->resy); + +#if LIBRSVG_CHECK_VERSION (2, 48, 0) + /* Generate the CSS for the SVG image. */ + char *css_spec = "svg{font-family:\"%s\";font-size:%4dpx}"; + int css_len = strlen (css_spec) + strlen (img->face_font_family); + char *css = xmalloc(css_len); + snprintf (css, css_len, css_spec, img->face_font_family, img->face_font_size); + rsvg_handle_set_stylesheet (rsvg_handle, css, strlen (css), NULL); +#endif + #else /* Make a handle to a new rsvg object. */ rsvg_handle = rsvg_handle_new (); @@ -9973,20 +10000,20 @@ svg_load_image (struct frame *f, struct image *img, char *contents, if (has_width && has_height) { /* Success! We can use these values directly. */ - viewbox_width = svg_css_length_to_pixels (iwidth, dpi); - viewbox_height = svg_css_length_to_pixels (iheight, dpi); + viewbox_width = svg_css_length_to_pixels (iwidth, dpi, img->face_font_size); + viewbox_height = svg_css_length_to_pixels (iheight, dpi, img->face_font_size); } else if (has_width && has_viewbox) { - viewbox_width = svg_css_length_to_pixels (iwidth, dpi); - viewbox_height = svg_css_length_to_pixels (iwidth, dpi) - * viewbox.width / viewbox.height; + viewbox_width = svg_css_length_to_pixels (iwidth, dpi, img->face_font_size); + viewbox_height = svg_css_length_to_pixels (iwidth, dpi, img->face_font_size) + * viewbox.height / viewbox.width; } else if (has_height && has_viewbox) { - viewbox_height = svg_css_length_to_pixels (iheight, dpi); - viewbox_width = svg_css_length_to_pixels (iheight, dpi) - * viewbox.height / viewbox.width; + viewbox_height = svg_css_length_to_pixels (iheight, dpi, img->face_font_size); + viewbox_width = svg_css_length_to_pixels (iheight, dpi, img->face_font_size) + * viewbox.width / viewbox.height; } else if (has_viewbox) { @@ -10107,6 +10134,10 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, FRAME_DISPLAY_INFO (f)->resy); + +#if LIBRSVG_CHECK_VERSION (2, 48, 0) + rsvg_handle_set_stylesheet (rsvg_handle, css, strlen (css), NULL); +#endif #else /* Make a handle to a new rsvg object. */ rsvg_handle = rsvg_handle_new (); @@ -10139,6 +10170,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, if (!pixbuf) goto rsvg_error; g_object_unref (rsvg_handle); xfree (wrapped_contents); + xfree (css); /* Extract some meta data from the svg handle. */ width = gdk_pixbuf_get_width (pixbuf); @@ -10210,6 +10242,8 @@ svg_load_image (struct frame *f, struct image *img, char *contents, g_object_unref (rsvg_handle); if (wrapped_contents) xfree (wrapped_contents); + if (css) + xfree (css); /* FIXME: Use error->message so the user knows what is the actual problem with the image. */ image_error ("Error parsing SVG image `%s'", img->spec); -- 2.29.2 --Ph3uCkv/6bY85x+4--