How to manually calculate coordinates of an object?

Discuss SVG code, accessible via the XML Editor.
peterkz
Posts: 1
Joined: Wed Aug 10, 2011 5:07 pm

How to manually calculate coordinates of an object?

Postby peterkz » Wed Aug 10, 2011 5:20 pm

Hi! I want to calculate the "real" coordinates of an object in an SVG XML file saved from Inkscape. I have a hard time figuring out the coordinate system in the generated XML compared to the system visible inside Inkscape.

An example:

My SVG starts like this:

Code: Select all

<svg
   [snip]
   width="417.09067"
   viewBox="-3364 -3942 4967.9354 4195.7246"
   height="352.04761"
   preserveAspectRatio="xMidYMid meet"


One of the objects in the SVG looks like this:

Code: Select all

<text
     id="text110124"
     y="-1642.8667"
     x="-1065.8459">My text</text>


The text object is not contained inside any element with a transform. If I run Inkscape from the command line I can query the "real" coordinates (those displayed inside Inkscape) like this:

$ /Applications/Inkscape.app/Contents/Resources/bin/inkscape -X --query-id=text110124 myfile.svg

And get the result: 185.9494 for the X position of the text element and 190.04316 for the Y position.

How can I manually calculate this value from the coordinate data in the SVG?

User avatar
LiquidAsh
Posts: 71
Joined: Fri Apr 22, 2011 11:35 pm
Contact:

Re: How to manually calculate coordinates of an object?

Postby LiquidAsh » Mon Aug 15, 2011 11:00 am

After working through some similar problems (http://www.inkscapeforum.com/viewtopic.php?f=16&t=9817), I'm starting to find this an interesting puzzle. I think I have a general formula, but unfortunately believe that you need a bit more information to calculate the answer exactly. If you zoom in on the text in inkscape, you can see the little square box in the lower left hand corner of your text (outside of the bounding box surrounding your text). I believe this box represents the position that inkscape displays, and that the position in your svg file is for the corner of the lower left corner of the bounding box(?). The offset here seems to depend on your font properties, as well as the characters used in your text. I'm not sure how to get this offset.

I think you can get close however with some help from: http://www.w3.org/TR/SVG/coords.html


Return to “SVG / XML Code”