diff --git a/release-notes.html b/release-notes.html
index f4a36e3..6d40887 100644
--- a/release-notes.html
+++ b/release-notes.html
@@ -11,11 +11,12 @@
-
+ July 4th, 2009
- added --keep-editor-data command-line option
+ - Fix Bug 395645: Keep all identified children inside a defs (Thanks Frederik!)
@@ -23,7 +24,7 @@
-
+
June 10th, 2009
- Collapse adjacent commands of the same type
- Convert straight curves into line commands
@@ -38,7 +39,7 @@
-
+ May 19th, 2009
- properly deal with fill="url("#foo")"
- properly handle paths with more than 1 pair of coordinates in the first Move command
@@ -53,7 +54,7 @@
-
+ May 17th, 2009
- upgraded enthought's path parser to handle scientific notation in path coordinates
- convert colors to #RRGGBB format
@@ -65,7 +66,7 @@
-
+ April 28th, 2009
- convert gradient stop offsets from percentages to float
- convert gradient stop offsets to integers if possible (0 or 1)
@@ -83,7 +84,7 @@
-
+ April 27th, 2009
- Remove path with empty d attributes
- Sanitize path data (remove unnecessary whitespace)
@@ -101,7 +102,7 @@
-
+ April 25th, 2009
- Fix bug when removing stroke styles
- Remove gradients that are only referenced by one other gradient
@@ -115,7 +116,7 @@
-
+ April 22nd, 2009
- Remove unnecessary nested <g> elements
- Remove duplicate gradient stops (same offset, stop-color, stop-opacity)
@@ -128,7 +129,7 @@
-
+ April 15th, 2009
- moved all functionality into a module level function named 'scour' and began adding unit tests
- prevent metadata from being removed if they contain only text nodes
@@ -141,7 +142,7 @@
-
+ April 13th, 2009
- Prevent error when stroke-width property value has a unit
- Convert width/height into a viewBox where possible
@@ -153,7 +154,7 @@
-
+ April 7th, 2009
- Removes unreferenced elements in a <defs>
- Removes all inkscape, sodipodi, adobe elements
diff --git a/scour.py b/scour.py
index 6542b2d..466d560 100755
--- a/scour.py
+++ b/scour.py
@@ -471,6 +471,24 @@ numBytesSavedInPathData = 0
numBytesSavedInColors = 0
numPointsRemovedFromPolygon = 0
+def removeUnusedDefs(doc, defElem, elemsToRemove=None):
+ if elemsToRemove is None:
+ elemsToRemove = []
+
+ identifiedElements = findElementsWithId(doc.documentElement)
+ referencedIDs = findReferencedElements(doc.documentElement)
+
+ keepTags = ['font', 'style', 'metadata', 'script', 'title', 'desc']
+ for elem in defElem.childNodes:
+ if elem.nodeName == 'g' and elem.namespaceURI == NS['SVG']:
+ elemsToRemove = removeUnusedDefs(doc, elem, elemsToRemove)
+ continue
+ if elem.nodeType == 1 and (elem.getAttribute('id') == '' or \
+ (not elem.getAttribute('id') in referencedIDs)) and \
+ not elem.nodeName in keepTags:
+ elemsToRemove.append(elem)
+ return elemsToRemove
+
def removeUnreferencedElements(doc):
"""
Removes all unreferenced elements except for