In the drawing below I have e.g., a rectangle.
In the GUI, Inkscape says the rectangle is at Y position 0, but in the XML for that element it says 873. Why is that and how do I get the “real” number?
Background: When exporting the image (scripted), I want to add 10 pixels border on all four sides. I thought I could just look for the largest / smallest coordinates in XML and add the 10 pixels for border, but I end up exporting an all white background instead of the image. Working with the XML comes natural here because I get other (meta) information from that.
I can query the image origin with
inkscape -Yand the image dimensions with
inkscape -W. That also gets me the numbers from the GUI. Exporting with these values works. However, that requires forking a new Inkscape process 4 times per image, and hence slows the whole export down. (Lots of images on old hardware.)
This is Inkscape 0.91 on Linux, in case that matters.
In your example the difference in width (236.185 vs 234.869) and height (180.000 vs 178.6805) is due to the border width of the rectangle, which is included in Inkscape W and H and not included in SVG width and height.
For example, with a border stroke of 1 px:
The same rectangle without a border:
Note that the border is centered on the path. In my example we have:
Inkscape W = SVG width (199px) + half stroke left (0.5px) + half stroke right (0.5px) = 200 px
Be aware that the Y coordinate in Inkscape has the zero on the bottom of the document, while in SVG the zero is on the top of the document.
Y = 0 in Inkscape means an object at the bottom of the document:
Y = 0 in SVG means an object at the top of the document:
This means that your “real” number is something like:
Y coordinate in SVG (px) = Page height (px) – Y coordinate in Inkscape (px) – Object and borders height (px)
(Note that the inversion of the Y axis will be fixed at some time in the future according to this issue.)