Inkscape Coordinate System Question

Discuss SVG code, accessible via the XML Editor.
Posts: 4
Joined: Wed Jul 06, 2011 4:22 pm

Inkscape Coordinate System Question

Postby skrasms » Wed Sep 05, 2012 3:20 pm

I feel like I must be missing some settings, because the results aren't intuitive. At a high level, I am writing a script to convert an Inkscape file with graphics into a list of drill locations to send to a metal fabricator. So, I parse the XML data from the Inkscape SVG and massage the numbers into the format I need.

The issue I'm on now is a matter of offsets. This is what confuses me:
1) Make a new document in Inkscape
2) Edit document properties to change height to 100mm and width to 100mm
3) Paste an image file and center/scale it to fill the page exactly
4) Look at coordinates of image in SVG file

In that case I see the y coordinate of the image as 698 (197mm). That's more than the size of my document! Why?

It appears Inkscape defines (0,0) in the SVG file as the upper left hand corner of an A4 page, regardless of the document's page size. This is made more confusing since the page outline as shown in Inkscape is the *lower* left hand corner of the imaginary A4 page. The bottom edge of my 100mm square document has a y coordinate of 297mm.

Is there a way in Inkscape to "fix" the coordinate system to stay with my page as defined by the document properties? I would like any point inside my 100mm square to not have an x or y coordinate greater than 100mm in the SVG file. I did not realize that would be confusing.

Posts: 39
Joined: Thu Aug 23, 2012 5:48 am

Re: Inkscape Coordinate System Question

Postby generatemutate » Wed Sep 05, 2012 7:27 pm

"One confusing aspect is that Inkscape uses a different scale internally. On the canvas, the x and y coordinates increase as one moves right or up. Internally the y coordinate is flipped as per the SVG standard. Thus, (0, 0) is defined from the upper-left corner of the page region internally but at the bottom-left corner in the canvas window. The internal scale is fixed (by default) to 90 dpi. The internal scale is important if you wish to edit by hand an object using the XML Editor. "

I would guess 698 is in the internal format 90 dpi, but that is still bigger than 100mm ??

don't know if this is reliant to the type of machine your using, but they may be able to point you in the right direction

Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Inkscape Coordinate System Question

Postby ~suv » Wed Sep 05, 2012 10:10 pm

a) path data in SVG always uses px (SVG user units), and not absolute units like e.g. 'mm'. The values shown in Inkscape's GUI are mostly converted between SVG and GUI coordinate system on-the-fly.

b) See also this earlier related comment: Re: Making files without an automatic offset in the y-coordinate

Posts: 4
Joined: Wed Jul 06, 2011 4:22 pm

Re: Inkscape Coordinate System Question

Postby skrasms » Thu Sep 06, 2012 1:04 pm

The units are clear: Inkscape uses 90 dpi when saving an SVG file. So, in that way it’s a simple conversion to mm or any other absolute length. 25.4mm in the Inkscape GUI is a distance of “90” in the SVG file.

The confusion here is why Inkscape does not fix the coordinate system offsets that it writes when saving an SVG file. The origin for a document of any size is in the upper left hand corner of an A4-size sheet. It just seems like a bug and makes the data more difficult to work with.

I found this workaround:

1) Create document in Inkscape using default page size
2) Save SVG file and close Inkscape
3) Open SVG file in a text editor
4) Change height and width attributes to desired values
5) Open file back up in Inkscape

That will fix the coordinate system to work as expected, with (0,0) in the SVG file pointing to the upper left hand corner of the page. The results are not the same if steps 3 and 4 are done using the XML editor built into Inkscape.

Return to “SVG / XML Code”

Who is online

Users browsing this forum: Google [Bot] and 4 guests