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: Sun, 14 Mar 2021 13:46:59 +0000 Message-ID: References: <83a6r9mwgk.fsf@gnu.org> <8335x1mpdk.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="26lDpBJ9jA7vWb3u" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4771"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 47074@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 14 14:48:56 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 1lLR71-00017x-NU for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Mar 2021 14:48:55 +0100 Original-Received: from localhost ([::1]:42000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLR70-00019w-F8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Mar 2021 09:48:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLR6A-0000e4-2H for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 09:48:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49821) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLR69-0005gv-R8 for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 09:48:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lLR69-0005Ef-OB for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 09:48: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: Sun, 14 Mar 2021 13:48: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.161572963320052 (code B ref 47074); Sun, 14 Mar 2021 13:48:01 +0000 Original-Received: (at 47074) by debbugs.gnu.org; 14 Mar 2021 13:47:13 +0000 Original-Received: from localhost ([127.0.0.1]:33134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLR5M-0005DL-B1 for submit@debbugs.gnu.org; Sun, 14 Mar 2021 09:47:12 -0400 Original-Received: from outbound.soverin.net ([116.202.65.218]:32961) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLR5K-0005D6-V7 for 47074@debbugs.gnu.org; Sun, 14 Mar 2021 09:47:11 -0400 Original-Received: from smtp.soverin.net (unknown [10.10.3.24]) (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 36835600D6; Sun, 14 Mar 2021 13:47:05 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.138]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1615729624; bh=BR9xlL+tqQaIDLHDea0fCy++9kIrkhGkpoS+kAViv1A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Xkh62Hja0G/ZXv2pqjbMA7VbvdSRsZLA0+tGTdlxDvDzVUEPw6uDyqNzhWz+QQaeD WsdQ0nhB0ByYirXGA4TQuLR66Jh5MmUIz+dtSX9V1WQMljpu9vxWzGJhIEdiTw92uI fEEU6X8W+IHD1L/g6RYcjLlNOBoEOgwhJMAGEVNdY80Tlr2mFFDaRT8Z/LDDYCm8wa lLEM4QLyh5Z594+nUfCBdQNvF0jJQhaGTo2h5yi7XwIswbix7a/2FmAmV0hIbhP7Kl uE0nGI2R92EepNPsqRUh6J7b+lG0Z1LIqydW/BphFuDrV5s9BgHFRqTmDEhH161e/Y 1ZxXW3Jyhegcg== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 367DC202AF5C27; Sun, 14 Mar 2021 13:46:59 +0000 (GMT) Mail-Followup-To: Alan Third , Stefan Kangas , Eli Zaretskii , 47074@debbugs.gnu.org Content-Disposition: inline In-Reply-To: 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:202369 Archived-At: --26lDpBJ9jA7vWb3u Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 12, 2021 at 08:44:55PM -0600, Stefan Kangas wrote: > Alan Third writes: > > > On Thu, Mar 11, 2021 at 10:01:11PM +0200, Eli Zaretskii wrote: > >> > > >> > I think SVG is obviously much preferable to XPM, but there is still the > >> > problem that the images don't scale with the text. Do we have a general > >> > solution to that? If not, should we have one? > >> > >> With SVG, I believe we could. (We can scale other kinds of images as > >> well, but they don't look well when enlarged, AFAIK.) > > > > I've been thinking about this, and assuming we can extract the font > > name and size from the face in C then we can create a default CSS > > stylesheet that should make 1em in an SVG equivalent to the actual > > Emacs font height. > > I took a stab at adding SVG icons, as found in the GNOME Adwaita Icon > Theme. I had to scrub some color details from the SVG files by hand, > but they now seem to automagically adapt to the :foreground and > :background of the current face (but I could be wrong about that as I > don't understand how this is supposed to work). > > How would a patch like the attached relate to the changes you propose, > Alan? I've attached a proof of concept patch for what I'm talking about. Stefan's patch must be applied first and it requires at least librsvg 2.48 and might foul up if create-image starts automatically changing scale (it's fine here). Does this look like the sort of behaviour you were thinking of, in terms of icon sizing? -- Alan Third --26lDpBJ9jA7vWb3u Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Autoresizing-SVG-files-PoC.patch" >From 27e284644ae30f767d04847fc45accb4f18f33ab Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sun, 14 Mar 2021 13:41:25 +0000 Subject: [PATCH] Autoresizing SVG files PoC Requires librsvg 2.48. --- 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 | 4 ++++ src/image.c | 25 +++++++++++++++++++------ 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/etc/images/ui/checkbox-checked.svg b/etc/images/ui/checkbox-checked.svg index 6fefd5569e..559c24af72 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..4dc71c3764 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..28e350c46b 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..e7a22ccf3f 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..bdd76f85a0 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..f076ad78d4 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..3e801672ec 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3066,6 +3066,10 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo) is created. */ unsigned long face_foreground, face_background; + /* Size of the font, only really relevant for types like SVG that + allow us to draw text. */ + int face_font_size; + /* 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..4810329537 100644 --- a/src/image.c +++ b/src/image.c @@ -1605,7 +1605,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, bool ignore_colors) { struct image *img; struct image_cache *c = FRAME_IMAGE_CACHE (f); @@ -1629,7 +1629,8 @@ 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))) break; return img; } @@ -1647,7 +1648,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, true))) { free_image (f, img); /* As display glyphs may still be referring to the image ID, we @@ -2419,6 +2420,7 @@ 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->height; /* F must be a window-system frame, and SPEC must be a valid image specification. */ @@ -2427,7 +2429,7 @@ 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, false); if (img && img->load_failed_p) { free_image (f, img); @@ -2442,6 +2444,7 @@ 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->load_failed_p = ! img->type->load_img (f, img); /* If we can't load the image, and we don't have a width and @@ -9912,6 +9915,12 @@ svg_load_image (struct frame *f, struct image *img, char *contents, g_type_init (); #endif + /* Generate the CSS for the SVG image. */ + char *css_spec = "svg{font-size:%4dpx}"; + char *css = malloc(strlen (css_spec + 1)); + sprintf (css, css_spec, img->face_font_size); + fprintf (stderr, "%s\n\n", css); + /* Parse the unmodified SVG data so we can get its initial size. */ #if LIBRSVG_CHECK_VERSION (2, 32, 0) @@ -9929,6 +9938,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, /* Check rsvg_handle too, to avoid librsvg 2.40.13 bug (Bug#36773#26). */ if (!rsvg_handle || err) goto rsvg_error; + rsvg_handle_set_stylesheet (rsvg_handle, css, strlen (css), NULL); rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, FRAME_DISPLAY_INFO (f)->resy); #else @@ -10054,7 +10064,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, const char *wrapper = "" "" @@ -10080,7 +10090,8 @@ svg_load_image (struct frame *f, struct image *img, char *contents, if (!wrapped_contents || buffer_size <= snprintf (wrapped_contents, buffer_size, wrapper, - foreground & 0xFFFFFF, width, height, + foreground & 0xFFFFFF, + width, height, viewbox_width, viewbox_height, background & 0xFFFFFF, SSDATA (encoded_contents))) @@ -10088,6 +10099,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, wrapped_size = strlen (wrapped_contents); } + fprintf (stderr, "%s\n\n", wrapped_contents); /* Now we parse the wrapped version. */ @@ -10105,6 +10117,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, /* Check rsvg_handle too, to avoid librsvg 2.40.13 bug (Bug#36773#26). */ if (!rsvg_handle || err) goto rsvg_error; + rsvg_handle_set_stylesheet (rsvg_handle, css, strlen (css), NULL); rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, FRAME_DISPLAY_INFO (f)->resy); #else -- 2.29.2 --26lDpBJ9jA7vWb3u--