--query-width returns visual width with no option for geometric width

Bug #1761229 reported by Johan Rosenkilde
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Triaged
Wishlist
Unassigned

Bug Description

Running the command line option `--query-width` returns the visual width of the object. For many (most?) scripting purposes, one would want the visual width of the object (e.g. for any automated placement of objects).

This is the behaviour even though the Inkscape GUI is set to report geometric dimensions in the Preferences.

It would be very valuable with a command line possibility for selecting visual/geometric dimensions. Alternatively, the command line should simply follow the preference of the Inkscape GUI.

I'm running:
- Inkscape 0.92.2 (5c3e80d, 2017-08-06)
- On Fedora 27

Tags: cli
Patrick Storz (ede123)
tags: added: cli
removed: commandline
Revision history for this message
Patrick Storz (ede123) wrote :

Can you explain a bit what the use cases for querying the geometric width would be?

If we make "--query-width" behave differently depending on a preference I'm afraid it will easily cause unexpected results (in the GUI it's quite obvious if this setting is changed, but on the command line there's no visual indication that the geometric width would be returned). More importantly many scripts depend on the current behavior.

If we should decide to implement this, I think it would need to be a different command line option, but I assume in most cases it might be easier to extract the geometric dimensions directly from the SVG document (especially within the scope of extensions), making the detour through calling Inkscape and rendering the file unnecessary (which is usually costly with respect to performance).

Revision history for this message
Johan Rosenkilde (jsrn) wrote :

Thanks for considering this. My use case is in a Python script, where use the Inkscape CLI get basic dimensionality information (and sometimes run some verbs). Extracting the geometric dimensions from an SVG object is not easy and requires e.g. understanding nested transformations, and finding max and min points in bezier curves. I could perhaps be using PythonWebkit instead, but the Inkscape CLI is very easy to use, and performance is not critical for my script. I guess this kind of use case is basically why the Inkscape CLI exists?

My script has (among other tasks) to place a few objects exactly next to each other: think of a drawing that is duplicated, mirrored and aligned on the original's bottom line. The two bottom lines has to be placed exactly on top of each other (I'm then sending the drawing to a laser cutter).

I could use verbs (AlignVerticalTopAnchor), and did indeed do so in the beginning, but verbs quickly became clumsy as my script grew in complexity. Also, it is not so nice that the Inkscape GUI launches for a split-second whenever the script is run.

I wouldn't mind that the command line option has another name: I see your point that it can be confusing to depend on the GUI's parameters. Alternatively, one could introduce "--geometric" which means that queries are geometric, e.g. "inkscape --geometric --query-id 23 --query-width".

Both geometric and visual dimensions are important and have their uses, so it makes sense that the Inkscape GUI supports both. So the CLI could similarly?

Revision history for this message
Patrick Storz (ede123) wrote :

There are some helper functions available for usage by Python extensions, see [1].

Notably "computeBBox()" in "simpletransform.py" might be interesting for your use case (It should return the geometric bounding box as far as I can see).

That said I've never used it myself, so I don't know how straightforward it is to use, but it might be all that's needed in your case.

As for supporting this as a CLI option it's probably not too hard to implement, but somebody needs to find the time to actually do it, so it might be a while (unless you can recruit yourself or motivate somebody else).

[1]https://inkscape.gitlab.io/inkscape/doxygen-extensions/CommonClasses.html

Changed in inkscape:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
Johan Rosenkilde (jsrn) wrote :

Thanks for the pointer to simpletransform.py! It certainly seems to handle most of the complexity I was talking about (transforms and bounding boxes of bezier curves), though it seems to still need a bit of tweaking to be pluggable in my use case (descending into groups, at least).

More generally, if you consider that my use case is not an isolated thing, then this is obviously a bit clumsy for someone who'd like to just know geometric bounding boxes. Text boxes are also not supported by the extension code, and likely lots of other things (since every case is hard-coded).

I've never contributed to Inkscape and have no idea on how the code is structured. I might take a look, though, and see if I can figure out how to implement this.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.