diff --git a/scour.py b/scour.py index d86ee77..fd63de6 100755 --- a/scour.py +++ b/scour.py @@ -455,8 +455,9 @@ def repairStyle(node): for uselessStyle in ['fill', 'fill-opacity', 'fill-rule', 'stroke', 'stroke-linejoin', 'stroke-opacity', 'stroke-miterlimit', 'stroke-linecap', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-opacity'] : - del styleMap[uselessStyle] - num += 1 + if styleMap.has_key(uselessStyle): + del styleMap[uselessStyle] + num += 1 # if stroke:none, then remove all stroke-related properties (stroke-width, etc) # TODO: should also detect if the computed value of this element is fill="none" @@ -490,8 +491,9 @@ def repairStyle(node): num += 1 elif fillOpacity == 0.0 : for uselessFillStyle in [ 'fill', 'fill-rule' ] : - del styleMap[uselessFillStyle] - num += 1 + if styleMap.has_key(uselessFillStyle): + del styleMap[uselessFillStyle] + num += 1 # stroke-opacity: 1 or 0 if styleMap.has_key('stroke-opacity') : diff --git a/testscour.py b/testscour.py index 6d36b44..bcb8e95 100755 --- a/testscour.py +++ b/testscour.py @@ -256,6 +256,21 @@ class RemoveStrokeLinejoinWhenStrokeTransparent(unittest.TestCase): self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linejoin'), '', "stroke-linejoin attribute not emptied" ) +class RemoveStrokeDasharrayWhenStrokeTransparent(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dasharray'), '', + "stroke-dasharray attribute not emptied" ) + +class RemoveStrokeDashoffsetWhenStrokeTransparent(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-dashoffset'), '', + "stroke-dashoffset attribute not emptied" ) + +# TODO : add in duplicate tests for when the stroke-width is 0 +# TODO : add in duplicate tests for when the stroke is none + #class RemoveUnreferencedFonts(unittest.TestCase): # def runTest(self): # doc = scour.scourXmlFile('unittests/unreferenced-font.svg') diff --git a/unittests/stroke-linejoin.svg b/unittests/stroke-linejoin.svg index 23fd86e..f462db9 100644 --- a/unittests/stroke-linejoin.svg +++ b/unittests/stroke-linejoin.svg @@ -1,3 +1,3 @@ - + \ No newline at end of file