From d09903fe39ef2d34136c5f5c2a9e3cf1bd34ad48 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Wed, 22 Apr 2009 22:26:40 -0500 Subject: [PATCH] Fix removal of stroke properties when stroke is transparent --- fulltests/Degri_Energy_Saving_Lightbulb.svg | 185 ++++++++++++++++++++ scour.py | 11 +- testscour.py | 32 +++- unittests/stroke-linejoin.svg | 3 + 4 files changed, 226 insertions(+), 5 deletions(-) create mode 100644 fulltests/Degri_Energy_Saving_Lightbulb.svg create mode 100644 unittests/stroke-linejoin.svg diff --git a/fulltests/Degri_Energy_Saving_Lightbulb.svg b/fulltests/Degri_Energy_Saving_Lightbulb.svg new file mode 100644 index 0000000..42f5d8e --- /dev/null +++ b/fulltests/Degri_Energy_Saving_Lightbulb.svg @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scour.py b/scour.py index d00bb7d..d86ee77 100755 --- a/scour.py +++ b/scour.py @@ -45,6 +45,7 @@ # * Collapse all group based transformations # Next Up: +# + fix bug when removing stroke styles # - Convert all colors to #RRGGBB format # - Reduce #RRGGBB format to #RGB format when possible # https://bugs.edge.launchpad.net/ubuntu/+source/human-icon-theme/+bug/361667/ @@ -502,8 +503,9 @@ def repairStyle(node): elif strokeOpacity == 0.0 : for uselessStrokeStyle in [ 'stroke', 'stroke-width', 'stroke-linejoin', 'stroke-linecap', 'stroke-dasharray', 'stroke-dashoffset' ] : - del styleMap[uselessStrokeStyle] - num += 1 + if styleMap.has_key(uselessStrokeStyle): + del styleMap[uselessStrokeStyle] + num += 1 # stroke-width: 0 if styleMap.has_key('stroke-width') : @@ -511,8 +513,9 @@ def repairStyle(node): if strokeWidth == 0.0 : for uselessStrokeStyle in [ 'stroke', 'stroke-linejoin', 'stroke-linecap', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-opacity' ] : - del styleMap[uselessStrokeStyle] - num += 1 + if styleMap.has_key(uselessStrokeStyle): + del styleMap[uselessStrokeStyle] + num += 1 # TODO: what else? diff --git a/testscour.py b/testscour.py index d380752..6d36b44 100755 --- a/testscour.py +++ b/testscour.py @@ -222,9 +222,39 @@ class NoInkscapeAttributes(unittest.TestCase): class KeepReferencedFonts(unittest.TestCase): def runTest(self): doc = scour.scourXmlFile('unittests/referenced-font.svg') - fonts = doc.documentElement.getElementsByTagNameNS('http://www.w3.org/2000/svg','font') + fonts = doc.documentElement.getElementsByTagNameNS(SVGNS,'font') self.assertEquals(len(fonts), 1, "Font wrongly removed from " ) + +class ConvertStyleToAttrs(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('style'), '', + "style attribute not emptied" ) + +class RemoveStrokeWhenStrokeTransparent(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke'), '', + "stroke attribute not emptied" ) + +class RemoveStrokeWidthWhenStrokeTransparent(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-width'), '', + "stroke-width attribute not emptied" ) + +class RemoveStrokeLinecapWhenStrokeTransparent(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linecap'), '', + "stroke-linecap attribute not emptied" ) + +class RemoveStrokeLinejoinWhenStrokeTransparent(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/stroke-linejoin.svg') + self.assertEquals(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('stroke-linejoin'), '', + "stroke-linejoin attribute not emptied" ) #class RemoveUnreferencedFonts(unittest.TestCase): # def runTest(self): diff --git a/unittests/stroke-linejoin.svg b/unittests/stroke-linejoin.svg new file mode 100644 index 0000000..23fd86e --- /dev/null +++ b/unittests/stroke-linejoin.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file