Difference between revisions of "Save Cleaned SVG"

From Inkscape Wiki
Jump to navigation Jump to search
m (Add category Proposals)
Line 80: Line 80:


--[[User:Tsingi|Tsingi]] 17:31, 14 November 2009 (UTC)
--[[User:Tsingi|Tsingi]] 17:31, 14 November 2009 (UTC)
[[Category:Proposals]]

Revision as of 10:42, 31 March 2012

Create Cleaned SVG

Please fix this wiki page if it doesn't fit the standard blueprint template.

Rationale

We're working on a proposal and design for allowing a plugin which saves svg data with various things striped and adjusted. Useful for scripting, templating with svg, editing later in a text editor and keeping files small for internet transfer.

Technologies

  • Python
  • python-xml
  • inkscape plugin svg/python module

Presented Options

The save format would not be totally pre-set or blind but would instead be based on the options selected by the user in a single, simple dialogue much like the pdf export dialogue.

Cleaning Operations

  • Specify a limit to the precision of all positional elements.
  • Clean up XML Elements
    • Collapse multiple redundent groups
    • Remove empty tags, such as defs or metadata.
    • Remove id tags for elements not referenced
  • Clean up Definitions
    • Remove unused definitions
    • Remove duplicate gradient stops
    • Collapse duplicate gradient definitions
    • Remove gradients that are only referenced by one other gradient
  • Clean up CSS
    • Remove Default values, i.e. opacity: 1;
    • Remove Not applicable values, i.e. opacity: 0; fill-color: #00000;
    • Convert RGB colours from RGB(r,g,b) to #RRGGBB format
    • Convert RGB colours from #RRGGBB to #RGB if possible
  • Clean up paths
    • Detect vertical/horizontal lines and replace.
    • Eliminate empty path segments
    • Eliminate last segment in a polygon
    • Collapse straight curves.
    • Convert absolute path segments to relative ones.
  • Process Transformations
    • Process quadratic Bezier curves
    • Collapse all group based transformations
  • Convert known properties to element attributes
    • css to element attributes
  • Output Standard SVG
    • Remove inkscape namespace
    • Remove sodipodi namespace
    • Remove adobe namespace
    • Use viewPort instead of document width/height

Tests

Testing of this code can be done automatically with a single good logical test. And should be written first. This involves a single svg document with all the worst noise and each ideal document output from that based on each operation. The test would be simply if the output is reached it passes.

Reference Work

SVG Tidy

  • This script has been created in Ruby where some of the ideas have been pulled:

See: http://www.intertwingly.net/blog/2008/02/01/SVG-Tidy

Scour

  • NOTE: scour (a Python script) has since been developed to automate the cleaning of SVG files. Most of the points on this page have been covered. Suggest using scour as the basis for the Inkscape plugin.

See: http://codedread.com/scour/

islint

  • Another project: (depricated, see NOTE below) islint (wiki link), InkScape lint is implemented with an InkScape "Save As" filter. Some different priorities than the above were assumed, i.e. islint creates a CSS style sheet. It was written to target web development. The points above are under review (with the other scripts found here) An exacting test page would be very beneficial.

NOTE: I changed the name from islint to svglint, I'm in the process of creating the project. svglint is a more recognizable name and islint implies that the tool is only for inkscape. I got ambitious.

I've also thrown out the old code completely, call it the first waffle.

See: http://svglint.sourceforge.net/ (project link)

--Tsingi 17:31, 14 November 2009 (UTC)