Code

more robust parsing of color info
authoralvinpenner <alvinpenner@users.sourceforge.net>
Sun, 24 May 2009 22:06:36 +0000 (22:06 +0000)
committeralvinpenner <alvinpenner@users.sourceforge.net>
Sun, 24 May 2009 22:06:36 +0000 (22:06 +0000)
share/extensions/dxf_outlines.py

index 6ff0c1a24176cdd3a6c69adb3652ac7500e4056b..3888bc7e3fe75042abba59ae0964dcc88d2ece00 100755 (executable)
@@ -150,14 +150,13 @@ class MyEffect(inkex.Effect):
         h = inkex.unittouu(self.document.getroot().xpath('@height', namespaces=inkex.NSS)[0])
         path = '//svg:path'
         for node in self.document.getroot().xpath(path, namespaces=inkex.NSS):
+            rgb = (0,0,0)
             style = node.get('style')
-            start = style.find("stroke:")
-            if style[start+11] == ';':
-                rgb = simplestyle.parseColor(style[(start+7):(start+11)])
-            elif style[start+14] == ';':
-                rgb = simplestyle.parseColor(style[(start+7):(start+14)])
-            else:
-                rgb = (0,0,0)
+            if style:
+                style = simplestyle.parseStyle(style)
+                if style.has_key('stroke'):
+                    if style['stroke'] and style['stroke'] != 'none':
+                        rgb = simplestyle.parseColor(style['stroke'])
             hsl = coloreffect.ColorEffect.rgb_to_hsl(coloreffect.ColorEffect(),rgb[0]/255.0,rgb[1]/255.0,rgb[2]/255.0)
             self.color = 7                                  # default is black
             if hsl[2]: