I write a python script in order to generate a SVG file. This SVG file uses a web font ( imported from google webfonts via CSS ) to render my texts nicely. Everything is fine except I need to know the size (in pixel) of a sentence before putting it in my SVG file.
As I started learning python few days ago, I don’t know if this kind of stuff is possible. Google helped me to find the existence of the ImageFont python module (from the Python Imaging Library) but it seems ImageFont needs to load font file from a local path in order to compute character size.
Is there any chance a way to compute character size on a web font exists ?
Thank you for your help.
You can achieve it on the client side with javascript and the SVG DOM.
First step : create a text element and compute its length with the getComputedTextLength() method ( http://www.w3.org/TR/SVG11/text.html#InterfaceSVGTextContentElement )
Then compute the path length with the getTotalLength() method ( http://www.w3.org/TR/SVG11/paths.html#InterfaceSVGPathElement )
And you can compute how many times you can put your text before it is truncated.