Save Cleaned SVG

From Inkscape Wiki
Revision as of 21:53, 16 September 2008 by Doctormo (talk | contribs) (New page: = 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 sa...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

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

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