Bug 453737: Update Inkscape extension to provide a GUI for the options

This commit is contained in:
JSCHILL1 2009-10-19 12:47:50 -05:00
parent 4b96613a5d
commit 6482314390
4 changed files with 90 additions and 14 deletions

View file

@ -9,6 +9,16 @@
<p>Copyright 2009, Jeff Schiller</p> <p>Copyright 2009, Jeff Schiller</p>
<section id="0.22">
<header>
<h2><a href="#0.22">Version 0.22</a></h2>
</header>
<p>TBD</p>
<ul>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/449803">Bug 449803</a> by ensuring input and output filenames differ.</li>
</ul>
</section>
<section id="0.21"> <section id="0.21">
<header> <header>
<h2><a href="#0.21">Version 0.21</a></h2> <h2><a href="#0.21">Version 0.21</a></h2>

View file

@ -1,8 +1,51 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys, inkex
from scour import scourString from scour import scourString
input = file(sys.argv[1], "r")
sys.stdout.write(scourString(input.read()).encode("UTF-8")) class ScourInkscape (inkex.Effect):
input.close()
sys.stdout.close() def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option("--tab",
action="store", type="string",
dest="tab")
self.OptionParser.add_option("--simplify-colors", type="inkbool",
action="store", dest="simple_colors", default=True,
help="won't convert all colors to #RRGGBB format")
self.OptionParser.add_option("--style-to-xml", type="inkbool",
action="store", dest="style_to_xml", default=True,
help="won't convert styles into XML attributes")
self.OptionParser.add_option("--group-collapsing", type="inkbool",
action="store", dest="group_collapse", default=True,
help="won't collapse <g> elements")
self.OptionParser.add_option("--enable-id-stripping", type="inkbool",
action="store", dest="strip_ids", default=False,
help="remove all un-referenced ID attributes")
self.OptionParser.add_option("--embed-rasters", type="inkbool",
action="store", dest="embed_rasters", default=True,
help="won't embed rasters as base64-encoded data")
self.OptionParser.add_option("--keep-editor-data", type="inkbool",
action="store", dest="keep_editor_data", default=False,
help="won't remove Inkscape, Sodipodi or Adobe Illustrator elements and attributes")
self.OptionParser.add_option("--strip-xml-prolog", type="inkbool",
action="store", dest="strip_xml_prolog", default=False,
help="won't output the <?xml ?> prolog")
self.OptionParser.add_option("-p", "--set-precision",
action="store", type=int, dest="digits", default=5,
help="set number of significant digits (default: %default)")
self.OptionParser.add_option("--indent",
action="store", type="string", dest="indent_type", default="space",
help="indentation of the output: none, space, tab (default: %default)")
def effect(self):
input = file(sys.argv[11], "r")
sys.stdout.write(scourString(input.read(), self.options).encode("UTF-8"))
input.close()
sys.stdout.close()
if __name__ == '__main__':
e = ScourInkscape()
e.affect(output=False)

View file

@ -1,14 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Scoured SVG Output</_name> <_name>Optimized SVG Output</_name>
<id>org.inkscape.output.scour</id> <id>org.inkscape.output.scour</id>
<dependency type="executable" location="extensions">scour.py</dependency> <dependency type="executable" location="extensions">scour.py</dependency>
<dependency type="executable" location="extensions">svg_regex.py</dependency> <dependency type="executable" location="extensions">svg_regex.py</dependency>
<dependency type="executable" location="extensions">yocto_css.py</dependency> <dependency type="executable" location="extensions">yocto_css.py</dependency>
<param name="tab" type="notebook">
<page name="Options" _gui-text="Options">
<param name="simplify-colors" type="boolean" _gui-text="Simplify colors">true</param>
<param name="style-to-xml" type="boolean" _gui-text="Style to xml">true</param>
<param name="group-collapsing" type="boolean" _gui-text="Group collapsing">true</param>
<param name="enable-id-stripping" type="boolean" _gui-text="Enable id stripping">false</param>
<param name="embed-rasters" type="boolean" _gui-text="Embed rasters">true</param>
<param name="keep-editor-data" type="boolean" _gui-text="Keep editor data">false</param>
<param name="strip-xml-prolog" type="boolean" _gui-text="Strip xml prolog">false</param>
<param name="set-precision" type="int" _gui-text="Set precision">5</param>
<param name="indent" type="enum" _gui-text="Indent">
<_item value="space">Space</_item>
<_item value="tab">Tab</_item>
<_item value="none">None</_item>
</param>
</page>
<page name="Help" _gui-text="Help">
<_param name="instructions" type="description" xml:space="preserve">This extension optimize the SVG file according to the following options:
* Simplify colors: convert all colors to #RRGGBB format.
* Style to xml: convert styles into XML attributes.
* Group collapsing: collapse &lt;g&gt; elements.
* Enable id stripping: remove all un-referenced ID attributes.
* Embed rasters: embed rasters as base64-encoded data.
* Keep editor data: don't remove Inkscape, Sodipodi or Adobe Illustrator elements and attributes.
* Strip xml prolog: don't output the xml prolog.
* Set precision: set number of significant digits (default: 5).
* Indent: indentation of the output: none, space, tab (default: space).</_param>
</page>
</param>
<output> <output>
<extension>.svg</extension> <extension>.svg</extension>
<mimetype>image/svg+xml</mimetype> <mimetype>image/svg+xml</mimetype>
<_filetypename>Scoured SVG (*.svg)</_filetypename> <_filetypename>Optimized SVG (*.svg)</_filetypename>
<_filetypetooltip>Scalable Vector Graphics</_filetypetooltip> <_filetypetooltip>Scalable Vector Graphics</_filetypetooltip>
</output> </output>
<script> <script>

View file

@ -34,13 +34,7 @@
# at rounded corners) # at rounded corners)
# Next Up: # Next Up:
# + remove unused attributes in parent elements
# + prevent elements from being stripped if they are referenced in a <style> element
# + only move common attributes and remove unused attributes after removing duplicate gradients
# + only move common attributes to parent if the parent contains non-whitespace text nodes
# + do not pretty-print elements if whitespace is important (xml:space="preserve")
# - TODO: fix the removal of comment elements (between <?xml?> and <svg>) # - TODO: fix the removal of comment elements (between <?xml?> and <svg>)
# (for instance, filter, marker, pattern) - need a crude CSS parser
# - add an option to remove ids if they match the Inkscape-style of IDs # - add an option to remove ids if they match the Inkscape-style of IDs
# - investigate point-reducing algorithms # - investigate point-reducing algorithms
# - parse transform attribute # - parse transform attribute
@ -70,7 +64,7 @@ except ImportError:
Decimal = FixedPoint Decimal = FixedPoint
APP = 'scour' APP = 'scour'
VER = '0.21' VER = '0.22'
COPYRIGHT = 'Copyright Jeff Schiller, 2009' COPYRIGHT = 'Copyright Jeff Schiller, 2009'
NS = { 'SVG': 'http://www.w3.org/2000/svg', NS = { 'SVG': 'http://www.w3.org/2000/svg',