From 29ed3ddde7ac0c63786946b42e478f24554085d5 Mon Sep 17 00:00:00 2001 From: jeff_schiller Date: Tue, 4 Aug 2009 20:15:08 +0000 Subject: [PATCH] Checkin for Bug 409004: Add Scour as an output option --- share/extensions/scour.inkscape.py | 8 + share/extensions/scour.inx | 16 + share/extensions/scour.py | 2091 ++++++++++++++++++++++++++++ share/extensions/svg_regex.py | 281 ++++ 4 files changed, 2396 insertions(+) create mode 100755 share/extensions/scour.inkscape.py create mode 100644 share/extensions/scour.inx create mode 100755 share/extensions/scour.py create mode 100644 share/extensions/svg_regex.py diff --git a/share/extensions/scour.inkscape.py b/share/extensions/scour.inkscape.py new file mode 100755 index 000000000..531dfb46c --- /dev/null +++ b/share/extensions/scour.inkscape.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import sys +from scour import scourString +input = file(sys.argv[1], "r") +sys.stdout.write(scourString(input.read()).encode("UTF-8")) +input.close() +sys.stdout.close() diff --git a/share/extensions/scour.inx b/share/extensions/scour.inx new file mode 100644 index 000000000..30c948c1e --- /dev/null +++ b/share/extensions/scour.inx @@ -0,0 +1,16 @@ + + + <_name>Scoured SVG Output + org.inkscape.output.scour + scour.py + svg_regex.py + + .svg + image/svg+xml + <_filetypename>Scoured SVG (*.svg) + <_filetypetooltip>Scalable Vector Graphics + + + diff --git a/share/extensions/scour.py b/share/extensions/scour.py new file mode 100755 index 000000000..01c01a8a4 --- /dev/null +++ b/share/extensions/scour.py @@ -0,0 +1,2091 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Scour +# +# Copyright 2009 Jeff Schiller +# +# This file is part of Scour, http://www.codedread.com/scour/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Notes: + +# rubys' path-crunching ideas here: http://intertwingly.net/code/svgtidy/spec.rb +# (and implemented here: http://intertwingly.net/code/svgtidy/svgtidy.rb ) + +# Yet more ideas here: http://wiki.inkscape.org/wiki/index.php/Save_Cleaned_SVG +# TODO: Adapt this script into an Inkscape python plugin +# +# * Process Transformations +# * Process quadratic Bezier curves +# * Collapse all group based transformations + +# Even more ideas here: http://esw.w3.org/topic/SvgTidy +# * removal of more default attribute values (gradientUnits, spreadMethod, x1, y1, etc) +# * analysis of path elements to see if rect can be used instead? +# * removal of unused attributes in groups: +# +# +# +# +# +# in this case, fill="blue" should be removed +# * Move common attributes up to a parent group: +# +# +# +# +# +# becomes: +# +# +# +# +# + +# Suggestion from Richard Hutch: +# * Put id attributes first in the serialization (or make the d attribute last) +# This would require my own serialization of the DOM objects (not impossible) + +# Next Up: +# - add an option for svgweb compatible markup (no self-closing tags)? +# - if a has only one element in it, collapse the (ensure transform, etc are carried down) +# - remove id if it matches the Inkscape-style of IDs (also provide a switch to disable this) +# - prevent elements from being stripped if they are referenced in a