[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mechanism to scale SVG images when default face height changes?
From: |
Alan Third |
Subject: |
Re: Mechanism to scale SVG images when default face height changes? |
Date: |
Mon, 18 Sep 2023 20:37:23 +0100 |
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,
> this isn't documented but indeed it scales.
Ems are only available for images, afaik:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Image-Descriptors.html
> But this doesn't seem to work, I suppose px is not a unit?
>
> ```elisp
> #("" 0 1
> (face all-the-icons-lpurple font-lock-face all-the-icons-lpurple
> fontified t display
> (image :type svg :data "<svg viewBox=\"0 0 512 512\" width=\"512\"
> height=\"512\"> <path d=\"...snip...\"></path></svg>" :scale 1
> :transform-smoothing t :width (- (1 . em) (1 . px)) :ascent center :margin
> 1)
> front-sticky nil rear-nonsticky t))
> ```
Hmm, yeah it only supports ems in that format, and it's not clever
enough to be able to do arithmetic on it. The conversion from ems to
pixels is done when the image is to be displayed.
> I like this approach a lot, but I do need pixel precision calculated on
> demand because I need to add a 1px margin between icons. If I don't
> subtract 2 px back from the dimensions, the icons will be wider than a
> character.
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.
--
Alan Third