Sort attributes when exporting SVG

Bug #1045464 reported by v1nce
26
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Inkscape
In Progress
Wishlist
Unassigned

Bug Description

Maybe we could have an option to sort the attributes when exporting.
This will ease file comparison using diff tools.

Maybe we could add a textbox int the svg output options to set a list of attributes we always want to see first. eg "id;x;y;width;height;"

Revision history for this message
v1nce (vincent-pennec) wrote :

Don't know how to change title to "Enh sort attributes when exporting SVG" which would be easier to read.

jazzynico (jazzynico)
Changed in inkscape:
importance: Undecided → Wishlist
summary: - enh: new export options for svg
+ Sort attributes when exporting SVG
tags: added: preferences svg
Revision history for this message
jazzynico (jazzynico) wrote :

It seems (only tested with a minimal rectangle) that File>Save As>Optimized SVG (scour) already sorts the attributes (starting with id). Thus it may be easier to implement the option directly in that extension than in Inkscape directly.

Revision history for this message
su_v (suv-lp) wrote :

This feature has been implemented by Tavmjong Bah in core Inkscape in rev 14980 and a few follow-up commits (14983, 15007).

* Optionally sort attributes and properties into a canonical order.
  Useful for comparing different versions of an SVG file.
https://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/14980

The new SVG output feature is controlled by a preference setting (which has no GUI yet in the preferences dialog), and is disabled by default. The attribute "sort_attributes" of the group "svgoutput" in preferences.xml controls the output ('0' to disable (default), '1' to enable).

Changed in inkscape:
status: New → In Progress
Revision history for this message
Alvin Penner (apenner) wrote :

just writing to note that this option works well when applied to linked image attributes.

I applied it to the two files linkBeethoven.svg and linkChopin.svg from Bug 1655613 and it removed the differences in the ordering of the parameters for the lined image.

Revision history for this message
jazzynico (jazzynico) wrote :

Would it be considered a new feature if we add the option in the preferences dialog? If not, it should not be too difficult to implement for 0.92.1.
Targeting 0.93 for now.

Changed in inkscape:
milestone: none → 0.93
Revision history for this message
Patrick Storz (ede123) wrote :

Why not make it the default, i.e. is there ever a reason not to order attributes?

Revision history for this message
su_v (suv-lp) wrote :

Eduard Braun wrote:
> Why not make it the default, i.e. is there ever a reason not to order
> attributes?

@Tavmjong - any thoughts on enabling 'sort_attributes' by default, does it affect performance?

Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :

No real performance penalty but it might cause files with minimal edits to be completely rewritten (I haven' tested)... which is why I didn't enable it by default.

Revision history for this message
LucaDC (lucadc) wrote :

@Tav: actually, without sorting even files with no modifications (e.g. create an object, delete it, save) are (modified and) rewritten. Moreover, the problem of files being rewritten is going to affect existing unsorted files only and only for their first save (which would happen anyway); subsequently the sorting is going to mitigate it.

I'm +1 for sorting by default and I don't see any reason to have an option to disable it as, FWIU, the unsorted ordering doesn't have any desirable property.

Revision history for this message
LucaDC (lucadc) wrote :

Elaborating my last comment: the unsorted saving could be useful if one doesn't want an existing (unsorted) file to be modified. But the current Inkscape's behavior doesn't permit this as it's not preserving the original ordering anyway.
So the enable/disable option would have sense only if the unordered saving is fixed first.

Revision history for this message
v1nce (vincent-pennec) wrote :

No comments about the second part of the wish ?

Sorting would be great (for DIFFing) but I'd really really like to be able to preserve the position of some attributes (typically id) so that I don't have to search for it in the middle of "meaningless" other attributes

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

Having some semantic order in attributes is definitely useful. Actually I just implemented that for Scour (landed in version 0.35), see [1] for some details and thoughts I had on it.

I'm skeptical if it justifies a (user-visible) option in Inkscape (most people probably don't care). Hardcoding an order for the most common attributes (as I ended up doing in Scour) might be worth a thought, though.

Or you could just use Scour. ;-)

[1] https://github.com/scour-project/scour/issues/60

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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