haji-ali · 2022-09-26 08:58
I am trying to create an svg image out of a single character (to be able to be able to rotate it). However, I can't quite get the svg to perfectly replicate the text. Consider this code
(let* ((char "A")
(height (window-font-height))
(svg (svg-create (window-font-width) height)))
(svg-text svg char :x 0 :y (/ (window-font-height) 2))
(insert-image (svg-image svg))
(insert "\n")
(insert char)
(insert "\n"))
I expect this code to produce a two identical `A` characters: one as an image and one as text. The result instead is as follows:
The image `A` is cut from the top and there is some padding which leads to different line height compared to text `A`
​
https://preview.redd.it/jx1tdzvx36q91.png?width=47&format=png&auto=webp&s=21b4a69876be1ac2c6fa10f1007b88737a9285f7
Am I doing something wrong? or is the result I am after can't be achieved?
itistheblurstoftimes · 2022-09-26 13:48
I messed around with the values for height and the :y offset and got it closer to matching entered text but could not get it to match. There are more arguments you can use with svg-text that might help (e.g., :font-size (but I don't know what they all are)).
haji-ali · 2022-09-26 13:57
Thanks. I also tried to mess around with these values with no luck. I could change the size to make everything fit, but I really just want the same size as normal text (ideally, the image should be indistinguishable). There must be something that I don't understand about the extra padding at the bottom.
itistheblurstoftimes · 2022-09-26 14:06
Every time someone has produced an SVG package (e.g., orgmode display tweaks, mode lines) I have had problems with displaying text. I fear that even if there is a solution it is not going to be very portable.
Nicolas-Rougier · 2022-09-26 14:12
You have to take ascent into account. Have a look at https://github.com/rougier/svg-lib/blob/master/svg-lib.el#L274
[deleted] · 2022-09-26 15:05
[deleted]
haji-ali · 2022-09-26 20:32
Thanks! This seems to be the issue. Though on my system, I had to divide the ascent of `font-info` by 10.
Also, any value for the `y` coordinate of the text seems to break when the text is scaled.
itistheblurstoftimes · 2022-09-28 03:23
Can you post the code? I am curious to get this working myself.
Nicolas-Rougier · 2022-09-28 10:04
Scaling (inside or outside emacs) is not so simple. the svg-lib issues are full of test to make it right but there's always a corner case where it breaks.