bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

classic Classic list List threaded Threaded
46 messages Options
123
Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Stefan Kangas
Severity: wishlist

In M-x customize, we use the etc/images/{un,}checked.xpm and other
icons. These images do not scale when you increase the font, and (this
is subjective but) generally don't look too good.

I think we could get better result if we used Unicode characters like:

- ☑ checked
- ☐ unchecked
- ▼ or ▾ down triangle
- ▶ or ▸ right triangle

I'm less sure about the look of these but they do exist:

- ⬤ or ◉ or 🔘 radio button selected (the last one was added to Unicode
  in 2015 and gives the hex square here)
- ◯ radio button unselected

Obviously how these look depends on the fonts you have installed.  On my
machine, the "Fira Code" font is used, which makes them look very good.
(They also obviously scale when increasing the font size.)

Perhaps we could prefer Unicode icons if they are available, and fall
back on icons if not.  It seems like we can use `char-displayable-p' to
see if there is any font that can display that codepoint.

If we don't think that will produce consistently improved results, we
could also just add a new option to use Unicode characters.

Thoughts?



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Lars Ingebrigtsen
Stefan Kangas <[hidden email]> writes:

> I'm less sure about the look of these but they do exist:
>
> - ⬤ or ◉ or 🔘 radio button selected (the last one was added to Unicode
>   in 2015 and gives the hex square here)
> - ◯ radio button unselected

These look like this here:



> If we don't think that will produce consistently improved results, we
> could also just add a new option to use Unicode characters.
>
> Thoughts?

I think it's a good idea.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

attachment0 (22K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Stefan Kangas
Lars Ingebrigtsen <[hidden email]> writes:

> Stefan Kangas <[hidden email]> writes:
>
>> I'm less sure about the look of these but they do exist:
>>
>> - ⬤ or ◉ or 🔘 radio button selected (the last one was added to Unicode
>>   in 2015 and gives the hex square here)
>> - ◯ radio button unselected
>
> These look like this here:

◉ seems to pair well with ◯ here too.  So perhaps that could be a
reasonable choice for the radio buttons.

The 🔘 character is fancy, but I don't know what to use for the
non-selected version (and it doesn't display here, so...).



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
In reply to this post by Stefan Kangas
> From: Stefan Kangas <[hidden email]>
> Date: Thu, 11 Mar 2021 10:51:19 -0600
>
> Obviously how these look depends on the fonts you have installed.  On my
> machine, the "Fira Code" font is used, which makes them look very good.

Exactly, so depending on a font to produce good results is not
necessarily a good idea.

> Perhaps we could prefer Unicode icons if they are available, and fall
> back on icons if not.  It seems like we can use `char-displayable-p' to
> see if there is any font that can display that codepoint.

char-displayable-p is expensive, though.  And it does nothing against
the not-so-pretty fonts, of course

So I generally find the idea of using characters for this purpose
problematic; we've seen these problems in other places in Emacs.  Why
not use SVG images instead?



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
In reply to this post by Lars Ingebrigtsen
> From: Lars Ingebrigtsen <[hidden email]>
> Date: Thu, 11 Mar 2021 18:01:06 +0100
> Cc: [hidden email]
>
> > - ⬤ or ◉ or 🔘 radio button selected (the last one was added to Unicode
> >   in 2015 and gives the hex square here)
> > - ◯ radio button unselected
>
> These look like this here:

With Symbola as the font (which is what we have by default), the
result is much worse than images.



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Stefan Kangas
Eli Zaretskii <[hidden email]> writes:

> With Symbola as the font (which is what we have by default), the
> result is much worse than images.

:-/

So I guess using Unicode would need to be optional.



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Stefan Kangas
In reply to this post by Eli Zaretskii
Eli Zaretskii <[hidden email]> writes:

> char-displayable-p is expensive, though.

Could we perhaps cache the results if it is prohibitively slow?

> And it does nothing against the not-so-pretty fonts, of course

This is the bigger problem indeed.

> So I generally find the idea of using characters for this purpose
> problematic; we've seen these problems in other places in Emacs.  Why
> not use SVG images instead?

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?



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Lars Ingebrigtsen
Stefan Kangas <[hidden email]> writes:

> 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?

`create-image' does scale the images with the text (by default -- but
perhaps not on all platforms) -- it looks at how big the default font is
and sets :scaling.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
In reply to this post by Stefan Kangas
> From: Stefan Kangas <[hidden email]>
> Date: Thu, 11 Mar 2021 11:51:45 -0600
> Cc: [hidden email]
>
> Eli Zaretskii <[hidden email]> writes:
>
> > char-displayable-p is expensive, though.
>
> Could we perhaps cache the results if it is prohibitively slow?

It isn't prohibitively slow, just slow.

> > So I generally find the idea of using characters for this purpose
> > problematic; we've seen these problems in other places in Emacs.  Why
> > not use SVG images instead?
>
> 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.)



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
In reply to this post by Lars Ingebrigtsen
> From: Lars Ingebrigtsen <[hidden email]>
> Cc: Eli Zaretskii <[hidden email]>,  [hidden email]
> Date: Thu, 11 Mar 2021 19:03:48 +0100
>
> Stefan Kangas <[hidden email]> writes:
>
> > 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?
>
> `create-image' does scale the images with the text (by default -- but
> perhaps not on all platforms) -- it looks at how big the default font is
> and sets :scaling.

But that doesn't happen in Custom buffers when one enlarges the text
scale, does it?



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Stefan Kangas
Lars Ingebrigtsen <[hidden email]> writes:

> Oh, I wasn't thinking about `C-x +' and friends.  No, the images are not
> re-scaled by that command.  (Of course, that's something we could decide
> to do, though.)

I think we should do precisely that.  Perhaps one should be able to turn
it off, as it might not always make sense (e.g. in eww buffers?).

How would we go about implementing something like that?  Do we need to
scan the buffer for any images and re-insert them when we change the
font size, or can we just add an image attribute or something?



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Lars Ingebrigtsen
Stefan Kangas <[hidden email]> writes:

> Lars Ingebrigtsen <[hidden email]> writes:
>
>> Oh, I wasn't thinking about `C-x +' and friends.  No, the images are not
>> re-scaled by that command.  (Of course, that's something we could decide
>> to do, though.)
>
> I think we should do precisely that.  Perhaps one should be able to turn
> it off, as it might not always make sense (e.g. in eww buffers?).

I think it would make sense in eww buffers, too...  probably.  If there
are buffers where this shouldn't happen, we can add a mechanism for
that, though.

> How would we go about implementing something like that?  Do we need to
> scan the buffer for any images and re-insert them when we change the
> font size, or can we just add an image attribute or something?

I think just altering the :scale image attribute would probably do the
trick...  but we can't destructively modify the image objects, I guess,
so re-inserting them is probably necessary...

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Lars Ingebrigtsen
Stefan Kangas <[hidden email]> writes:

>> I think just altering the :scale image attribute would probably do the
>> trick...  but we can't destructively modify the image objects, I guess,
>> so re-inserting them is probably necessary...
>
> So basically `text-scale-adjust' should search the buffer for any images
> and re-insert them with the new size?

Yes, I think so.  I haven't actually tried this, but I think it should
be possible...

If the images are large, then this may be slow, but it shouldn't
generate a lot of garbage (since the image data itself in (in case of a
"data" image) should be shared, still.  I think it's worth a try, at
least.  If it turns out to be very slow, then we can start thinking
about mechanisms for marking specific (smaller) icons for rescaling,
while leaving the rest of the images alone.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
In reply to this post by Eli Zaretskii
> Date: Thu, 11 Mar 2021 23:49:54 +0000
> From: Alan Third <[hidden email]>
> Cc: Stefan Kangas <[hidden email]>, [hidden email]
>
> 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.

The font details can be accessed from Lisp as well, if that's more
convenient.

> Alas it doesn't resize the image as you scale with C-x C-+.

Why not? what is preventing that?

> Perhaps there is some way to mark certain SVGs as part of the UI and
> regenerate them?
>
> Yet another alternative is to define a different text property (or
> whatever) that only draws SVGs, but on the fly so there's no caching
> and we can put them anywhere in the frame. But that might not be a
> good idea.

if these two paragraphs explain why the images currently don't resize
with the text scale, I don't think I follow the reasoning.  Please
elaborate.



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Alan Third
In reply to this post by Eli Zaretskii
On Fri, Mar 12, 2021 at 01:12:02AM +0100, Lars Ingebrigtsen wrote:

> Alan Third <[hidden email]> writes:
>
> > In fact, it's possible to build an SVG within Emacs that contains the
> > correct font details that will display at the correct size.
> >
> > Something like this:
> >
> > (require 'svg)
> > (let* ((scale (cadr (assoc :height (assoc 'default face-remapping-alist))))
> >        (height (* (/ (face-attribute 'default :height) 10) (if scale scale 1)))
> >        (family (face-attribute 'default :family))
> >        (img (svg-create height height
> > :font-size height
> > :font-family family)))
> >   (svg-circle img "0.5em" "0.5em" "0.5em")
> >   (insert "XX")
> >   (insert-image (svg-image img :ascent 'center))
> >   (insert "XX"))
>
> Hm...  Isn't that basically what `image-compute-scaling-factor' does
> already, only on the `create-image' level?

Sort of, although this should produce an image that's the exact same
size as the text, which I don't think we can duplicate without making
image-compute-scaling-factor resize much more aggressively. Nor would
we want to, generally.

--
Alan Third



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Alan Third
In reply to this post by Eli Zaretskii
On Fri, Mar 12, 2021 at 09:27:01AM +0200, Eli Zaretskii wrote:

> > Date: Thu, 11 Mar 2021 23:49:54 +0000
> > From: Alan Third <[hidden email]>
> > Cc: Stefan Kangas <[hidden email]>, [hidden email]
> >
> > 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.
>
> The font details can be accessed from Lisp as well, if that's more
> convenient.

It depends. Doing it at the C level means it Just Works for all SVGs.
That is if you put unstyled text into any SVG it would appear with the
size and font of the surrounding face rather than whatever the librsvg
default setting is.

Doing it in lisp would require a little more care.

> > Alas it doesn't resize the image as you scale with C-x C-+.
>
> Why not? what is preventing that?

Simply that we're inserting an image and to change it we'd have to
regenerate it. If it were being done as part of a mode (this bug
report is about customize, so in there I guess?) it should be possible
to make it fix it.

> > Perhaps there is some way to mark certain SVGs as part of the UI and
> > regenerate them?
> >
> > Yet another alternative is to define a different text property (or
> > whatever) that only draws SVGs, but on the fly so there's no caching
> > and we can put them anywhere in the frame. But that might not be a
> > good idea.
>
> if these two paragraphs explain why the images currently don't resize
> with the text scale, I don't think I follow the reasoning.  Please
> elaborate.

No, I was just listing off the different ways I could think of to make
SVGs appear more coupled to the text.
--
Alan Third



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Alan Third
On Fri, Mar 12, 2021 at 08:37:40PM +0200, Eli Zaretskii wrote:

> > Date: Fri, 12 Mar 2021 18:25:34 +0000
> > From: Alan Third <[hidden email]>
> > Cc: [hidden email], [hidden email]
> >
> > > > Alas it doesn't resize the image as you scale with C-x C-+.
> > >
> > > Why not? what is preventing that?
> >
> > Simply that we're inserting an image and to change it we'd have to
> > regenerate it.
>
> Even if some attributes of the image spec reference variables?

Yes, it's inserted into the buffer as a simple list, I believe, so
changing the variables doesn't affect the existing image spec.
--
Alan Third



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
> Date: Fri, 12 Mar 2021 18:43:44 +0000
> From: Alan Third <[hidden email]>
> Cc: [hidden email], [hidden email]
>
> > > Simply that we're inserting an image and to change it we'd have to
> > > regenerate it.
> >
> > Even if some attributes of the image spec reference variables?
>
> Yes, it's inserted into the buffer as a simple list, I believe, so
> changing the variables doesn't affect the existing image spec.

We could change that, though.  Like supporting :eval in the spec or
somesuch.



Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Stefan Kangas
In reply to this post by Eli Zaretskii
Alan Third <[hidden email]> 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?

0001-Add-SVG-icons-for-customize-buffers.patch (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#47074: Replace XPM icons with Unicode codepoints in customize/widgets

Eli Zaretskii
> From: Stefan Kangas <[hidden email]>
> Date: Fri, 12 Mar 2021 20:44:55 -0600
> Cc: [hidden email]
>
> @@ -2385,9 +2385,9 @@ 'checkbox
>    ;; We could probably do the same job as the images using single
>    ;; space characters in a boxed face with a stretch specification to
>    ;; make them square.
> -  :on-glyph "checked"
> +  :on-glyph "ui/checkbox-checked"
>    :off "[ ]"
> -  :off-glyph "unchecked"
> +  :off-glyph "ui/checkbox"
>    :help-echo "Toggle this item."
>    :action 'widget-checkbox-action)

How will this work in an Emacs session that doesn't support SVG?  The
images/ui/ directory has only SVG images.  Am I missing something?



123