API for X/Y/width/height coords of things on page?

General discussions about Inkscape.
holloway
Posts: 3
Joined: Fri Oct 22, 2010 12:16 pm

API for X/Y/width/height coords of things on page?

Postby holloway » Wed Dec 01, 2010 12:42 pm

Hi, is there a way to retrieve the X/Y/width/height coordinates of individual items in an SVG page? E.g. something that will resolve nested transformation matrices, font sizes and kerning and other font metrics, or any other layout aspects of the format. Parsing SVG files directly won't reveal this information unless I do a lot of math, and I was hoping that Inkscape has this available already somewhere.

I guess I'm looking for a renderer with an API where I can query where it's putting things on the page. Does such a thing exist?

User avatar
prkos
Posts: 1625
Joined: Tue Nov 06, 2007 8:45 am
Location: Croatia

Re: API for X/Y/width/height coords of things on page?

Postby prkos » Wed Dec 01, 2010 9:54 pm

just hand over the chocolate and nobody gets hurt

Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download

holloway
Posts: 3
Joined: Fri Oct 22, 2010 12:16 pm

Re: API for X/Y/width/height coords of things on page?

Postby holloway » Thu Dec 02, 2010 6:19 am

That looks very close to what I was after, thanks. It's definitely much better than parsing the file manually and it'll give me an X/Y reference point for my calculations :)

One remaining issue is that the tspan element can have letter kerning. Eg.

<tspan x="0 1 2 50" y="0" id="tspan34">ABCD</tspan>

(the letter "D" is offset by 50 units)

And parent elements may have their own transformation matrices that distort the position of "D" yet further. Is there a way to get X/Y coordinates of each letter? (even if it means tweaking the SVG slightly)


Return to “General Discussions”