Discussion:
[elm-discuss] Sizing svg text to fit a box
Ben Burdette
2015-11-24 22:31:02 UTC
Permalink
I'm using svg to draw some text, and I'd like it to be as large as
possible, but still fit inside a box. This stackoverflow illustrates the
idea for a single line of text.

http://stackoverflow.com/questions/15430189/pure-svg-way-to-fit-text-to-a-box

The solution there seems to be to query SVG to get a bounding box for the
text, then use the result of that to estimate the appropriate font size and
text location. This approach doesn't seem to be appropriate for elm though,
its not declarative. There doesn't seem to be a getBBox() function in the
svg lib either.

Any ideas on this? Right now going to just go with guessing from the
string length.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jan Hrček
2017-08-06 09:14:35 UTC
Permalink
I know that this answer is coming late, but I had similar problem that I
needed to solve in my graph editor app. I wanted to draw boxes around SVG
text. I used ports to obtain the bounding box. Here's the gist of my
solution as github repo [2] and I also posted this in ellie [2] in case
anyone finds this useful.

I'd welcome suggestions for improvement if anyone solved similar problem in
some more elegant way.

[1] https://github.com/jhrcek/svg-bbox
[2] https://ellie-app.com/3WDzNWnMkYXa1/1
Post by Ben Burdette
I'm using svg to draw some text, and I'd like it to be as large as
possible, but still fit inside a box. This stackoverflow illustrates the
idea for a single line of text.
http://stackoverflow.com/questions/15430189/pure-svg-way-to-fit-text-to-a-box
The solution there seems to be to query SVG to get a bounding box for the
text, then use the result of that to estimate the appropriate font size and
text location. This approach doesn't seem to be appropriate for elm though,
its not declarative. There doesn't seem to be a getBBox() function in the
svg lib either.
Any ideas on this? Right now going to just go with guessing from the
string length.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...