I am using python to generate an SVG with text that can vary, and I'd like to put a translucent rectangle behind it to guarantee some contrast when it is overlayed on another graphical element later on.
Unfortunately, I do not know how to predict the pixel extents of a specific string of text in SVG. I can choose what font I use (but I don't think monospace will be acceptable) and what font size I'm using.
How would I go about using python to predict the extents of the SVG text so I can generate an appropriately sized rectangle?