Update for 0.15: --keep-editor-data command-line option to keep Adobe, Inkscape, Sodipodi elements and attributes

This commit is contained in:
JSCHILL1 2009-06-24 10:00:49 -05:00
parent 8e589a80b4
commit e9f1e07a02
5 changed files with 35 additions and 15 deletions

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
SCOURVER="0.14" SCOURVER="0.15"
cd .. cd ..
tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
gzip scour/tarballs/scour-$SCOURVER.tar gzip scour/tarballs/scour-$SCOURVER.tar

View file

@ -9,6 +9,16 @@
<p>Copyright 2009, Jeff Schiller</p> <p>Copyright 2009, Jeff Schiller</p>
<section id="0.15">
<header>
<h2><a href="#0.14">Version 0.15</a></h2>
</header>
<ul>
<li>added --keep-editor-data command-line option</li>
</ul>
</section>
<section id="0.14"> <section id="0.14">
<header> <header>
<h2><a href="#0.14">Version 0.14</a></h2> <h2><a href="#0.14">Version 0.14</a></h2>

View file

@ -29,21 +29,18 @@
# #
# * Clean up Definitions # * Clean up Definitions
# * Collapse duplicate gradient definitions # * Collapse duplicate gradient definitions
# * Clean up paths
# * Eliminate last segment in a polygon
# * Process Transformations # * Process Transformations
# * Process quadratic Bezier curves # * Process quadratic Bezier curves
# * Collapse all group based transformations # * Collapse all group based transformations
# Suggestion from Richard Hutch: # Suggestion from Richard Hutch:
# * Put id attributes first in the serialization (or make the d attribute last) # * Put id attributes first in the serialization (or make the d attribute last)
# This would require my own serialization fo the DOM objects (not impossible) # This would require my own serialization of the DOM objects (not impossible)
# Next Up: # Next Up:
# + fix bug with consecutive path coordinates not being translated properly to relative commands # + add option to keep inkscape, adobe, sodipodi elements and attributes
# + convert straight curves to lines # - ensure a really good understanding of prec vs. quantize and what I want --set-precision to do
# + eliminate last segment in a polygon # - enable the precision argument to affect all numbers: polygon points, lengths, coordinates
# - provide command-line option to disable raster-to-base64 conversion
# - remove id if it matches the Inkscape-style of IDs (also provide a switch to disable this) # - remove id if it matches the Inkscape-style of IDs (also provide a switch to disable this)
# - convert polygons/polylines to path? (actually the change in semantics may not be worth the marginal savings) # - convert polygons/polylines to path? (actually the change in semantics may not be worth the marginal savings)
# - prevent elements from being stripped if they are referenced in a <style> element # - prevent elements from being stripped if they are referenced in a <style> element
@ -72,7 +69,7 @@ except ImportError:
Decimal = FixedPoint Decimal = FixedPoint
APP = 'scour' APP = 'scour'
VER = '0.14' VER = '0.15'
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',
@ -1487,10 +1484,11 @@ def scourString(in_string, options=None):
# for whatever reason this does not always remove all inkscape/sodipodi attributes/elements # for whatever reason this does not always remove all inkscape/sodipodi attributes/elements
# on the first pass, so we do it multiple times # on the first pass, so we do it multiple times
# does it have to do with removal of children affecting the childlist? # does it have to do with removal of children affecting the childlist?
while removeNamespacedElements( doc.documentElement, unwanted_ns ) > 0 : if options.keep_editor_data == False:
pass while removeNamespacedElements( doc.documentElement, unwanted_ns ) > 0 :
while removeNamespacedAttributes( doc.documentElement, unwanted_ns ) > 0 : pass
pass while removeNamespacedAttributes( doc.documentElement, unwanted_ns ) > 0 :
pass
# remove the xmlns: declarations now # remove the xmlns: declarations now
xmlnsDeclsToRemove = [] xmlnsDeclsToRemove = []
@ -1627,6 +1625,9 @@ _options_parser.add_option("--enable-id-stripping",
_options_parser.add_option("--disable-embed-rasters", _options_parser.add_option("--disable-embed-rasters",
action="store_false", dest="embed_rasters", default=True, action="store_false", dest="embed_rasters", default=True,
help="won't embed rasters as base64-encoded data") help="won't embed rasters as base64-encoded data")
_options_parser.add_option("--keep-editor-data",
action="store_true", dest="keep_editor_data", default=False,
help="won't remove Inkscape, Sodipodi or Adobe Illustrator elements and attributes")
# GZ: this is confusing, most people will be thinking in terms of # GZ: this is confusing, most people will be thinking in terms of
# decimal places, which is not what decimal precision is doing # decimal places, which is not what decimal precision is doing

View file

@ -65,6 +65,7 @@ class ScourOptions:
group_collapse = True group_collapse = True
strip_ids = False strip_ids = False
digits = 5 digits = 5
embed_rasters = False
# params are the form elements (if a checkbox is unchecked it will not be present) # params are the form elements (if a checkbox is unchecked it will not be present)
def fetch(req, indoc,**params): def fetch(req, indoc,**params):
@ -81,7 +82,6 @@ def fetch(req, indoc,**params):
if not params.has_key('simplifyColors'): if not params.has_key('simplifyColors'):
options.simple_colors = False options.simple_colors = False
options.digits = int(params['digits']) options.digits = int(params['digits'])
options.embed_rasters = False
req.write(scourString(indoc,options)) req.write(scourString(indoc,options))

View file

@ -37,6 +37,14 @@ def walkTree(elem, func):
if walkTree(child, func) == False: return False if walkTree(child, func) == False: return False
return True return True
class ScourOptions:
simple_colors = True
style_to_xml = True
group_collapse = True
strip_ids = False
digits = 5
embed_rasters = True
class NoInkscapeElements(unittest.TestCase): class NoInkscapeElements(unittest.TestCase):
def runTest(self): def runTest(self):
self.assertNotEquals(walkTree(scour.scourXmlFile('unittests/sodipodi.svg').documentElement, self.assertNotEquals(walkTree(scour.scourXmlFile('unittests/sodipodi.svg').documentElement,
@ -588,6 +596,7 @@ class DoNotRemovePolgonLastPoint(unittest.TestCase):
self.assertEquals(p.getAttribute('points'), '200,50 300,50 300,150 200,150', self.assertEquals(p.getAttribute('points'), '200,50 300,50 300,150 200,150',
'Last point of polygon removed' ) 'Last point of polygon removed' )
# TODO: write tests for --set-precision for path data, for polygon data, for attributes
# TODO; write a test for embedding rasters # TODO; write a test for embedding rasters
# TODO: write a test for --disable-embed-rasters # TODO: write a test for --disable-embed-rasters