emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mechanism to scale SVG images when default face height changes?


From: Jimmy Yuen Ho Wong
Subject: Re: Mechanism to scale SVG images when default face height changes?
Date: Mon, 18 Sep 2023 22:04:17 +0100


On Mon, Sep 18, 2023 at 9:53 PM Alan Third <alan@idiocy.org> wrote:
On Mon, Sep 18, 2023 at 08:55:55PM +0100, Jimmy Yuen Ho Wong wrote:
> On Mon, Sep 18, 2023 at 8:37 PM Alan Third <alan@idiocy.org> wrote:
>
> > On Mon, Sep 18, 2023 at 08:10:59PM +0100, Jimmy Yuen Ho Wong wrote:
> > > Ah, I was looking at
> > >
> > https://www.gnu.org/software/emacs/manual/html_node/elisp/Pixel-Specification.html
> > ,
<snip>
> >
> > I suppose you could calculate the number of ems required by
> > doing something like...
> >
> >       ((/ (- font-px-size 1) font-px-size) . 'em)
> >
> > But while that would scale on demand, it wouldn't scale properly
> > because the calculation is done before the user changes the font size.
> >
> > I can't think of any way round it, or even any practical way to extend
> > the current mechanism.
> >
> >
> Sad face :(. I suppose what I'm really looking for is to extend the pixel
> specification mini language to support something like CSS' calc()
> <https://developer.mozilla.org/en-US/docs/Web/CSS/calc> function, where it
> can do arithmetic on both relative and absolute units.
>
> Is that possible?

I didn't actually know about the pixel specification language before
now. It seems to me like it would make sense to teach the image code
to understand it too and add ems to it, but since I know nothing about
it I can't say if that's practical or not.

> For my specific purpose, having `:margin` to support
> floating point em will also suffice, but that doesn't seem to work at the
> moment.

Indeed, this would actually be quite simple, but it won't help you now
as it won't be available until Emacs 30.

All I can suggest for compatibility with current versions of Emacs is
to wrap the SVG's within other SVGs. We do this internally in Emacs to
implement vector scaling and you could probably do something similar,
although I'm not sure exactly how much control you could get from it.

For example, you can do something like:

<svg xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 width="1em" height="1em" preserveAspectRatio="none">
  <xi:include href="" encoded SVG data>">
  </xi:include>
</svg>

It should be possible to scale down the embedded image to leave a gap
around it, but I'd have to go and investigate how to do it.

I recommend base64 encoding the SVG data as shown above, because
directly embedding the SVG text can be problematic unless it's very
simple.
--
Alan Third

Thank you! I'll report back once I've played around with SVG wrappers.

Thanks

reply via email to

[Prev in Thread] Current Thread [Next in Thread]