How can I get a text bounding box in a python script?

Hello,
I try to write a python script that help drawing diagrams (i.e. syntax diagrams). A node in this typ of diagram, is a rectangle with rounded edges and a centered text caption in it. In the script, I need the bounding box of the text, for the calculation of the correct node rectangle size, to hold the whole text in it. But how can I get the bounding box? Is there somebody that can point me to a solution?
Best regards, Bernd

On Mon, 29 Dec 2008 22:58:01 +0100 Bernd D. <Feldrain@...889...> wrote:
Hello,
I try to write a python script that help drawing diagrams (i.e. syntax diagrams). A node in this typ of diagram, is a rectangle with rounded edges and a centered text caption in it. In the script, I need the bounding box of the text, for the calculation of the correct node rectangle size, to hold the whole text in it. But how can I get the bounding box? Is there somebody that can point me to a solution?
I think you need to invoke inkscape a second time, using subprocess.Popen or similar, and grab the output from inkscape with the following flags:
inkscape --without-gui --query-all path/to/myfile.svg
you may need to right the DOM to a file first.
--query-all dumps id,x,y,width,height for every object in the file. If you only want info. on a single object you can use some of the other --query-??? flags - see inkscape --help
Cheers -Terry
Best regards, Bernd
Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel

check out the code in the file : \Inkscape\share\extensions\perspective.py, in particular the line that says: f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:]
this was meant to retrieve the bounding box of a path, but it might work on text as well.
participants (3)
-
Alvin Penner
-
Bernd D.
-
Terry Brown