Closed user202729 closed 7 months ago
Edit → Preferences → Interface → Origin at upper left with y-axis pointing down is purely a user-interface feature. It has no bearing whatsoever on the document itself. The origin location isn't even written to the SVG file; the file will be the same whether the y-axis points up or down. Extensions like Simple Inkscape Scripting have no means of determining the user interface's y-axis direction.
To my knowledge, SVG itself has no mechanism to flip its coordinate system. The viewbox can be scaled by positive factors only and translated arbitrarily, but that's it. To use a quadrant I coordinate system, I'd recommend creating a transformed layer and appending all of your objects to it:
lay = layer('Flipped').scale((1, -1)).translate((0, canvas.viewbox[3]))
ln = line((0, 0), (100, 100), stroke='blue', stroke_width='2pt')
lay.append(ln)
Look for inkex
's unit-conversion functions in inkex.units
.
I find that I don't often need to convert units. The main use case is when an object needs to appear in an absolute size. More commonly, I'll simply set the viewbox and work in terms of viewbox coordinates.
~/.config/inkscape/preferences.xml
, but okay up to you. <group
id="options"
yaxisdown="0">
Thanks for the additional commentary on preferences.xml
. I hope other visitors to this page find that useful.
(Caveat: On Windows, the file location is %APPDATA%\inkscape\preferences.xml
.)
I notice I can
In both cases, SimpInkScr still uses the "original" coordinate.
(Actually the first point can be changed by Ctrl+Shift+D → set Scale (e.g. changing Scale to 10 → unit = cm)
Maybe it would be more intuitive to use the document unit instead, as it corresponds to what the ruler shows on the page. Opinion?
The document unit can be obtained with
but I've no idea if inkex has a convenient API to convert document unit to user unit (terminology: https://wiki.inkscape.org/wiki/Units_In_Inkscape / https://www.w3.org/TR/SVG/coords.html#Units ), or how to get the setting "Origin at upper left" value.
The best I can find at the moment is (any 1 of 3)
Edit: actually I realize this is more complicated, it's possible for a SVG file to set
viewBox
to make the origin does not align with the ruler's origin.