I have tspan element with some text in it. I specified some font-size for it as well. In addition I have parent’s box size, i.e. width and height. So now I’d like my text to fit the box with the specified width and height.
One of the options I have is manually calculate string width and height (but it became more complicated in case of different fonts and browsers).
So is there any other way in SVG to resize tspan to necessary sizes? Please note that I want text font size to be changed properly, i.e. so text will be displayed in max font size and any single char from it will be visible.
Well, I’ve came up with the following solution – have absolutely positioned
divelement outside of visible area. Apply all fonts and other-related styles (except font size) fromtspanto thatdiv, put text into thediv. Next try different sizes (you can use binary search for better performance) and measuredivsize. Once max font size found – apply it along with the text totspan.